Defending the ternary operator

Dave Brueck dave at pythonapocrypha.com
Sat Feb 8 23:22:31 CET 2003


On Sat, 8 Feb 2003, Laura Creighton wrote:

> > On Sat, 8 Feb 2003, Laura Creighton wrote:
> >
> > > Regardless of the reasons some people _want_  conditionals, people
> > > are going to _use_ them because they save keystrokes. The number of
> > > people who will do anything to save keystrokes is legion.
> >
> > But how effectively can the language police peoples' laziness, and should
> > it? I mean, a lazy developer could just as easily save keystrokes by using
> > all one- and two-character variable names, indenting only a single space,
> > and not writing any comments. The same laziness (lack of discipline) will
> > manifest itself in a lack of architecture/design, lack of tests, etc.
> >
> > Pair programming or code reviews or even some good old fashioned mentoring
> > is the place to encourage best practices and discourage bad ones - not the
> > language.
>
> I don't understand this reasoning.  It means that the people who don't
> have anybody to mentor them are stuck with _another_ uncorrected bad
> practice, which they are probably unaware of, and people who are
> mentoring have yet another thing to decide when to forbid and how to
> teach.

Wait, back up, maybe I just didn't express my opinion very well. I was
mostly responding to the assertion that people would use (abuse)
if-expressions because it would save keystrokes, and my opinion is that,
true or not (and I don't think it is), that's not a great reason for being
against adding them to the language. The lack of discipline that leads to
taking short cuts manifests itself in too many places for the language to
effectively prevent (hence the examples of lousy variable names and lack
of comments - *far* more damaging than if-expression abuse). Besides not
being a problem the language can solve, excluding features based on what
lazy programmers do seems to be catering to the wrong audience, so as a
guideline it should be used with caution.

Now, as to the notion that a lack of mentor means you're "stuck", I partly
_agree_, but I will point out that all the mentor you need may be a
chapter in a book or a web page that teaches some best practices for the
language.

Having said that, I will also readily admit that in my experience people
who code in isolation *do* tend to write lousier code than those who have
peers. The primary example I have of this is myself - I was self-taught
and had _no_ notion of code readability, maintainability, etc - instead of
"software development" it was "code slinging". Books like "Code Complete"
and "Writing Solid Code" were real eye openers for me, but the greatest
improvement to my coding style came when I worked with other people who
took the time to point out some bad habits I had and show me some better
ways to do things.

Finally, does adding this feature *really* add that much to what a mentor
or teacher has to do? IMO, not really. In an introductory course you
probably wouldn't even mention if-expressions at all, and goodness, most
people would be smart enough to figure it out on their own (a skill
they'll have to develop no matter what). A good teacher won't try to
hand-hold the student through every little feature anyway.

-Dave





More information about the Python-list mailing list