Alien whitespace eating nanovirus strikes again!

Markus Stenberg mstenber at cc.Helsinki.FI
Thu Jun 3 06:58:46 CEST 1999

"Hans Nowak" <ivnowa at> writes:
> Sometimes I dare read a few messages in the Perl newsgroups, and some 
> people there seem to think of Python as the summum of inflexibility. 
> It doesn't allow you enough freedom to code what you want. Just look 
> at that whitespace! -- Nonsense, of course. The fact that Python 
> heavily uses whitespace doesn't mean you cannot code what you want, 
> and in a way you want it. The same thing can be said for Scheme and 
> Lisp. They use lots of parentheses, and while the languages look 
> peculiar because of that, it doesn't make them any less flexible. On 
> the contrary.

Au contraire; Python isn't whitespace-fasist, really. For basic
GNU-indentation-style CurlyPython it takes only few-line preprocessor to
produce from this, beautiful GNU-style CurlyPython example: (Ok, I should
call it 'slant'-style, however, it _is_ whitespace-neutral)

-------- cut -------- curly_hello.cpy -------- cut -------- 
        class foo
      def x(self): print 'hello'
     #.. or..
    def y(self)
  print 'hello'

-------- cut -------- 

Ugly, whitespace-infested result like this:

-------- cut -------- -------- cut -------- 
class foo:
   def x(self): print 'hello'
   #.. or..
   def y(self):
      print 'hello'

-------- cut -------- 

.. Now to add CurlyPython support to __import__ so it can eat .cpy:s and
preprocess them automatically. Hmm. :) 

(As a joke, simplified CurlyPython converter supplied at end of the

> Whitespace in Python enforces readability, it does not force you to 
> use a certain coding style. I really cannot understand why some 
> people seem to think Python is not flexible. It actually allows very 
> much, just takes out brain-damaged things, like for instance adding 
> strings and integers, which makes as much sense as adding file 
> objects and complex numbers. :o)


> > Okay, I *will* say the same about Perl and its curly braces requirement:
> > 
> > } That is, if something's worth doing, it's worth driving into the
> > ground to the
> > } exclusion of all other approaches. Look at the use of curly braces in
> > } Perl.
> $Yes, (%(and) quite) @a { $few %other $annoying {characters...} }

No shit - but that's being _post-modern_, not fascistic forcing to using
obscure non-whitespace markers for all variables! Really!

> > Okay, sorry for all this, it's out of line, I just needed to blow off
> > steam. :)
> Me too. :)

Join the club.

> Veel liefs,
> --Hans Nowak (ivnowa at
> Homepage:

-Not-yet-member-of-Larry-Wall-fanclub-ly yours, 

(and now the uber-ugly CurlyPython converter as I promised ;>)

-------- cut -------- 
import re, string

INDENT_LEVEL=4 # per curly

def curl(l):
    res = []
    start_curly = re.compile("^\s*{").match
    end_curly = re.compile("^\s*}").match
    # Note: real parser would make this actually robust + pretty.
    # But CurlyPython is just a joke, anyway ;-)
    ind = 0
    comm = 0
    for line in l:
	line = string.strip(line)
	if start_curly(line):
	    res[-1] = res[-1] + ":"
	    ind = ind + 1
	if end_curly(line):
	    ind = ind - 1
	line = "  "* ind + line
    return map(lambda x:x+"\n", res )

if __name__ == '__main__':
	# Usage: python <whatever> filename_base (without .cpy)
-------- cut -------- 

	"If you want to travel around the world and be invited to speak at
	a lot of different places, just write a Unix operating system."
		-- Linus Torvalds

More information about the Python-list mailing list