[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code

INADA Naoki wrote:
> Rick Johnson wrote:
> > INADA Naoki wrote:
> > >
> > > I can't agree with you.  It's too redundant.  It doesn't
> > > provide any information about what coder think.
> >
> > It's not about what the "coder thinks", many times what
> > the coder thinks is wrong, it's about writing code that is
> > intuitive to as wide an audience as possible.
> My point is not "what the coder thinks", but "express what
> the coder thinks". It's very important point about
> readability.  When I talk about readability, it's defined
> in "The Art of Readable Code". [snip: link] It means; How
> long average leveled programmer understand the code deep
> enough, to modify the code or fix bug in the code.  It not
> means "intuitive to as wide an audience as possible."

I think for most languages an intuitive syntax is not
important -- C is such a language, Lisp is such a language,
Perl is such a language, and there are many more -- but
for Python, intuitiveness is very important.

> > > While PEP 8 recommends `if x:`, I accept `if x > 0` or
> > > `if len(x) > 0` when I review code in my company.
> >
> > So when `x` is an iterable, as in:
> >
> >     if len(x) > 0:
> >         # blah
> >
> > You're okay with the explicit test.
> Yes, you know "this code is assuming x is container" from
> redundant `len(x) > 0`. It's valuable information. As a
> bonus, len(x) raises TypeError and program stops, (and
> transaction will be rolled back) when x is None.

Or when `x` has no __len__ method. Which has the effect of
both: (1) making the code explicit, and (2) ensuring that
that a chicken, a pig, and/or a cow does not sneak past our
naive little "duck test".

> > Or when `x` is a numeric, as in:
> > 
> >     if x > 0:
> >         # blah
> >
> > You're okay with the explicit test.
> Yes, you know this code assumes x is numeric.  `if x:`
> doesn't tell the information to you. As a bonus, if x is
> None, `x > 0` raises TypeError on Python 3.

In the spirit of my last comment, i was going to say: "Or if
`x` does not support rich comparisons", but alas, it seems that
_all_ objects in Python support rich comparisons, even when
it doesn't make sense to! o_O For example:

    >>> False > 1
    >>> dir > 1
    >>> isinstance < 100
    >>> "" >= 10
    >>> (1,) <= 500
And down the rabbit hole we go!
Now, not only do we have magic that implicitly casts all
objects to booleans in conditional statements *AND* we have
arbitrary Boolean values assigned to every Python object,
but now, we discover that every Python object has been
assigned an arbitrary rich comparison value as well! I
assume the devs are using the boolean values 1 and 0 to make
the comparison work??? But would someone be kind enough to
chime in to confirm or deny my conjecture?

Of course, allowing all objects to use the `==`, `!=` sugars
makes perfect sense, but `<`, `>`, `<=`, `>=` are
meaningless outside of numeric-ish types.

> > So, from a standpoint of
> > consistency, you /should/ be okay with this:
> >
> >     if bool(x) == True:
> >         # blah
> >
> > But you're not! :-).
> I don't accept it because `if bool(x) == True` doesn't give
> any information than `if x:`. Both mean just `if x is
> truthy`.  No more information. Redundant code is just a
> noise.

So what about:

    if bool(x):
        # blah

> [...]
> I can't agree with you here. And who agree with you in this
> thread?

This thread, like most every thread on this list (and
Python-ideas for that matter), only represents a handful of
Python programmers out of a large number of Python
programmers who exist in the wild. And since small
communities (just like a family) tend to be single-minded in
their views, the fact that no one in this thread is
supporting me is more a result of personal beefs and an
unwillingness to consider outside opinions than any proof
that my arguments are invalid.

Like Fakebook, mass media, most college campuses, and every
governmental organization on the _planet_, Python-list is an
echo chamber; an echo chamber that has insulated itself
against all outside influence, and who has become so
infatuated with its own vanity, that delusion has set in,
and now it considers itself as the only true judge of
objective reality, and all other judgements are inferior.

Fakebook is the quintessential example of how we wall
ourselves off from those opinions that we do not agree with.
At first, we think we are "free", but as time marches on,
and we continue to constrict our little "sphere of
influence" more and more, we eventually find ourselves
living in a prison of our own version of reality; one in
which we are surrounded by only those people who agree with
us; only those who parrot "yes, yes, yes" and never "no, no,
no". And it is such an environment as this that have given
birth to the most depraved ideas the human mind has ever
managed to conceive.

>From a perverted concept of "freedom"; to a narcissistic
self delusion; to a feeling of in-group superiority... that,
my friends, is the direct path to depraved actions.

> > While such type of optimization is possible, it's not easy
> > > as you think. You can overwrite `bool`.
> > >
> > > def bool(x):
> > >     return !x
> >
> > Oops. That looks like a syntax error. Ruby uses the "!" as a
> > logical not operator, _not_ Python.
> >
> >
> Sorry.  Writing Python in gmail textarea is bad experience.

Google software has to be the worst on the planet! And with
all the financial and technical resources Google has at its
disposal, you'd think they could do a little better. Listen,
i don't mean to be a unappreciative jerk, because after all,
were it not for the Google Chrome Webbrowser[1] Microsuck
might have never gotten off its lazy bum and *FINALLY*
invested some R&D into that atrocious Internet
Exploder[2][3]. And sure, Google has always been kind enough
to give away free software, but while beggars can't be
choosers, useless software is still useless software. Why
even go to the trouble of writing anything if the end
product will just frustrate the hell out of every user
unlucky enough to try it? And while Gmail is not the worst
interface i've ever used, it's not even moderately good
software. The damn spell checker is broken half the time and
the interface is slow, among other things...

If i were to speculate, my suspicion is that Google is not
hiring qualified people. Yes, yes, i know... there is this
ubiquitous "assumption" that Google is employing the best
and the brightest engineers in the world, but from the
evidence i have seen, this is not always the case. It seems
that Google's hiring practices are more concerned with
irrelevancies like political affiliation and sexual
orientation than any _real_ technical ability (the echo
chamber strikes again!). In one specific case i remember
quite vividly, the lead engineer had to appeal to a member
of the google community to write a fairly simple script that
the lead engineer was unable to write himself. And upon
discovering that the lead engineer was a total incompetent
who couldn't even write code for the project he was hired to
lead, I was shocked. But i suppose if Google wants to
forsake its future and the future of its employees and stock
holders so it can be feel-good social justice laboratory,
well then, who am i to tell them what to do?

The self driving car be damned!

Besides, i hear rumblings that Amazon is about to enter the
(soon to be highly competitive) self driving car market. And
let's not forget, that the Asians are light years ahead of
the West in robotics and automation, and with their dirt
cheap labor and little regard for environmental issues, they
will ultimately win this technological war.

So while Google runs itself around in circles fretting over
the enviroment and engineering the next generation of
snowflake PTSD treatment centers (talk about a clash with
reality!), the Asians are working 24-7-365 inventing the
practical technology that will transform our world in ways
that we still cannot even imagine. Everything is about to
change: how we live; how we make war; how we make /love/.

Oh, Sergy Brin, why don't you take off the goofy google
glasses and just grab a fiddle already!

> > Although, your point -- "that a programmer can shoot
> > [him/her]self in the foot" -- is really moot,
> No, it's not my point. My point is just optimizing `bool(x)
> == True` is not easy as static language. Optimizer must be
> very very conservative about changing language behavior.

I agree. There are many ways a programmer can shoot a toe,
or even an entire foot, off. And highly dynamic languages
like Python make this deceptively easy:

[A random pynoob writes some code, then executes it...]

    "Hey, look! My code runs without errors the first time! :-)"
[A few minutes later...]

    "Aw snap! :-("
Yes, and good thing your script was not mission critical
(Crash + Burn!). And as many a dynamic language user has
learnt, static type checking (as onerous as it can be at
times) just might save your bacon... and ducks do not lay
golden eggs! ;-)

[1] Which i did use and support for a year or so, but after
becoming dissatisfied with the software, i returned to the
loving arms of my old friend the flaming fox.

[2] Which now they call "Edge", and which finally supports
HTML5. 'Bout time!

[3] Among many other things Microsuck had been dragging its
bum about for decades! But i suppose sucking every last dime
out of the latest iteration of windows95 (aka: lipstick on a
pig) was more important than actually writing good, 21st
century interfaces and supporting modern HTML elements and
internet protocols. Go figure!