Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's Dart journey — lesson 13 of 94.

In Dart, naming conventions make code readable and consistent:

1. Use camelCase for variables

void main() {
  String firstName = 'John';
  int userAge = 25;
  double accountBalance = 100.50;
  bool isLoggedIn = true;
}

2. Start with letters/underscores

void main() {
  var name = 'Dart';
  var counter = 1;
}

3. Use meaningful names

void main() {
  // Better naming
  var temperatureFahrenheit = 75.5;
}

4. Use lowerCamelCase for constants

void main() {
  const pi = 3.14159;
  const maxUsers = 100;
  const baseUrl = 'https://api.example.com';
  const defaultTimeout = Duration(seconds: 30);
}
challenge icon

Challenge

Beginner

In this challenge, you'll practice Dart naming conventions by fixing poorly named variables in a program:

  1. Rename the variable x to a descriptive name for a person's age (use camelCase)
  2. Rename the variable Y to a descriptive name for a person's height in meters (use camelCase)
  3. Rename the constant ABC to a descriptive name for pi (use uppercase with underscores for constants)
  4. Rename the final variable temp123 to a descriptive name for maximum allowed temperature (use camelCase)

After renaming, print each variable with a descriptive label exactly as shown below:

Age: 25
Height: 1.75
Pi Value: 3.14
Max Temperature: 100.0

Your output must match this exact format.

Try it yourself

void main() {
  int x = 25;
  double Y = 1.75;
  const double ABC = 3.14;
  final double temp123 = 100.0;
  
  // Print the variables with labels
  print("Age: $?");
  print("Height: $?");
  print("Pi Value: $?");
  print("Max Temperature: $?");
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals