Naming Conventions
Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 10 of 93.
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 Kotlin, variables and values 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:
fun main() {
// Bad Naming
val is_active = false // not camelCase (snake_case)
val a = 10
val b = "Hello"
val x = true
// Good Naming
val age = 10
val greeting = "Hello"
val isActive = true
}Challenge
BeginnerWrite code that initializes the following values using proper camelCase naming:
playerNamewith the value"Alice"playerAgewith the value25isGameOverwith the valuefalse
Make sure you use the exact variable names and values. Remember:
- Kotlin is case sensitive! (
playerName≠Playername)- String values must be enclosed in double quotes
- Boolean values are lowercase:
true/false
Try it yourself
fun main() {
// Type your code below
val playerName = ?
val playerAge = ?
val isGameOver = ?
// Don't change the lines below
println("playerName = $playerName")
println("playerAge = $playerAge")
println("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 OperatorAugmented AssignmentComparison OperatorsRecap - Simple Math7Basic IO
Println FunctionString TemplatesReadLine InputType ConversionRecap - Years Until RetirementRecap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesNamed ArgumentsDefault ValuesSingle Expression FunctionsRecap - Sigma FunctionRecap - Validation Function2Variables
Val vs VarType InferenceNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Logical Operators Part 3Ternary With If ExpressionRecap - Simple Logic8Bill Split Calculator
Welcome MessageGetting Input3Nullability
What Is Null SafetyNullable TypesSafe Call OperatorElvis OperatorFunction Challenge BasicsNot Null AssertionRecap - Safe Access6Decision Making
If StatementIf - ElseIf As An ExpressionWhen ExpressionWhen With RangesRecap - Simple Calculator9Loops
For LoopWhile LoopDo-While LoopBreakContinueRanges In LoopsNested LoopRecap - FactorialRecap - Dynamic InputPractice on your own: Kotlin playground