1-line idiom to replace if blocks

Jon Perez jbperez808 at yahoo.com
Sun Jan 26 00:57:16 EST 2003


"Y2KYZFR1" <jarrodhroberson at yahoo.com> wrote:

> > I hate code that takes up too many lines and
> > have come up with the ff. idiom to replace
> > many 4 line if statements:
> >
> > result=[value-if-false,value-if-true][condition]
> >
> > This idea could also be applied as a compact
> > switch block replacement in certain cases.
> >
>
> God I feel sorry for anyone that has to come behind you and work on
> any code you ever write. If you are this lazy not to write out a
> simple if statement where other people can come behind you and
> understand it.
>
> The entire idea behind Python even more so than other languages is
> maintance and readablity and you whack jobs just insist on making it
> convoluted and obfuscated!
>
> It does not show how clever you are, just how lazy and inconsiderate
> you are. I have fired people for less than this personally!

LOL, I came up with that idiom precisely to ***promote
code readability*** and not to be clever!!  Super short if-blocks
that nevertheless take up 4 lines make it hard and tedious to
read a long piece of logic which won't fit within a page.  It
only takes a few moments to get used to and understand the idiom
after which you will find it faster to scan through logic that
uses it.

I'm pretty anal about screen space.  I use a 160x65 fbcon
text mode under Linux and I still don't find there is enough
space (primarily vertical, I believe I've hit the sweet spot
with 160 columns :-D) to make poring through code easy.  Am
not as strong in the short-term memory department as I would
like to be, that's why I my thinking style is biased towards
'chunking'... i.e. easier to remember what one-line does rather
than going through 4 step by step.  Multiply that by many
instances of the idiom and you might see what I mean.








More information about the Python-list mailing list