Python compared with Xen (for XML)

Discussion in 'Python' started by Will Stuyvesant, Dec 3, 2004.

  1. Here is a comment on the paper "Programming with Circles,
    Triangles and Rectangles" by Erik Meijer, Wolfram Schulte
    and Gavin Bierman. Google will find it quickly if you try.

    In the paper they introduce Xen, an extension to C# for
    better XML support. They show how Lifting, Filtering and
    Apply-to-all can be done so much better in C# with Xen.

    How is Python, my favorite programming language, doing in
    this respect? Let's see:

    Python for XML


    The example:
    [[an expression for all titles of books in bib]]

    (stuff in double quotes "..." is suggested Xen code from the
    article by E.Meijer et al., stuff in double square brackets
    [[...]] is the intended meaning. Python code is shown after
    >>> , the prompt from the Python interactive interpreter.)

    We can do this "Lifting" in Python with list comprehension:
    >>> [b.title for b in bib.books]


    The example:
    "bib.books[it.year >= 1998]"
    [[An expression for the books from 1998 or later]]

    This can also be done with Python list comprehensions.
    >>> [b for b in bib.books if b.year >= 1998]


    The example:
    "bib.books.{print it}"
    [[print all books: execute a code block for every book
    in .books.]]

    I would do it like this in Python:

    for b in bib.books:
    print b

    looks much clearer to me than the .{...} stuff. Oh and
    maybe the new generator expressions can be used for this,
    but they are new to me and I can hardly imagine clearer
    syntax. Anyone?

    All that is needed for this to work in Python is that you
    collect XML attributes in object attributes; and that you
    give a name to the XML children of an XML element and put
    them as a list into an object attribute with that name. Go
    wild and even define new classes for it dynamically, or
    beforehand if you have the XML DTD or Schema. Not too hard
    a programming exercise; who is first?

    As for the other content of the article it is my opinion
    that they pay way too much attention to data-models and
    types, and then strangle themselves trying to fit one
    data-model onto another one, and a statically typed one too
    for that! (C#, Java, even Visual Basic is mentioned for
    laughing out loud). Better try to get the job done first.

    They did this work paid by microsoft.research. I think
    microsoft.research better pay some more attention to Python.
    Or are they? Are the "competitive edge" rumors true?
    Will Stuyvesant, Dec 3, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eddy C
    Eddy C
    May 27, 2006
  2. Sig
    Evan Simpson
    Aug 12, 2003
  3. Christian Seberino
  4. Nicolas Pernetty
    Nicolas Pernetty
    Oct 30, 2005
  5. rtilley

    Is python very slow compared to C

    rtilley, Feb 11, 2006, in forum: Python

Share This Page