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
    ==============


    Lifting
    -------

    The example:
    "bib.books.title"
    [[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]



    Filtering
    ---------

    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]



    Apply-to-all
    ------------

    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
    1. Advertising

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
    Replies:
    0
    Views:
    997
    Eddy C
    May 27, 2006
  2. Sig
    Replies:
    3
    Views:
    413
    Evan Simpson
    Aug 12, 2003
  3. Christian Seberino
    Replies:
    30
    Views:
    913
  4. Nicolas Pernetty
    Replies:
    2
    Views:
    377
    Nicolas Pernetty
    Oct 30, 2005
  5. rtilley

    Is python very slow compared to C

    rtilley, Feb 11, 2006, in forum: Python
    Replies:
    51
    Views:
    1,042
Loading...

Share This Page