summaryrefslogtreecommitdiffstats
path: root/src/chapter1/lesson7/naming.cpp
blob: 70256b28942da9f6c673b1bb17d44eb8c2dde1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <ostream>

/*
 * Question #1
 *
 * Based on how you should name a variable, indicate whether each variable name
 * is conventional (follows best practices), unconventional (compiler will
 * accept but does not follow best practices), or invalid (will not compile),
 * and why.
 *
 */

int main() {

	// Assume it's obvious what we're summing
	// Conventional
	[[maybe_unused]] int sum {};

	std::cout << "\"int sum {};\": conventional\n";

	// Unconventional: starting with underscore
	[[maybe_unused]] int _apples {};

	std::cout << "\"int _apples {};\": unconventional\n";

	// Unconventional: starting with capital character and whole identifier
	// is uppercase
	[[maybe_unused]] int VALUE {};
	std::cout << "\"int VALUE {};\": unconventional\n";

	// invalid: whitespaces are not allowed
	//int my variable name {};
	std::cout << "\"int my variable name {};\": invalid\n";

	// Unconventional: starting with capital character
	[[maybe_unused]] int TotalCustomers {};
	std::cout << "\"int TotalCustomers {};\": unconventional\n";

	// invalid: reserved word used for identifier
	//int void {};
	std::cout << "\"int void {};\": invalid\n";

	// Conventional
	[[maybe_unused]] int numFruit {};
	std::cout << "\"int numFruit {};\": conventional\n";

	// invalid: starting with a number
	//int 3some {};
	std::cout << "\"int 3some {};\": invalid\n";

	// Conventional
	[[maybe_unused]] int meters_of_pipe {};
	std::cout << "\"int meters_of_pipe {};\": conventional\n";

	std::cout << "\nLook comments in source code for explanations." << std::endl;

	return 0;
}