How coding in Python is bad for you

Chris Angelico rosuav at gmail.com
Mon Jan 23 19:56:01 EST 2017


On Tue, Jan 24, 2017 at 11:44 AM, BartC <bc at freeuk.com> wrote:
> On 23/01/2017 22:09, Chris Angelico wrote:
>> 1 is wrong - there is structure, same as in every language. Or if it's
>> true, it's true in every language.
>
>
> Python (I think in common with other scripting languages) allows you to
> place statement outside functions, either before, after or in-between
> functions. While functions themselves, as well as imports, can be
> conditionally defined.

In other words, Python doesn't have arbitrary, useless structure by
forcing you to put everything inside a class definition and then
inside a method, as in Java. How is that a reason that Python is "bad
for you"?

REXX has even less structure than Python - it doesn't even have
functions, just labels, so you can actually have two functions that
share a common tail. And yes, you can abuse that horrendously to
create unreadable code. Is REXX a bad language because of that? No.
You can use structure badly, and you can use freedom badly.

>  2 is also trivially true - you can
>>
>> ALWAYS define variables wrongly. Yes, okay, so you don't have data
>> type checking, but that's only going to catch a specific subset of
>> errors.
>
>
> With Python, you can take function names that you've defined, imported
> modules, or math.pi, and set them all to "edward g robinson". (The name just
> came into my head..)

Yes, and? You can do that in other languages too. So? Again, how is
this proof that Python is "bad for you"?

>> 3, well, okay. But if you get your indentation wrong in C++,
>> Java, etc, it should fail code review.
>
>
> With C++ or Java, it's possible to tell the indentation is wrong (because of
> the extra redundancy of having the indentation /and/ block delimiters).
> That's a bit harder in Python making source more fragile.

With C++ or Java, it's possible to tell that the braces are misplaced
(because of the extra redundancy). When that happens, the compiler
won't tell you; it'll just silently do the wrong thing. In Python,
that can't happen. Python is therefore more robust.

What's to say which is correct?

>> 4 is flat out wrong.
>
>
> (About having no compiler.) Yes (C)Python does have a byte-code compiler but
> there are a vast range of errors that it cannot trap at compile-time because
> of its dynamic nature.
>
> Maybe you can run tools to do extra analyses, but as it's normally used,
> many errors are not detected until execution. Spelling errors in names for
> example. (Actually when I tested my assertion above I assigned to math.p
> rather than math.pi; no error not even at runtime, just the wrong result. Or
> technically the right one, as math.pi still had the usual value!)

Plenty of editors can catch those even before you run the code. And
there are languages with far more structure that still don't protect
you against very common classes of bug.

if (i = 1) {
    printf("i is 1.... now.");
}

Some compilers will give you a warning for this code, if you ask for
all warnings to be enabled. Others won't. The C language doesn't
protect you. Should we abolish C?

> I'm not criticising it, just stating facts which may well have been the
> experience of the guy who wrote the article, giving the impression of a more
> chaotic, free-for-all language than they may have been used to, or expected.

And because it's not what he's used to, it is a fundamentally bad
language. That's the sign of a badly uninformed post.

ChrisA



More information about the Python-list mailing list