Why does python not have a mechanism for data hiding?

NickC ncoghlan at gmail.com
Wed Jun 4 14:00:29 CEST 2008


On Jun 4, 9:24 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> NickC <ncogh... at gmail.com> writes:
> > if/else was added solely because people kept coming up with ways of
> > embedding a pseudo conditional inside expressions and writing buggy
> > code in the process. All it really saves you in practice is a bit of
> > vertical whitespace, so, no, you still don't need it - but if you
> > insist on doing it, at least there's now an easy way to do it
> > correctly.
>
> Come on, it's more than vertical whitespace, it's extraneous variables
> and sometimes even extraneous functions and function call overhead.
> And Python is supposed to be unbureaucratic.  People kept looking for
> ways to write conditional expressions instead of spewing the logic
> across multiple statements for a reason: the code is often cleaner
> that way.

True, but it really was the multitude of buggy workarounds for the
lack of a ternary expression that sealed the deal, rather than the
benefits of ternary expressions in their own right :)

Given that I personally use ternary expressions solely as the right
hand side of an assignment statement, the reduction in vertical
whitespace usage really is the only thing they gain me. I guess if you
embedded them as an argument to a function call or other more
complicated expression then there may be additional savings. I prefer
not to do that though, since such things can get quite difficult to
parse mentally when reading them later.

Cheers,
Nick.



More information about the Python-list mailing list