How coding in Python is bad for you

Nathan Ernst nathan.ernst at gmail.com
Fri Jan 27 12:30:03 EST 2017


I used to manually reformat unfamiliar C++ by hand, if for no other reason
in that it forced me to read the code and somewhat comprehend what was
going on. Now, I've lost my patience and use clang-format, a great & highly
configurable tool. I also use vim for Python & C++ coding, so I also rely
upon the command "gg=G" to reformat the current file (this doesn't do much
in Python, however).

One of the things I like about python is the indentation. It almost forces
(or rather strongly encourages you) to keep functions short & sweet, to do
a single thing in a function, and avoid too deeply nested structures.

I've seen horrible abominations in C++ over the years. In separate
projects, I've seen functions that were, in one case, over 45 printed
pages, another over 65 pages. The nesting level was way too deep. I think
in the worst case there were 8 levels of nested loops. This was problematic
for many reasons. Multiple developers working on this function at the same
time and attempting to merge was a big problem - the diff tool used by
Clearcase (I know, a WTF, in of itself) would get confused and
occassionally omit closing braces. Good luck resolving a compilation error
by a missing brace in a 5000 line function.  As a result of the pain I've
experienced, I try and keep functions small enough to fit on a
half-vertical, half-horizontal screen, with no line-wraps on a 1080p
monitor. (I'm usually working in a terminal half-screen wide and use
vertical splits in vim to see different parts of a file, or different
files).

On Fri, Jan 27, 2017 at 4:54 AM, Cecil Westerhof <Cecil at decebal.nl> wrote:

> On Friday 27 Jan 2017 05:07 CET, Brandon McCaig wrote:
>
> > Hell, considering the code that I have seen in the wild it might
> > even catch some extra errors that become syntax errors! It's not
> > at all rare for indentation to not match in languages that don't
> > require it to at least fit a pattern.
>
> I remember that when I had to amend the code of a certain programmer I
> always needed half a day to reformat his code. Because he was very
> good in copy/paste, but I could not made head or tail of his code
> because of the zig-zag of his code.
>
> That is why I immediately like the indent rule of Python very much.
>
> My only ‘problem’ was that I used to put debug statement at the
> beginning of a line to see immediately what the debug statements
> where. But that was a small price to pay. ;-)
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list