see whatever…

jump to menu

September 2, 2006

and switching programming languages

Filed under: Java,Javascript,Jython,PHP,Programming,Python — see @ 11:18 pm

In Reqiem for an operator Barry Warsaw farewells the <> operator which will be removed in Python 3000. I have no real opinion on the topic itself although I think <> and != are one of the few not TOOWTDI things in Python and so a reasonable decision to remove one. But the followoing question in the same blog entry got me thinking:
“How often do you type semicolons at the end of your Python statements? How often do you type colons at the end of your C conditionals? Yeah, me neither.”

Actually I do tend to forget colons in Python after programming a while in Javascript or PHP, and I do forget using braces in e.g. “if” clauses in Javascript or PHP or Java after programming in Python for a while. Actually I forget to use a lot of things in other languages that are not needed in Python like () {} ; etc. What really made me nervous was building a simple JSP form this week where I had to use Java and I almost got angry about all the stuff I had to type which would have not been necessary if it would have been a Python or even Jython form. All the declarating, casting, complicated and verbose looping etc was simply a nervekiller.

So I guess getting rid of <> in Python in favor of != makes language hopping at least a bit easier.

About the only thing I sometimes wish for Python would be the removal of mandatory colons at the end of if, for, class, def etc. I guess this would make parsing of Python sourcecode impossible or at least “indeterminable” (is that an english word?). But the colon is one of the few places where a special character makes the code not more readable but a bit convoluted. Not a big problem as the parser complains about missing colons (which I see frequently ;) .

BTW, this post is somehow related. It makes me like the language even more as there still seems to be space for a bit of fun.

August 4, 2006

Jython for Java programming

Filed under: Java,Jython,Programming — see @ 8:05 pm

I try to avoid Java programming as it normally is not really fun. But I had to do an adjustment to a JSP in which a XML was loaded as a file and parsed with basic DOM (no libraries available so just plain DOM ;) . The change was merely to load the XML from a URL instead. But I never did that before so I thought before trying this in the JSP itself I rather try it out with Jython first. I had installed Jython 2.2a1 as my new Laptop at work has JDK 1.5 installed (which seem to work better with 2.2 instead of 2.1). So i simple started the jythonconsole script (a bit scruffy but perfect for this simple task as it has auto-completion) and hacked away without even looking at the Java API docs. I know myself around the libs a bit so it took nothing more than about 5 minutes and the thing worked. Translating the stuff back to the JSP took a bit longer as all the declaration and exception catching stuff does get tedious. But all in all I reckon this was much easier and also quicker than working in the JSP itself.

I sometimes wonder why not more people at work use Jython. Most are full time Java programmers but I noticed even they tend to take quite some time with exploration of new (or simply unknown) features or libraries. This is very easy with Jython and also really fun too. But maybe a full time java programmer does not know how to have fun (ok, sorry ;)

April 12, 2006

Using the same data in Python and Jython

Filed under: Jython,Programming,Python,RelaxNG — see @ 9:26 pm

I had the problem of needing the same data for some related tasks for which I wrote

  1. a (C)Python script because I used the really great Lingfo – a library to read Excel data with Python together with this Cookbook recipe
  2. a Jython script as I used Jing to validate some XML files with a RelaxNG schema

I may have used other libs which may be available for only one taste of P/J-ython but found these the easiest to use and actually used them for other stuff before so did know how to use them. I could have used Pythons’s lxml but do not know if it validates with the RNC compact syntax or could have used something like Java’s POI to read the Excel but I actually try to minimize the Jython usage as I almost always prefer Python (being faster, 2.4. being much more convenient than Jython’s 2.1 implementation [2.2. still being alpha] etc etc)…

Aynway, so I read data from an Excel sheet with the Python script, read some XML files with the obtained data but needed the same data to do the validation of the XML files with Jython. The XML files themselves are on disk so no problem, the data on the other hand was a bit more complex list of dicts with quite a few information atoms.The solution turned out to be quite simple actually. As for the problem at hand I am able to start both scripts independently (or maybe writing a third shell script which calls both) I put a simple pickle in the Python script and read the same data with pickle in Jython.

Maybe a bit too trivial to actually blog about at all but as I never needed anything like the pickle (shelve, marshall etc) modules and never really saw a use case for them it was actually quite enlightening. I was wondering for some time now how to best integrate Python and Jythons tasks into the same app and this seems like a possibility at least for some cases. And I tried out another module of the very nice and comprehensive stdlib. (Which I missed by the way while doing some other work in PHP ;)

January 11, 2006

jylluminate

Filed under: Java,Jython,Programming — see @ 12:12 am

found this presentation on Jython which mentions jylluminate, a thing I was looking for for a long time now. Quite often I try some java library to test and check how it works or how to do something with it in Jython, so much more convinient than actually using Java itself.

BTW, a colleaque insists Eclipse does all he wants so he will even be quicker (regarding typing) with it compared to my Jython but of course less typing alone is not everything Jython makes a better Java or even bearable…
Even he admitted conversion of arrays to lists and back with all the casting and even for a java programmer unusual syntax is at best awkward.

I guess quite a few programmers in the java world give up on certain libraries and work a way around the original problem as I just experienced with a simple problem in DOM4J which took only a few lines in Jython (or even better the jyconsole (forgot the link…)) which is really great to work with.
Maybe just my experience but I saw it a few times and wonder if that might be a general thing.

Actually now after using Python and its really good docs make the Javadocs of e.g. the JSEE look a bit shabby. Javadoc and of course the whole standard library is just huge with loads of classes. Python on the other hand almost always seems to have same functionality but with a much simpler API. Now I jump from x to y I know but that’s almost anagolous to DOM4J’s huge API compared to XOM‘s tiny, easy and well thought through API (which is expected from Elliotte Rusty Harold of course). So a nice API in Java is possible but does not seem as ubiquitous as in Python (which of course has bad examples too).

Powered by WordPress