[Edu-sig] Errors in Wikipedia entry for IronPython?

Dethe Elza delza at livingcode.org
Mon May 8 18:32:49 CEST 2006


On 5/6/06, kirby urner <kirby.urner at gmail.com> wrote:
> I have a problem with this example code:
>
> from BookService import BookDictionary
>
> booksWrittenByBookerPrizeWinners = []
> for book in BookDictionary.GetAllBooks:
>     if "Booker Prize" in book.Author.MajorAwards:
>         booksWrittenByBookerPrizeWinners.append(book.Title)
> booksWrittenByBookerPrizeWinners
>
> First, the variable names seem intentionally ugly, but I'm not going
> to worry about that.

There is a style of programming where you spell out what you're doing
in graphic detail, as opposed to just declaring var x,y,z; def
foo(x,y): return z style of minimalist programming.  Most Python code
is somewhere in between, but when using an external system (dotNet in
your example, PyObjC in my experience), it makes sense to have the
python code reflect the style of the main library/framework that
you're using (or wrap it out of sight altogether, the way PyGUI tries
to do).

  What really bugs me is
> BookDictionary.GetAllBooks without making it callable.  The prefixing
> verb Get would imply a function, and Python distinguishes itself from
> Ruby (per Martelli) by making a sharp distinction between a function
> *named* and a function *called*.

In Java, rather than properties, they have the JavaBeans naming
convention.  According to this convention, getters are named getFoo()
-> foo, and setters are named setFoo(foo) -> void.  In most of the
dotNet code I've seen, you can take Java (or SVG, or whatever system
they're imitating this month) and make it initCap (getFoo() becomes
GetFoo()). Since Jython treats the JavaBeans calling conventions as
properties, I assume IronPython is doing something similar.  Although
in that case, you should be able to just write AllBooks rather than
GetAllBooks (although both ways might work).

> Perhaps its just an unfortunate naming issue, i.e. GetAllBooks is
> really to be thought of as an iterable, not a function call.  Under
> the hood, there might be some property, i.e. if it has to consult a
> database (whatever BookService does).  But in that case, I'd really
> prefer a function with no arguments, a callable in other words.
>
> Anyway, as you can see, I'm unhappy with this code.
>
> Plus there's a clear typo in the next sentence:
>
> "In this case, assume that the .NET framework implements a class,
> BookDictionary, in a module called BookService, and publishes an
> interface into which IronPython scripts can be sent and exectuted."
>
> I've edited Wikipedia before, but hesitate to dive in on this one
> without more seasoning (comments?).

I think you should freely change the obvious typo, but not the code
unless you've tried to run it and found it does not actually work.  I
don't have IronPython, or any intention to install or run it, so take
anything I say about it with a large grain of salt.

--Dethe

>
> Kirby
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>


More information about the Edu-sig mailing list