Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте 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

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Awesome!

Completion rate improved to 5.26

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

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 2
some-alt