Practice & Exercise
1. Identifier Naming Best Practices
Task: Write a function that checks if a given number is a perfect square.
Requirements:
Name the function appropriately, following identifier naming best practices.
Use meaningful parameter names and return a boolean value indicating whether the number is a perfect square.
Example Input:
16
Expected Output:
true
2. Class and Interface Naming
Task: Create a class that models a library book.
Requirements:
Name the class and its properties in a way that clearly conveys their purpose.
Include properties for the book title, author, and ISBN number.
Implement a constructor to initialize these properties.
Example Usage: Create a
Book
object with Title: "1984", Author: "George Orwell", ISBN: "123-4567890123".
3. Method and Property Naming
Task: Implement a method that calculates the factorial of a non-negative integer.
Requirements:
Choose a clear and descriptive name for the method.
Use meaningful parameter names and ensure the return type is appropriate.
Example Input:
5
Expected Output:
120
4. Variable and Boolean Naming
Task: Write a function that determines if a person is a minor.
Requirements:
Define a meaningful function name and use clear variable names for the parameters.
Return a boolean indicating if the person is under 18 years old.
Example Input:
17
Expected Output:
true
5. Naming Patterns for Self-Documenting Code
Task: Create a function that reverses a string.
Requirements:
Use an appropriate name for the function that reflects its action.
Ensure the parameter and return values are named clearly to avoid confusion.
Example Input:
"hello"
Expected Output:
"olleh"
Last updated