crazy programming language thoughts

Paul D. Fernhout pdfernhout at kurtz-fernhout.com
Thu Aug 21 21:41:51 EDT 2003


Ryan Lowe wrote:
> the basic concept would be to use identifying words in front of the
> arguments to determine their identity as well as making the function call
> read more like an english phrase. for instance, take the simple python
> statement:

>>>>vtext.replace('a', 'b')
> wouldnt it be nicer (more english-like at least) to say:
>>>>replace 'a' with 'b' in vtext

> i just want to say that i know i saw a similar idea in another language, a
> few years ago, but damned if i remember where or what language. i guess the
> language didnt make it:( but if anyone knows a language like this, PLEASE
> let me know.

You may be thinking of Smalltalk.
   http://www.smalltalk.org/
although there are other languages with related phrasing (like in 
HyperCard? and even COBOL?).

The Python code:

   x = sin(10) + 50 * 20 * self.myfunctionXY(cos(30), 40)

would be in Smalltalk something like:

   x := 10 sin + (50 * 20 * self myfunctionX: 30 cos y: 40).

where the order of precedence is unary (sin, cos), binary (+, *) and 
then keyword (myfunctionX:y:). Evaluation is otherwise left to right. 
Note the extra parentheses needed to ensure "*" is done before "+" as 
there is no other order of precedence. Note, Smalltalk has very few 
reserved words --- even things like "if" and "while" are typically done 
in Smalltalk as overrideable keywords of True and False classes (and the 
compiler may optimize these inline in some cases).

I prefer Smalltalk's keyword type method function calls over Python's 
nameless parameters (yes they can be named but it is inelegant) because 
I think keywords are more self documenting of parameter expectations 
than function calls which do not indicate the possible number of 
paraeters or hint at their uses. However, I do prefer Python's use of 
significant white space over Smalltalk's use of braces to mark off 
blocks. (Although Smalltalk blocks are very powerful idea Python doesn't 
quite have except maybe as nameless functions.)

I tend to use Python over Smalltalk these days because it is elegant 
enough, has lots of third party modules, has a good user community, has 
a fairly stable core, has books on it, appeals to C coders, is 
reasonably well licensed, and seems reasonably free of worries over 
copyright infringement etc (made easier because the language is 
different from most commercial languages, so there is little temptation 
or possibility to cut and paste library functions from commercial 
implementations).

But I do miss keywords and Smalltalk's level of integration and 
transparency related to development tools and debugging GUIs down to the 
VM. I also miss changing the program while it runs for a complex GUI 
app; although I have recently learned how to do this some in Python from 
someone elses' usenet post a while back (although reloading a module 
still klunkier than Smalltalk but maybe this can be fixed by a better 
development environment which works more like a Smalltalk image by 
modifying live code).

Incidentally, I'm not sure if Python really semantically needs the "." 
operator as opposed to a space, in which case it would look a little 
more Smalltalk like. For example:

   self.list.InsertColumn(0, "S")

would seem to me could still be meaningful as:

   self list InsertColumn(0, "S")

This of course might freak out some C programmers. But I don't think it 
would be ambiguous (I haven't thought this through completely though).

But then I might also make ":' optional (despite the argument it is for 
clarity), and I might enforce indentation at two spaces (like Occam) and 
I might enforce variable declarations before use to avoid bugs from 
typos in assignments (like Smalltalk), and I might get rid of the need 
for "self" in object method function declarations (like Smalltalk) by 
making it implicit and enforcing the "self" name for any such reference. 
That last might not be a great idea as one of the nice things about 
Python is that functions and methods don't need to be compiled in 
different ways, unlike Smalltalk where there is a difference in 
compilation structure between blocks and methods, but maybe something 
could be worked through by a smart compiler seeing that a function with 
a reference to self in it was treated specially, and functions assigned 
to method slots could be somehow be upgraded to accept another argument 
if they didn't reference self (or perhaps all functions could take an 
implicit self?).

I have tried to come up with a way to combine significant white space 
with Smalltalk syntax, but run up against difficulties with indenting 
keyword arguments when nesting keywords. I do think one can mix keyword 
function calls and significant white space easily and usefully, but 
perhaps only if one uses reserved words for block structuring (if, else, 
for, etc.) as opposed to Smalltalk's dynamic blocks. For example, the 
python method declaration

     def addOrFindStringRecord(self, string, readOnlyFlag = 0):
         if not readOnlyFlag:
             self.refreshLockFileIfNeeded()
         self.checkOpen()
         if Options.caching:
             try:
                  if self.stringCache.has_key(string):
                      location = self.stringCache[string]
                       return self.readStringIndexRecord(location)
             except TypeError, e:
                  # may generate type error if object not hashable
		 pass
          ...

becomes in this hybrid language (Pytalk?):

      def addOrFindStringRecord: string readOnlyFlag: readOnlyFlag = 0
         if not readOnlyFlag
             self refreshLockFileIfNeeded
         self checkOpen
         if Options caching
             try
                  if self stringCache has_key: string
                      location = self stringCache[string]
                       return self readStringIndexRecord: location
             except TypeError, e
                  # may generate type error if object not hashable
		 pass
          ...

(Not sure what to do about brackets, so I left them...)

I think that combination might be easier to maintain, but alas, Python 
is good enough that I don't see such a more perfect (IMHO) variant 
taking off anytime soon. Also, people would complain about the loss of 
variable length argument lists, and they would say it is good enough for 
IDE's to intelligently display parameter hints when hovering over a 
fucntion name.

In any case, while Python is, like just about all things in this 
beautiful and mysterious world, not quite perfect, (and also open to 
argument over what perfection is), Python is elegant and fun and 
practical. And thanks be to Guido (and others) for making it happen.

--Paul Fernhout



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----




More information about the Python-list mailing list