Naming Conventions
Part of the Fundamentals section of Coddy's Swift journey — lesson 9 of 86.
Naming conventions are a set of guidelines that developers follow to make their code more readable and maintainable. Different programming languages often have different naming conventions. In Swift, variables and constants are written in camelCase — the first word starts with a lowercase letter, and each subsequent word starts with an uppercase letter.
When writing a variable name, be descriptive and use meaningful words.
For example:
// Bad Naming
let is_active = false // not camelCase (snake_case)
let a = 10
let b = "Hello"
let x = true
// Good Naming
let age = 10
let greeting = "Hello"
let isActive = trueChallenge
BeginnerWrite code that initializes the following constants using proper camelCase naming:
playerNamewith the value"Alice"playerAgewith the value25isGameOverwith the valuefalse
Make sure you use the exact variable names and values. Remember:
- Swift is case sensitive! (
playerName≠Playername)- String values must be enclosed in double quotes
- Boolean values are lowercase:
true/false
Cheat sheet
In Swift, variables and constants follow camelCase naming convention — the first word starts with a lowercase letter, and each subsequent word starts with an uppercase letter.
Use descriptive and meaningful names for your variables and constants:
// Bad Naming
let is_active = false // not camelCase (snake_case)
let a = 10
let b = "Hello"
let x = true
// Good Naming
let age = 10
let greeting = "Hello"
let isActive = trueTry it yourself
// Type your code below
let playerName = ?
let playerAge = ?
let isGameOver = ?
// Don't change the lines below
print("playerName = \(playerName)")
print("playerAge = \(playerAge)")
print("isGameOver = \(isGameOver)")This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorCompound AssignmentRecap - Simple MathComparison Operators7Basic IO
Print FunctionString InterpolationReadLine InputType ConversionRecap - Till 120Recap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesArgument LabelsRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Sequences
Iterating Over ElementsThe Enumerated MethodIterating Over Strings P1Iterating Over Strings P22Variables
Let vs VarType AnnotationsNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting Input3Optionals
What Are OptionalsUnwrapping With If LetGuard LetNil Coalescing OperatorRecap - Safe Unwrapping9Loops
For-In LoopWhile LoopRepeat-While LoopBreakContinueRecap - FactorialRanges In LoopsNested LoopRecap - Dynamic Input