Whython – Python For People Who Hate Whitespace

Whython : Whitespace Haters Python

http://writeonly.files.wordpress.com/2010/04/whython.png?w=590

Example

Clearly Confusing (standard 3.x):

for ii in range(10):
    print(ii)
    print("which is %s" % (['even','odd'][ii % 2]))

Improved:

for ii in range(10) {
    print(ii);
    print("which is %s" % (['even','odd'][ii % 2]));
}

Maximum Enterprise Whythonic:

for ii in range(10) { print(ii); print("which is %s" % (['even','odd'][ii % 2])); }

How about some Scheme with your Python?

defun myfun():  return 1
assert myfun() == 1

Or add some Ruby shine?

def myfun() BEGIN return 1; END
assert myfun() == 1

Why Whython?

  • Less Whitespace, More Enterprise
  • It’s not a real language without braces and semi colons
  • Whitespace delimited is like so restrictive, man!
  • Python sucks for code golf
  • Finally, a Python for everyone who can’t decide between tab and space
  • Possibly (as in the mathematical sense – a small non-zero probability)
    useful for doing command line one liners in python
  • Help determine how bad a PEP/developement idea needs to be before
    someone gets kickbanned from #python-dev.

More seriously

  • reading the Dragon Book [Aho86] gives a person dangerous ideas
  • good excuse to deep dive into the python interpreter source code and the AST, dis modules
  • finally wanted to learn GDB and python -d debug mode
  • humoring trolls is fun
  • for education, the whitespace thing really can cause problems. When
    copying code out of books into IDLE or IPython, there are corner cases when
    it terminates blocks “too early”, confusing new learners.
  • preparation for the “Python Spring Cleaning” project, to see how hard it is
    to get and modify source, write a PEP, raise bug ideas, talk in irc, etc.
  • since this is unlikely to ever be adopted by Python (I hope!), it will
    remain a useful exercise, unlike othe “bugs” which get fixed once and for
    all

Want It? (Download and Install)

Are you sure you can handle this level of awesome? Okay! Download and install:

http://bitbucket.org/gregglind/python-whython3k/src/

## Get the source!
$ hg clone https://gregglind@bitbucket.org/gregglind/python-whython3k/
    # or if you haven't jumped on the `Mercurial <http://mercurial.selenic.com/wiki/Tutorial>`_  bandwagon
    # then:  wget http://bitbucket.org/gregglind/python-whython3k/get/79a2c77fe3e1.zip and unzip it!
$ cd python-whython3k
$ configure  # go make a pot of tea
$ make       # go watch an episode of the `IT Crowd <http://www.netflix.com/WiMovie/The_IT_Crowd_Series_1/70113774>`_
$ ./whython  # beautiful failure begins

Limitations

  • only simple_stmt are really usable in this way. That means that
    blocks (functions, if, else, etc.) can’t be nested inside a braced block.

Thanks to

  • The Authors of PEP 306
  • GVR, Martin v. Loewis (my umlaut is misbehaving!), Georg Brandl, Greg Ewing, Jeremy Hylton and others on the
    Python-Dev mailing list
  • Fred Drake, for responding to my crazy and incoherent email
  • gutworth, merwok, __ap__ and others in #python-dev

References

[Aho86] Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman.
Compilers: Principles, Techniques, and Tools,
http://www.amazon.com/exec/obidos/tg/detail/-/0201100886/104-0162389-6419108

Follow

Get every new post delivered to your Inbox.