|
From: Leif J. <le...@am...> - 2003-11-11 07:46:14
|
Today I converted CCMMOFGraphTraverser.java and CodeGenerator.java to
Python (all on a separate CVS branch, not to worry :). I came up with a
nifty script for doing a lot of the converting from Java to Python
(attached :) but still had some work to do. After these two files,
though, I discovered that it's not really worth the hassle !
Doing a line, word, and byte count on the respective files yields :
1118 5279 45933 CodeGenerator.java
963 3869 35390 CodeGenerator.py
231 1030 8538 CCMMOFGraphTraverserImpl.java
159 719 5890 CCMMOFGraphTraverserImpl.py
This doesn't reflect actual executed code size, because the bulk of both
files is contained in comments. But a mere 33 % decrease---not too
impressive. I think everyone knows I like Python better than Java, but
they turned out to be more equivalent than I thought.
That said, it would be nice if Java had a lambda keyword and map
function for sequences. For example, the following Java :
MInterfaceDef iface = (MInterfaceDef) current_node;
List bases = new ArrayList();
for (Iterator i = iface.getBases().iterator(); i.hasNext(); )
bases.add(getScopedInclude((MInterfaceDef) i.next()));
value = join("\n", bases);
is much more elegantly expressed in Python as :
value = '\n'.join(map(lambda b: getScopedInclude(b),
current_node.getBases()))
(That's a 60 % decrease in size.) Lambda keywords, ahhhh.
Oh well, pipe dreams. I'm working this week on the Python wrapper
generator for C++ components.
leif
--
Leif Morgan Johnson : http://ambient.2y.net/leif/
|