Lambda the Ultimate

inactiveTopic Python Compared to Other Languages
started 9/29/2001; 10:54:10 AM - last post 10/3/2001; 2:11:30 AM
Ehud Lamm - Python Compared to Other Languages  blueArrow
9/29/2001; 10:54:10 AM (reads: 3038, responses: 7)
Python Compared to Other Languages
Some readers may have concluded from a recent discussion that LtU has an anti-Python bias. Nothing can be further from the truth. In fact, Python has a dedicated LtU department: even Java didn't get this honor.

On the other hand, this site is dedicated to programming languages, and many of us have experience in many languages, on top of a theoretical knowledge of programming languages. This means that we like to form our own opinions. I think this is a great thing, and I try to learn from all the viewpoints heard on LtU.

The link above is to a Python.org page listing documents comparing Python to other languages. In general, I am no great fan of language comparisons, agreeing with Stroustrup that language comparisons are rarely meaningful and even less often fair. This is why I try not to post them here, leaving them to comp.lang.misc.

Still, even if only to give a more balanced view, I thought I'd link to this page.

I for one would be happy to hear reasoned discussion on topics like readability - including the readability of Python as compared to other languages.


Posted to Python by Ehud Lamm on 9/29/01; 10:55:55 AM

jon fernquest - Re: Python Compared to Other Languages  blueArrow
9/30/2001; 1:43:42 AM (reads: 1662, responses: 0)
One of the features originally advertised for the Guile dialect of Scheme was translation from Python, and several other scripting languages syntaxes, into Scheme. A similar idea to the Microsoft's Common Language Runtime and Intermediate Language.) I see they have a partial implementation of Tcl. Does anyone know how (or if) the Python project is coming?

I've started using the super-stripped down Lua instead of Python recently since most of the little programs I write have to be very small and compact. Is it possible to use a small compact subset of Python?

(Aside: A translator for the tiny Lua language seems like it would be a very reasonable programming project and a good way of putting the techniques of "Essentials of Programming Languages" and "Lisp in Small Pieces" into practice for a real as opposed to toy language.)

Lua and Python make it relatively easy to interface to a given platform's API's, an often time-consuming activity. Anyone have any good references for more programming language theoretic perspective on binding a language to a platform's API's?

The everything-is-a-table one-way-of-doing-things philosophy makes for extreme simplicity when compared to Python. Good or bad points?


In a thread on the Lua mailing list there was an interesting analysis of the options for interfacing Lua to the (huge) WinCE API:

http://groups.yahoo.com/group/lua-l/message/5811

Later in the thread this interesting paper was mentioned:

"Calling the C world from the Scheme World"
http://www.angelfire.com/wa/brianbec/siodffi.html

And there is this attempt to organize and make sense of "foreign function interface" options (for interfacing a high-level language to the underlying platform API in a low-level language):

"Design Issues for Foreign Function Interfaces A survey of existing native interfaces for several languages and some suggestions"
http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html

Cheers,

Jon Fernquest bayinnaung@hotmail.com

John Lawter - Re: Python Compared to Other Languages  blueArrow
10/1/2001; 7:44:40 AM (reads: 1596, responses: 1)
I think some of the readability claims stem from comparisons with Perl, which was (is ?) viewed as a competitor. Of course, you could say that almost anything is more readable than Perl...

Also, Python is a descendant of ABC. ABC was designed to be a simple, easy to use and learn language. The indendation based grouping comes derives from it.

Python uses whole words where other languages use symbols. For example, "not" instead of "!" and "or" instead of "|", which may be easier for the average person to understand.

Part of the readability though (and I may be going out on a limb, here) has more to do with the programmer rather than an intrinsic property of the language. I think that certain languages (C/C++ and Perl among them) influence programmers to produce code that is not always easy to read or understand and first glance. These languages seem to encourage brevity and short-cut taking. I don't think Python does this as much. So, part of Python's "readability" is caused by the good programming habits that the language ( and the example code written by its user community) produce.

Ehud Lamm - Re: Python Compared to Other Languages  blueArrow
10/1/2001; 8:40:52 AM (reads: 1670, responses: 0)
A large Part of the readability though (and I may be going out on a limb, here) has more to do with the programmer rather than an intrinsic property of the language.

Hope you like my addition.

One should not overlook the fact lanugage features do have readability implications. For example, keyword assoication for parameters helps readability but must be done on the language level.

A more interesting case is the use of high level language features. Since we disucssed generators, take this as an example.

You can program without generators, but then you may have to roll your own when you need this kind of functionality. Since this is far from trivial you are going to end up with quite a lot of complicated code. Adding this control structure to the language can thus arguably enhance readability.

This amy also be seen as an argument about Scheme readability: sure continuations are cool, but code that uses them to achieve what Icon does with the keyword suspend is going to be harder to read. This is exactly the same argument favoring for loops to goto statements.

Notice that this argument works without the need to classify continuations as a difficult to understant "mathematical" concept.

Adewale Oshineye - Re: Python Compared to Other Languages  blueArrow
10/1/2001; 9:20:08 AM (reads: 1576, responses: 1)
I can see the advantages of having sophisticated features built into the language rather than requiring them to be implemented repeatedly by every programmer. However we have to take into the principle that Stroustrup says guided the evolution of C++: you shouldn't have to pay for what you don't use.

Trying to make every feature available increases the cognitive load on all users of a language whilst benefitting only a small number. MS Word is a classic example of trying to please all possible user-groups. Everybody uses a different 20% of it's feature set.

One possiblity would be to add features to a language based on the idioms that are actually observed in use. If the language developers keep seeing people attempting to re-invent generators then there's a clear case for making that a part of the language.

As for readability I think we shouldn't overlook the impact of idiomatic code. [http://c2.com/cgi/wiki?PythonIdioms] contains some useful examples for Python. The evolution of Python, for instance, tries to be consistent with certain principles [http://c2.com/cgi/wiki?PythonPhilosophy]. So whenever people suggest adding a do...while loop syntax to the language the standard response is that people should use the following idiom instead.

while 1: break

The core idea is that: "there should be one -- and preferably only one -- obvious way to do it" which means that similar problems tend to get solved in similar ways. This is perhaps a better explanation for Python's readability. Obfuscated Python code happens but it requires a willful disregard for the language's philosophy/culture.

Frank Atanassow - Re: Python Compared to Other Languages  blueArrow
10/1/2001; 11:53:38 AM (reads: 1644, responses: 1)

Also, Python is a descendant of ABC. ABC was designed to be a simple, easy to use and learn language. The indendation based grouping comes derives from it.

Directly derives, since ABC probably derived it from Miranda, and Miranda from ISWIM.

One should not overlook the fact lanugage features do have readability implications. For example, keyword assoication for parameters helps readability but must be done on the language level.

In Scheme, keyword parameters can be implemented with macros.

Whether or not a feature can be implemented within a language, rather than added as a primitive, depends on how expressive the language is. When a language is expressive enough to implement what must be primitive in another language, it is almost always better to do so, because 1) it makes the specification smaller, 2) it lets you manipulate that feature use the other parts of the language, 3) if you have a module system you can decide whether or not to import it. The arguments against doing so are usually that, when something is primitive, you can sometimes implement it more efficiently, and provide better error-checking.

You can program without generators, but then you may have to roll your own when you need this kind of functionality. Since this is far from trivial you are going to end up with quite a lot of complicated code

That's what libraries, modules and other abstraction features are for!

This amy also be seen as an argument about Scheme readability: sure continuations are cool, but code that uses them to achieve what Icon does with the keyword suspend is going to be harder to read. This is exactly the same argument favoring for loops to goto statements.

That is no argument at all. Just bind it to a name. suspend gets implemented as a procedure. In Scheme, the primitive would be implemented as a syntactic keyword, so they wouldn't even look any different. And as a procedure you could manipulate within the language, e.g., you could pass it to another procedure, which is impossible with a primitive.

However we have to take into the principle that Stroustrup says guided the evolution of C++: you shouldn't have to pay for what you don't use.

Wasn't he referring to efficiency? I agree with this on both counts, though.

So whenever people suggest adding a do...while loop syntax to the language the standard response is that people should use the following idiom instead.

while 1: break

This is a bit different from the situation where you implement control structures with continuations. In fact, it's a bit funny because there are two instances of this phenomenon here. First, you implemented do-while with while-do. Second, you implemented booleans with integers! :) I'll get back to that later; first let me explain why I think this kind of unification is different from the continuation case.

First, using continuations, I can implement for-do loops, while-do loops and do-while loops, generators, non-pre-emptive multitasking and, in the presence of dynamic binding, exceptions and resumptions, and, I think, in the presence of asynchronous signals, even pre-emptive multitasking, and many other wondrous things. So there is a very high value-to-cost ratio for continuations. But if all you can implement with while-do is do-while, then that's not very impressive.

Second, in the case of continuations, I can package up all these features into a set of procedures, which can then be used in a fashion which is more-or-less indistinguishable from the versions implemented as primitives. For example, if I implement exceptions, I get procedures handle (or try, if you will) and raise, and the usage is not much different from having them as keywords. In other words, since they are first-class citizens, I can bundle them up and assign them names. But while-do is not a first-class citizen, it is a piece of syntax, and I can never name it "do-while".

Third, there is a small possibility for inefficiency. A really naive optimizer might not recognize the obvious optimization. Or, suppose you have a program generator which for some strange reason (and, believe me, it can happen) replaces 1 with some arithmetic expression which evaluates to 1. Then the optimizer will definitely miss the optimization.

Now let's get back to your representation of the booleans as the integers. This is also a sort of language unification. It makes your language more orthogonal, right? But why stop there? After all, you can implement strings with integers, so we don't need those either. And characters too. And, wait a minute, we can actually implement integers with booleans by encoding them in binary! Taken to an extreme, this approach will suggest you go back to programming in machine code!

Obviously you wouldn't go that far, but it raises the question of where to draw the line. If you use base your decision on just some fuzzy subjective opinion, then someone is bound to disagree with you and call you to task, and probably you will waffle after thinking about it for a while too. Ask yourself: why am I identifying true with 1 and not 6712319? It's an arbitrary choice, and there's going to be somebody in this world for whom a different representation is more convenient. The number of possible embeddings increases dramatically as the datatypes involved increase in complexity, so the arbitrariness of the choice does too.

So (quite apart from the fact that you are giving your programmer more ways to trip himself up), while this sort of unification makes sense for simple types like bools and ints, it doesn't scale well.

Also, most languages will have user-defined datatypes which it wants to treat as well as primitives, so this little infelicity for the sake of convenience will look like a wart. For example, automatic coercions between ints and reals are nice at first, but if the user defines his own numerical system, then it will always be inferior to the built-ins for lack of coercions (except in C++, but the coercions there cause endless problems too).

OTOH, if your approach is to distinguish booleans and integers, but also provide explicit coercing functions between them, you are not making an arbitrary choice, because you can have as many coercions as you want. Furthermore, you can give each representation of bools-as-ints a name. Sounds lame for such a simple case, but consider representing complex numbers as real tuples: there are polar and cartesian representations.

Well, enough rambling... I was going to talk about type safety, but I'm all rambled out.

Ehud Lamm - Re: Python Compared to Other Languages  blueArrow
10/3/2001; 2:11:30 AM (reads: 1631, responses: 0)
Essentially what you are advocating is layered or stratified language design.

This in itself is a crucial concept, directly related - as you mention - to the idea of abstraction. The problem with it, as regards programming languages is that if the layers are not mandated by some standard or reference implementation, you are back to the old issues of reuse.

Reuse is the holy grail of SE - but in practice it rarely achieves its goals. There are many reasons for this, the most improtant of which ar finding the right reusable components, and integrating different components together.

In the context of language design, it should be evident that an Icon progrmmer for example knows about suspend, where as simply by learning Scheme you will not know about generators. You must learn these concepts seperately, which makes them seem harder than they really are.

The second issue is how all these macros and extensions coexist. This is not trivial, though some of the work Scheme (e.g., Scheme macros) may help.

Ehud Lamm - Re: Python Compared to Other Languages  blueArrow
10/3/2001; 2:36:13 AM (reads: 1642, responses: 0)
Thakns for the links.

It is indeed impractical and bad engineering to add every conceivable feature the a language. perhaps this is why there are so many languages, each with different features

It has been suggested many times that idioms can inspire language features.

I think I posted here a link to a paper (by Yossi Gil) about mining design patterns for language features.