Python is one of the most elegant and clean programming languages, yet having a beautiful and clean syntax is not the same as writing clean code.
...
For further actions, you may consider blocking this person and/or reporting abuse
This is a pretty poor example of clear variable names (see Naming Conventions #2 above)
The variable name's purpose would be clearer if it were 'countries', not 'cities'!
For loop should also not be indented...
Maybe this indent decided to leave the
print
statement (where it is destined to be)and moved in with that
for
loop neighbor against all odds.Seriously, indent really matters in Python. As well as the case (especially for keywords), so
Pass
instead ofpass
will trigger a NameError unless there is a variable named Pass.
And speaking of technical debt, these two kinds of bugs (wrong indentation and case incosistency) in poorly written Python code are sneaky enough to go unnoticed since they may not trigger any error messages in some cases.
Also, the quotation marks in the
cities
list are not"
(\x22
) but“
(\u201C
) and”
(\u201D
) unicode characters. It would raiseSyntaxError
.There's always a possibility that's an issue with the page formatter for code. I know Confluence can be a bit funny about that if you paste into a code block.
Whether on purpose or not, it is a clear example of why it's important to give clear names. If this was a bug, I could clearly find it just by looking at the code.
It's also a relatively good example of why compiled languages are so (much more) useful :-)
Is using flags really that bad? Especially for large complex functions? Not using them would mean that I need two (large) functions instead of having one simple switch. I would imagine this often leads to problems because stuff is fixed inside one function but not the other.
Yeah, there are cases when it should be done and the cases where it should not. The example in the article is an obvious example when it should not be used though.
The issue is with description of the case. It should've say something along the lines of "boolean flags in function arguments should not change the function's core logic, only its side effects".
Agreed. It’s easily avoided in the article’s example, a one-line function. But flags can help us write DRY code for more complex functions.
Thank you so much for your post. It helps a lot.
p.s: dices have 6 sides I think!!
Ever played ttrpg’s?
Dices can have
4, 6, 8, 10, 12, 20, and 100 sides.
Polyhedral dice sets. So to me it did make sense.
“Dices” is not a word. Dice is already plural, referring to more than one cube. Die is the word to represent one cube.
Btw Good article, the point was well made.
I consider the name
Las_name
confusing. Is it supposed to belast_name
or does Las mean something else? (In Sweden, LAS is a law about employment.)I think it was a typo
There are far too many typos for an article about clean code.
the fetch and display function is totally fine by itself. It only makes sense to separate them when you need to only display or only fetch the users separately
I found interesting this post. Some fundamentals but important points are present here. Good job!!!
Cool
Keeping codes clean and easy to read is very important not only Python but also other languages. This is a very useful tips for developers to maintain their codes. Thanks for sharing.
Thank you for this piece...
No one said anything about using comprehensions?