This section provides an example of bad coding standards. Bad coding standards can lead to code that is difficult to read, maintain, and debug.

Common Bad Practices

  • Not Using Comments: Code should be self-explanatory, but comments are essential for understanding the logic behind complex code.
  • Inconsistent Naming Conventions: Different variables, functions, and classes should follow a consistent naming convention.
  • Overuse of Global Variables: Global variables can lead to unexpected behavior and make code difficult to test.
  • Lack of Error Handling: Proper error handling is crucial for robust code.

Example

# Bad Practice: Not using comments and inconsistent naming conventions
def add(a, b):
    return a + b

if a > b:
    result = add(a, b)
else:
    result = add(b, a)

# Bad Practice: Overuse of global variables
globalVar = 10

def function():
    global globalVar
    globalVar += 1

# Bad Practice: Lack of error handling
def divide(a, b):
    return a / b

result = divide(10, 0)

Learn More

For more information on coding standards, please visit our Coding Standards Documentation.

Python