Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele 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

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 2

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 5.26

bookCommon Code Smells in Python

Pyyhkäise näyttääksesi valikon

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

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 2
some-alt