Does Python really follow its philosophy of "Readability counts"?

P

Paul Rubin

Steve Holden said:
Sometimes I just want to shout "be quiet, Python is just fine the way it
is", but alas your objections are usually too sensible to be dismissed
in that way. In the long term I feel it has to be good for Python that
it has such conscientious critics.

Thanks for the kind words. But I'm not aiming to be a conscientious
critic; I'm just an everyday user who sometimes has to grapple with
the limitations of the tool, and look for ways around them.
 
R

Russ P.

I'd say functional programming emphasizes a style that avoids use
of side effects, but saying "functions cannot have side effects" is
a bit of an overstatement.  Even Haskell lets you code effectfully
when necessary, using the type system (IO Monad) to separate
effectful code from pure code.

I think we need to distinguish here between purely functional
languages and a languages that support functional programming. I would
be even more averse to a purely functional language than I am to a
purely OO language such as Java.

One feature of Ada that I always thought was a good idea is the
distinction between functions and procedures, where functions are
guaranteed to not have side effects. But I don't think Ada allows
advanced functional programming such as passing functions as arguments
to other functions.

Scala combines advanced functional and OO programming very nicely as
far as I can tell (I've read some about it but haven't used it yet). I
don't think it distinguishes between functions and procedures, but it
does allow you to declare function arguments as "val" (value) or
"var" (variable), where the former cannot be modified.

If Scala only had default arguments and argument passing by keyword
(and maybe "continue" and "break"), I think it would be *very* hard to
beat for a very wide range of applications.
 
J

James Mills

One feature of Ada that I always thought was a good idea is the
distinction between functions and procedures, where functions are
guaranteed to not have side effects. But I don't think Ada allows
advanced functional programming such as passing functions as arguments
to other functions.

Russ please do your research before you post.

The whole idea of the Functional Paradigm is _in fact_ computing
expressions and functions. Functional Programming is an implementation
of formal systems (calculus). Therefore it would be very useless
for any functional language to not do what you describe aboave.

Passing the result of a function as input to another function
_is not_ Advanced Functional Programming, but a requirement
of the functional paradigm.

--JamesMills
 
P

Paul Rubin

Russ P. said:
I think we need to distinguish here between purely functional
languages and a languages that support functional programming. I would
be even more averse to a purely functional language than I am to a
purely OO language such as Java.

I guess I'm not sure what you're considering "purely functional
language" to mean, in this context. Haskell has a print function that
prints on the terminal. It's "purely functional" in the sense that it
conceptualizes an expression like 'print "hello"' as a "state
transformer function" that takes as input a state of the world in
which your screen is blank, and returns as output a state in which
your screen has "hello" on it. Your program constructs this state
transformer, and then the runtime system applies the transformer to
the external world and presto, "hello" appears on your screen. But
that is just the metaphysics of it. Normally in practical usage,
you'd think of the print function as something you use more or less
the way you'd use it in Python, except that you can only use it in
functions with IO in their type.
One feature of Ada that I always thought was a good idea is the
distinction between functions and procedures, where functions are
guaranteed to not have side effects. But I don't think Ada allows
advanced functional programming such as passing functions as arguments
to other functions.

Well, Haskell uses its type system to encapsulate functions with side
effects. If you want to open a file or print something, you can only
do it from a function with IO in its type. Similarly, if you want to
do the equivalent of assigning a new value to a variable, you have to
use a special type for that purpose, and the type isolates any code
that can affect that variable, etc. I think that generalizes what
you're describing about Ada. It's actually very beautiful but takes
some getting used to.
If Scala only had default arguments and argument passing by keyword
(and maybe "continue" and "break"), I think it would be *very* hard to
beat for a very wide range of applications.

I guess I don't understand the issue about continue and break, since
if Scala is anything like Haskell, the issue doesn't really arise.

Haskell doesn't have keyword args per se, but there are various ways
of simulating them, at least for the usual sorts of applications.

Anyway, Haskell is quite a bit more formal than Python, and it doesn't
yet have as much library support for everyday tasks, and generally
suffers from the not-always-practical priorities of being a "research"
language, but some people have switched to it from Python. I
personally find Haskell very interesting but too difficult in some
aspects, and lacking in "creature comforts" compared with Python.

I liked Tim Sweeney's talk about where he thinks PL design should go:

http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf
 
M

Michele Simionato

I have a situation which I face almost every day, where I have some
gigabytes of data that I want to slice and dice somehow and get some
numbers out of.  I spend 15 minutes writing a one-off Python program
and then several hours waiting for it to run.
Often, the Python program crashes halfway through, even though I
tested it on a few megabytes of data before starting the full
multi-gigabyte run, because it hit some unexpected condition in the
data that could have been prevented with more compile time checking
that made sure the structures understood by the one-off script matched
the ones in the program that generated the input data.

I know the feeling. The worse thing is when you have a stupid typo
(which would be immediately caught by a compiler) which affects a
section of the code that runs after 8 hours of computations. Pylint
helps - when you remember torun it on all your code base - but it
is definitely not the same as a compiler.
I would be ecstatic with a version of Python where I might have to
spend 20 minutes instead of 15 minutes writing the program, but then
it runs in half an hour instead of several hours and doesn't crash.  I
think the Python community should be aiming towards this.

Dunno. Python has been designed from the start to be fully
dynamic and with no type checks, I don't think it is really
possible to change that. On the other hand, one could envision
a Python-like language with more type safety (there are already
a few experiments in that direction).
Personally, I would be glad to trade some flexibility for additional
safety; if you we get more speed as an additional bonus, that's fine
too.
 
R

Russ P.

(..)


Russ please do your research before you post.

Please spare me the pedantry.
The whole idea of the Functional Paradigm is _in fact_ computing
expressions and functions. Functional Programming is an implementation
of formal systems (calculus). Therefore it would be very useless
for any functional language to not do what you describe aboave.

So what?
Passing the result of a function as input to another function
_is not_ Advanced Functional Programming, but a requirement
of the functional paradigm.

Oh, excuse me for misusing the word "advanced." I was merely using it
to distinguish it from programming without side effects, which I would
regard as more "basic" functional programming. But then I'm not as
sophisticated as you.

By the way, your statements earlier to the effect that Python is as
good as any language for large-scale safety-critical systems were very
interesting. I'm wondering how you "know" that.

Also, have you checked with Boeing or ARINC on that? Last I heard,
those neanderthals at ARINC are still suporting Ada as the standard
language for flight systems. I urge you to get in touch with them and
straighten them out right away.
 
M

Michele Simionato

We are in an era for programming languages sort of like the Windows 95
era was for operating systems, where everything is broken but some of
the fixes are beginning to come into view.  So there is no language
that currently really works the right way, but some of them including
Python are (one hopes) moving in good directions.

To be fair, this has been true for the last 50 years. If a language
that works the right way really existed, CS would be dead and there
would be no progress to make. Happily I think we will never end in
that situation ;)
 
R

Russ P.

On Jan 14, 9:04 pm, "James Mills" <[email protected]>
wrote:

Oh, by the way, please quit emailing me every time you reply to one of
my posts. You're the only one here who does that, and it isn't
necessary. Thanks.
 
M

Michele Simionato

I started looking at Scala a while back. It is has many nice features.
It seamlessly combines object orientation with advanced functional
programming.

I don't like that. Scala was designed with the idea of putting
together the two worlds, by I think the result was to get the
complications of both worlds. I don't think a SML-like functional
language needs to be integrated with object orientation, it is fine
just without it. The old quote
applies:

"""
Programming languages should be designed not by piling feature on top
of feature, but by removing the weaknesses and restrictions that make
additional features appear necessary. -- William Clinger
"""
 
R

Rhodri James

If the language-tool combo uses the info in a formal way, they are
extensions, not conventions.

If the tool isn't part of the compile/run cycle, I'm not convinced that
that's a useful view to take. It is useful to regard to C preprocessor
statements as extensions to C, though it's had the result that nobody
uses that quite general purpose preprocessor for anything other than C.
It's less obvious that the conventional folding marks "{{{ ... }}}"
some editors (can be made to) recognise are usefully considered as
extensions to any language.

But this is just quibbling over semantics.
 
M

Michele Simionato

I really wonder why peoples that seems to dislike one of the central
features of Python - it's dynamism - still use it (assuming of course
they are free to choose another language). And FWIW, I at least had a
partial answer on this.

It could just be an issue of practicality. Python is an industrial
strength language with libraries for everything and you can use it for
your daily work. There are nice little languages out there that are
however not usable for real work because of lack of libraries/lack of
support/small community etc.
 
J

James Mills

It could just be an issue of practicality. Python is an industrial
strength language with libraries for everything and you can use it for
your daily work. There are nice little languages out there that are
however not usable for real work because of lack of libraries/lack of
support/small community etc.

So _exactly_ how does this thread relate to the
subject: Does Python really follow its philosophy of "Readability counts"?

--JamesMills
 
S

Steven D'Aprano

So _exactly_ how does this thread relate to the subject: Does Python
really follow its philosophy of "Readability counts"?

If you had followed the thread since the beginning, you'd see that the
topic has evolved (or perhaps strayed) from the original subject.
 
M

Michele Simionato

I don't understand why some folks spew such violent rhetoric against
the idea of augmenting Python with features to alert you automatically
when you depart from the convention, so that you can check that the
departure is actually what you wanted.  A lot of the time, I find, the
departures are accidental and automated checks would save me
considerable debugging.

I would be fine having something like pylint built-in in the language
and running at every change of the source code (unless disabled with a
command line switch). I think this is the only reasonable solution to
get some additional protection we can hope for. A true change of the
language IMO is impossible, both technically, politically and for
legacy issue. Also, I am not convinced it would be a good idea, even
theoretically. It is easier to write a new Python-like language
from scratch than to add type checking to Python (I think you
were not proposing adding type checking in this post, right?).

Michele Simionato
 
M

Michele Simionato

So I can claim that Python is not strictly object oriented until it
gets encapsulation (in the sense of data hiding). That is simply a
fact, and no amount of pleading or obfuscation will change it.

Should Python get true encapsulation? I don't know. Maybe
encapsulation cannot be added without excessive overhead or without
compromising other more important aspects and features of the
language. But I do know that not having encapsulation is a limitation
to the use of Python for good software engineering. I may be in the
minority in the Python "community" on this one, but I am apparently in
the majority in the OO programming "community."

There are lots of Python developers (and most of the core developers)
that think the OO community is wrong about enforced encapsulation.
Personally, I think in a few years everybody will realize the mistake
of enforced encapsulation and that the OO definition in the Wikipedia
page will be changed. Even if not, Wikipedia definitions does not
matter much, everybody has his own idea of what OO means,
and the Python definition is good as any other. Don't get pissed off
on words.

Michele Simionato
 
J

James Mills

I would be fine having something like pylint built-in in the language
and running at every change of the source code (unless disabled with a
command line switch). I think this is the only reasonable solution to
get some additional protection we can hope for.

Protection from what ?

If one is a clumsy programmer, then perhaps
one ought to be using a language that holds one's hand.

--JamesMills
 
J

James Mills

There are lots of Python developers (and most of the core developers)
that think the OO community is wrong about enforced encapsulation.
Personally, I think in a few years everybody will realize the mistake
of enforced encapsulation and that the OO definition in the Wikipedia
page will be changed. Even if not, Wikipedia definitions does not
matter much, everybody has his own idea of what OO means,
and the Python definition is good as any other. Don't get pissed off
on words.

Amen! The first thing said right in this entire thread! (one of)

--JamesMills
 
M

Michele Simionato

If one is a clumsy programmer, then perhaps
one ought to be using a language that holds one's hand.

Yes, and I use Python because it is a language that holds my hand,
otherwise I would use C and enjoy segmentation faults all the time.
 
P

Paul Rubin

Michele Simionato said:
To be fair, this has been true for the last 50 years. If a language
that works the right way really existed, CS would be dead and there
would be no progress to make. Happily I think we will never end in
that situation ;)

I'd say there was a time Lisp worked the right way, and a time C
worked the right way, and maybe a time Python worked the right way,
and for a while, Algol 60 was perfection embodied. But times have
changed more than those languages have, so they no longer work the
right way. The right way basically can never mean more than "the best
that can be done using current technology". Right now, the stuff
happening in the programming-language research world is light years
beyond what us poor peons are using in everyday hacking, while we face
harder and harder challenges due to bigger and faster computers
leading to more complex software, and a vastly enlarged attack surface
exposed to internet security threats.

Have you looked at Tim Sweeney's talk that I mentioned in another post?

http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,488
Latest member
MohammedHa

Latest Threads

Top