The end to all language wars and the great unity API to come!

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat Jul 2 23:57:03 EDT 2011


The place where this "Unity API" idea of yours falls down
is that an API is only truly easy to use when it's designed
to closely match the characteristics of the language it's
being used from.

For example, Python has a very powerful feature that most
other languages don't have anything remotely like: very
flexible keyword arguments.

A truly Pythonic API will take advantage of them wherever
it makes sense. An extreme example is PyGUI, where you can
write things like

   win = Window(title = "Fred", width = 300, height = 100,
     position = (30, 50), movable = True, resizable = True)

In fact, almost *any* attribute of any PyGUI object can be
specified using keyword arguments in the constructor. In
your typical C or C++ based API, either you have a constructor
taking a zillion positional parameters that all have to be
in the right order, or you have to set all the attributes
individually afterwards:

   win = Window()
   win.title = "Fred"
   win.width = 300
   win.height = 100
   win.position = (30, 50)
   win.movable = True
   win.resizable = True

Either way you end up with an API that feels very awkward
when used from Python.

-- 
Greg



More information about the Python-list mailing list