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?

すべての正しい答えを選択

question mark

Which of the following are considered code smells in Python?

すべての正しい答えを選択

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  2

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  2
some-alt