Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Common Code Smells in Python | Foundations of Code Quality
Code Quality and Refactoring in Python

bookCommon Code Smells in Python

Understanding code smells is essential for anyone aiming to write high-quality Python code. A code smell is a surface indication that usually points to a deeper problem in your codebase. While a code smell is not necessarily a bug, it often signals that your code could be improved for better readability, maintainability, or performance. In Python, some typical code smells include long functions that try to do too much, duplicated code that makes maintenance harder, and magic numbers — hard-coded values with no explanation. These issues can make your code difficult to understand or change, and they often lead to more serious problems as your project grows.

12345678910111213141516
def process_data(a, b, c, d): # This function does too many things at once x = a * 3.14159 # What does 3.14159 mean here? y = b * 2 z = c + d result = x + y + z tmp = result / 42 # Why 42? if tmp > 100: value = tmp - 10 else: value = tmp + 10 # Unclear variable names and magic numbers everywhere for i in range(0, 10): value += i return value
copy

1. Which code smell is present in the code sample above?

2. Which of the following are considered code smells in Python?

question mark

Which code smell is present in the code sample above?

Select the correct answer

question mark

Which of the following are considered code smells in Python?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 5.26

bookCommon Code Smells in Python

Swipe um das Menü anzuzeigen

Understanding code smells is essential for anyone aiming to write high-quality Python code. A code smell is a surface indication that usually points to a deeper problem in your codebase. While a code smell is not necessarily a bug, it often signals that your code could be improved for better readability, maintainability, or performance. In Python, some typical code smells include long functions that try to do too much, duplicated code that makes maintenance harder, and magic numbers — hard-coded values with no explanation. These issues can make your code difficult to understand or change, and they often lead to more serious problems as your project grows.

12345678910111213141516
def process_data(a, b, c, d): # This function does too many things at once x = a * 3.14159 # What does 3.14159 mean here? y = b * 2 z = c + d result = x + y + z tmp = result / 42 # Why 42? if tmp > 100: value = tmp - 10 else: value = tmp + 10 # Unclear variable names and magic numbers everywhere for i in range(0, 10): value += i return value
copy

1. Which code smell is present in the code sample above?

2. Which of the following are considered code smells in Python?

question mark

Which code smell is present in the code sample above?

Select the correct answer

question mark

Which of the following are considered code smells in Python?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2
some-alt