I hope this whole undertaking (more or less more than an hour wasted) helps at least getting rid of all this meaningless spam. Actually all mails coming from the form was almost always considered spam by me so it may have been easier to remove the form completely…
… not using XPath on XML but actually parsing the XPath itself. I did a quick googling and about one of the few libs there seem to be is SAXPath which is part of Jaxen, the Java XPath lib also bundled with XOM. While I do like XOM and try to use it whenever I need to use XML and Java I was actually looking for an XPath parser for Python. Of course I could use SAXPath with Jython, but I could not find a XPath parser for pure (C)Python.
A basic splitter simply splitting an Xpath in its steps would be sufficient for the beginning so I thought so write my own. This basic functionality should not be too hard but in the end not too useful either… A complete XPath parser would probably be very hard to do, even XPath 1.0 is not the easiest, XPath 2.0 support would even be better.
So I am still wondering though if there is a library (or a part of a library like 4Suite, libxml (or better lxml) which does not seem to do this on first sight…) which does XPath anyway and would emit the actual parsing of the XPath itself?
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.”
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.
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
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).