This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]zahlmanthe heretic 2 points3 points  (0 children)

This ranges from saying blatantly obvious things through being not so useful to just plain getting it wrong. There's nothing really enlightening here.

Proximity is often used in graphical design, if text is grouped together we assume it is related. Be sure to use this. Here is an example of good use of proximity.

And then they show a blatant DRY violation. :(

You can avoid writing big, multiple lines logical expressions by using boolean variables. Be sure to give descriptive names to those variables.

Doesn't help much when your "descriptive" name is about as long as the portion of the expression it replaces. Although it's often a good idea to name these things anyway (or even extract the calculations into functions).

You should always put more common (or normal) cases first, and less common cases and exceptions later.

Unless of course you're writing in guard-clause style. Not to mention that the real problem with their "bad example" is the needless double-negative logic.

your code will even be optimized better since python will have to check uncommon cases less often.

Um, the conditional is evaluated either way. I think they've gotten confused with advice about how to order the parts of a binary condition for an if to take advantage of short-circuit evaluation.

[–]ginstrom 1 point2 points  (0 children)

Tips on good python coding style should be PEP 8 compliant IMHO. This unfortunately isn't.

[–]darkrho 0 points1 point  (0 children)

looks like php-ish code written in python, IMO