On Sat, Sep 07, 2019 at 08:22:58PM +0100, Rob Cliffe via Python-ideas wrote:
> in which of the following is it easier to spot the mistake?
>
> # Version 1:
> if max_results > 0 : querydata['max_results'] = max_results
> if active is not None : querydata['active'] = active
> if deleted is not None: quervdata['deleted'] = deleted
>
> # Version 2:
> if max_results > 0:
> querydata['max_results'] = max_results
> if active is not None:
> querydata['active'] = active
> if deleted is not None:
> quervdata['deleted'] = deleted
Obviously the mistake is that max_results is supposed to be greater than
OR EQUAL to zero. *wink*
But seriously, most coding errors aren't simple spelling errors. If they
are, chances are that you will immediately get a NameError, or (as you
point out yourself) your spell checker will spot it. The insidious
errors are logic errors and this does not help with those unless your
lines are almost identical:
if seq[0] == 1: query[0] == 0
if seq[1] == 1: query[1] == 1
if seq[2] == 1: query[2] == 2
in which case you should probably use a for loop.
If this style works for you, I'm glad for you and don't wish to persuade
you differently. But for me, I am not comfortable with this style and
would not use it because I have seen far too many people (including
myself) waste too much time farting about fixing formatting and
alignment issues instead of doing productive work.
# Oh no now I have to re-align ALL THE THINGS
if max_results > 0 : querydata['max_results'] = max_results
if active is not None : querydata['active'] = active
if deleted is not None: querydata['deleted'] = deleted
if items and items[0] >= items[-1]: querydata['items'] = items
if max_results > 0 : querydata['max_results'] = max_results
if active is not None : querydata['active'] = active
if deleted is not None : querydata['deleted'] = deleted
if items and items[0] >= items[-1]: querydata['items'] = items
Not only is a time-waster, it messes up your diffs, forces short lines
to be as long as long lines (increasing the chances you will exceed 80
columns), and fills your code with rivers of whitespace in the middle of
the text.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3CGSEWO3PWHQKNPDWRUJUUQZAONE3AO3/
Code of Conduct: http://python.org/psf/codeofconduct/