Naming Conventions: Camelcase vs Snakecase

IntegralThorium avatar
IntegralThorium
·
·
Download

Start Quiz

Study Flashcards

17 Questions

Which of the following best describes the concept of initialization in programming?

Giving a variable an initial value at the time of declaration

What is the purpose of naming conventions in programming?

To ensure that variables have meaningful and consistent names

Which of the following is an example of a legal identifier in programming?

_variableName

What is the importance of using meaningful variable names in programming?

To make the code more readable and maintainable

In programming, which naming convention usually capitalizes the first letter of each word and joins them together without spaces?

camelCase

Which naming convention involves starting with a lowercase letter and capitalizing the first letter of each subsequent word?

camelCase

In the context of naming conventions, which of these is a correct example of snakecase?

my_value

Why is it important to use meaningful names for variables in programming?

To indicate the meaning or use of the stored value

Which of the following is NOT a legal identifier in C++?

$amount

Choose the statement that correctly describes variable declaration in C++.

Variables must be declared before they are used

Which of the following is a common misconception about naming conventions?

'kebab-case' involves capitalizing every word in an identifier

Which character is NOT allowed in C++ identifiers?

A hyphen (-)

What is the correct naming convention for the following identifier: 'totalAmountOfSales'?

total_amount_of_sales

Which of the following C++ identifiers is legal?

_averageScore

What is the naming convention used in C++ where the first letter of each word except the first word is capitalized?

camelCase

Which of the following identifier names adheres to good practice and is meaningful?

totalSalesValue

Given the identifier 'RATE.CPP', why is it considered illegal in C++?

'RATE' cannot be followed by a period in identifiers.

Study Notes

Identifiers and Naming Conventions

  • Identifiers must start with a letter (A-Z or a-z) or an underscore (_).
  • Identifiers can be of any length, but C++ is case-sensitive.
  • Legal identifier names include CISC1600, RATE, and _RATE, but not 1600CISC, $cash, my-Value, or RATE.CPP.
  • Two common naming conventions are Camelcase and Snakecase (or "C-Style").
  • Camelcase: start with a lowercase letter, and capitalize the first letter of each subsequent word in a compound word or phrase.
  • Snakecase: use underscores between compound words and longer phrases, with no additional capitals.

Variable Declarations

  • All variables in a C++ program must be declared.
  • A variable declaration gives the variable a name, e.g. int myVar;, double RATE;, or char firstInitial;.
  • Variables can be initialized with a value during declaration, e.g. int numOfStudents = 10;.

Variables and Assignments

  • Variables are used to store and name data.
  • A variable's value can be changed later in the program.
  • If a variable is given no value when it is created, it will have a garbage value until it is assigned a value.
  • Each variable is assigned an address/memory location when the program is compiled.
  • The value assigned to a variable is stored in that memory location while the program runs.

Assignment Statements

  • A variable has no meaningful value until it is assigned one.
  • Example of assignment: desiredValue = minValue + 25;.
  • Uninitialized variables store garbage data and can have different values each time the program is run.
  • Variables can be initialized with a value during declaration, e.g. int minValue = 10;.
  • Multiple variables can be initialized with values during declaration, e.g. double rate = 0.07, time, balance = 0.0;.

Input and Output

  • Streams can be used to feed input from a source into a program or send output generated by the program.
  • cout is used to output strings of text or the value of variables.
  • Example of output: int faculty = 26; cout << faculty;.

Learn about the common naming conventions used for identifiers in programming, such as Camelcase and Snakecase. Understand how these conventions make identifiers consistent and easier to read at a glance.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser