One liners

Joel Goldstick joel.goldstick at gmail.com
Sat Dec 7 01:39:50 CET 2013


On Fri, Dec 6, 2013 at 7:20 PM, Michael Torrie <torriem at gmail.com> wrote:

> On 12/06/2013 05:14 PM, Dan Stromberg wrote:
> > I'm thinking mostly of stackoverflow, but here's an example I ran into (a
> > lot of) on a job:
> >
> > somevar = some_complicated_thing(somevar) if
> > some_other_complicated_thing(somevar) else somevar
> >
> > Would it really be so bad to just use an if statement?  Why are we
> > assigning somevar to itself?  This sort of thing was strewn across 3 or 4
> > physical lines at a time.
>
> You're right that a conventional "if" block is not only more readable,
> but also faster and more efficient code.  Sorry you have to deal with
> code written like that!  That'd frustrate any sane programmer.  It might
> bother me enough to write code to reformat the program to convert that
> style to something sane!  There are times when the ternary (did I get
> that right?) operator is useful and clear.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

While it seems to be a higher status in the team to write new code as
compared to fixing old code, so much can be learned by having to plough
through old code.  To learn others coding style, pick up new understanding,
and most importantly totally disabuse yourself of trying to be cute with
code.  Code is read by the machine and by the programmer.  The programmer
is the one who should be deferred to, imo.  You buy the machine, you rent
the programmer by the hour!

Aside from django urls, I am not sure I ever wrote regexes in python.  For
some reason they must seem awfully sexy to quite a few people.  Back to my
point above -- ever try to figure out a complicated regex written by
someone else?



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131206/3b06971b/attachment.html>


More information about the Python-list mailing list