Comments on Stephan Schmidt’s “Is Java Dead?” 21 September 2009
Posted by manniwood in Java.1 comment so far
Stephan Schmidt’s Is Java Dead? is a perceptive look at how Java is not dead, but how it is nonetheless not the only language one might want to start a new project in.
Five years ago, it would have been easy to pick a language to specialise in: Java, hands down.
But, with popular web sites being built in technologies like C#, Ruby, Python, and PHP, job postings are no longer Java only. Java still seems to dominate, but many other languages are nipping at its heels.
One of the reasons I got so deep into Python is that Google uses a lot of Python. With their work on unladen-swallow, and Python 3’s use of UTF-8 as the default character set, the future of Python seems to be one of better performance and better internationalisation (two things Java currently does quite well). Oh: and Guido Van Rossum works at Google, so I’d say that’s quite an endorsement of Python over at the search giant.
There’s been a lot of research into JVMs lately (LLVM, Parrot), but I think Stephen Schmidt is on to something when he says that whereas Java might become less popular, the JVM might remain so. The next language that gets accepted into the enterprise might be JVM-based, making in harder for non-JVM languages to gain traction. In fact, languages like Clojure, that run on the JVM and even call back into Java, may be the ones with the brightest future. (Schmidt would choose Scala for his next project.)
So this is a strike against Python, but conversely a plus for Jython, which seems to be in active development.
It’s definitely a good time to be interested in picking up a new language, though. As Schmidt says:
But just because Java is not dead doesn’t mean it has a future. Developers need to open their eyes and learn new languages. I’m really disappointed in interviews when candidates show no interest in programming beside Java.
It would be so much easier if there was a clear successor to Java, the way Java seemed to just clobber Perl/CGI for web programming. (Though I’m certain that history looks different to the PHP crowd, so a shout-out to all of you.)
This time, there is no clear successor. But, learning a new language (any language) is probably a good idea right about now. So even if my investment in Python doesn’t pay the dividends I’d hoped (and I really do like Python), and Python doesn’t get traction outside of Google, I’m still glad I learned it. That’s an investment in itself.
Does the Internet No Longer Operate on Internet Time? 27 August 2009
Posted by manniwood in Java, Programming.add a comment
As sectors of the economy get more established, it seems that progress slows down and becomes more incremental. I’ve been wondering lately if the Internet no longer runs on Internet Time (a popular phrase from the roaring 90s).
I have two reasons to believe that the Internet is slowing down:
1) IE6 is still around.
2) Java is still the top programming language for web sites (although perhaps I’m ignoring the popularity of C#)
IMPORTANT NOTE: First off, I want to point out that I am not equating Java with IE6’s badness. Whereas I think most developers would cheer if IE6 disappeared tomorrow, I don’t think anybody wants to drive a stake into the heart of Java. I promised myself I’d try to make nuance a feature of my blog, so let me put some nuance right here: I’m not gunning for Java the way I am for IE6.
I’ll address IE6 first. In the late 90s, when IE became more popular than Netscape, Netscape seemed to disappear within a few years. It didn’t take long for most sites to simply stop supporting Netscape.
But when you look at how small the browser population was back then, in retrospect it seems like it would have been easy to turn away from Netscape in a couple of years, like turning a small boat.
On the other hand, when you look at the popularity curve of IE, waiting for it to go away will be more like trying to turn a battleship. Happily, the mindshare of developers is fully focused on the newer browsers; fortunately, even Microsoft wants everybody to upgrade to IE8; fantastically, large sites are starting to post warnings about discontinuing support for IE6.
But when you look at the longevity of IE6, even if its popularity dropped off a cliff tomorrow, it’s had a much larger, longer run than Netscape ever had. It’s as though the Internet is slowing down as it gets larger.
Now let’s look at the continuing popularity of Java.
Why do I equate the continuing popularity of Java with a slowing Internet? Because I think that if the Internet moved as quickly as it did in the roaring 90s, the current crop of Java programmers would happily be using what they deemed to be Java’s worthy successor by now, the way a lot of C developers switched to C++ (perhaps after some grumbling) and the way a lot of C++ developers switched to Java (perhaps after some more grumbling).
When you look at a rough time line, C seems to have been ascendant for about a decade, and then C++ for another decade, and now there seems to be Java. Java’s already been going strong for a decade, but unlike C and C++, it’s very unclear at this point if Java is on a downward slope or not.
If we are to believe Bruce Tate’s book Beyond Java, published four years ago, we would think that Java would be on its way out by now. Tate did a good job describing Java’s pain points. All languages have them, and Java is no more exempt from this than C or C++ are. But four years on, we are definitely not beyond Java.
It seems sort of inevitable that the same way C++ tried to correct C’s shortcomings, and Java tried to correct C++’s shortcomings, that some Java-community-anointed successor language should be here trying to correct Java’s shortcomings. After all it’s been more than 10 years since Java took over (largely) from C++ (not to mention clobbering Perl/CGI in the web application realm).
I suppose a whole blog entry could be written on why Java has no clear successor. Both Ruby and Python do not follow the C/C++/Java syntax, and that’s probably a real no-no in trying to win over Java developers. The Java community itself seems to be incrementally improving Java rather than creating a new successor language the way C++ aspired to succeed C, and Java aspired to succeed C++.
But today’s blog post is not going to try to explore the many reasons, good or bad, for why the Internet seems to be slowing down. I’m just going to use IE and Java as two data points to observe that the Internet is, in fact, no longer running on Internet Time.
Will Python Make Me A Better Java Programmer? 21 August 2009
Posted by manniwood in Java, Programming, Python.add a comment
As I said in J2EE Still Rules the Roost, the Python jobs are few, and the Java jobs are many.
So I’ve been interviewing primarily for Java jobs lately.
But it strikes me that knowing Python is perhaps an advantage. For instance, employers generally want to know that you’re excited about learning new technologies, and that you have a proven track record of doing so. Well, if you’ve taught yourself a new language and migrated your latest project to that language, that’s pretty good proof, right?
Also, more generally, the world of technology is always moving forward. We all have to keep up, and we should all ideally be forward looking.
I happen to be particularly impatient for that future to arrive, so when left to my own devices, I tend to embrace newer technologies. This is why I’m still chomping at the bit to learn Lisp, or maybe even Arc: I think Paul Graham is on to something when he says that languages are converging towards the feature set offered by Lisp. (Even if not the syntax offered by Lisp. Apparently, Perl 6 is going to have Lisp-style macros—if it ever ships.)
More immediately, will my knowledge of Python help me or hinder me if I end up programming Java at my day job? I think it will only help. Any time you’ve got knowledge beyond what you are required to know to solve the immediate problem at hand, I think it can only be a good thing.
J2EE Still Rules the Roost 19 August 2009
Posted by manniwood in J2EE, Java, Programming.1 comment so far
Two blog posts in a row today!
This is another one about my on-going job search, and things I’ve been learning.
In Beating the Averages, Paul Graham talked about how using a high-level language like Lisp helped make ViaWeb a success. In one of his other essays, Great Hackers, he talks about how which language a business chooses to develop in determine the quality of programmers they can hire (on the assumption that great hackers are more willing to learn off-the-beaten-path languages).
And I must say, at the startup where I currently work, switching from J2EE to PythonDjango definitely made a difference with getting our product completed.
But the Python jobs are few, and the J2EE jobs are many.
Python and Ruby haven’t really broken through yet. Books like Bruce Tate’s Beyond Java (already four years old!) still remain hypothetical, describing a possible future that hasn’t arrived yet.
I’m still glad I know Python, and still glad we switched to it on my current project. Learning a new language gives you a new way of looking at the same problems. And hey: at least my knowing Python shows that I’m not a one-trick pony. When I say I like learning new things, my knowledge of Python supports that.
I still eagerly interview for Python positions when they come up.
But Python and Ruby, in terms of popularity, are still nibbling at firmly-entrenched Java. Python is a great language, and I hope it goes far, but Java is still where the market and the jobs are at.
SQL NULL is not Application Language NULL 14 July 2009
Posted by manniwood in Java, PostgreSQL, Programming, Python, SQL, SQL NULLs.3 comments
When I first started using Python, it irritated me that null was None. C uses NULL, Java and JavaScript use null; why did Python have to use None? And why did Lisp have to use nil? Can’t all languages just standardise on null? It seems so arbitrary and capricious.
I’ve had a change of heart: I actually think the word ‘null’ needs to go away: languages should specify exactly what they mean by null, the way Python means None when it says None.
Like most application languages, Python throws errors when you try to add None to an integer, or concatenate None with strings:
>>> 1 + None Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' >>> "foo " + None Traceback (most recent call last): File "", line 1, in TypeError: cannot concatenate 'str' and 'NoneType' objects
In Java, you get null pointer errors trying to do similar things with Integer objects and Strings. Maybe it would be nice if Java also called null None, seeing as that’s what null really means in Java too.
In the case of SQL, it would be nice if NULL was called UNKNOWN. (Unfortunately, UNKNOWN is already taken! When was the last time you used the UNKNOWN keyword in SQL? Me neither. But it’s there…)
SQL’s NULL is often (ab)used to indicate “none”, but that’s incorrect: really a SQL NULL means “I have no idea”.
Watch this to see what I mean.
I fire up a PostgreSQL client, and ask it to print “NULL” instead of whitespace whenever NULL is encountered in result sets:
mydb=# \pset null 'NULL' Null display is "NULL".
and now I try to add an integer and NULL, then try to concatenate NULL to a string:
mydb# select 1 + null as "RESULT"; RESULT -------- NULL (1 row) mydb# select 'foo ' || null as "RESULT"; RESULT -------- NULL (1 row)
No tracebacks or null pointer errors in SQL! Nope. You get results. Why? Because SQL NULL does not mean “None”, it means “I have no idea!”
Hence, the only logical answer to adding one and “I have no idea” is “I have no idea”, because we have no idea what to what we are adding the number one—so if we are forced to provide an answer, we must respond “I have no idea!” And I’ll say it again: in SQL, NULL means “I have no idea”, not “None”. (Given that SQL has the UNKNOWN keyword, you’d think that UNKNOWN would be the result to the above queries. For whatever reason, SQL returns NULL instead. On the plus side, this re-inforces the fact that even SQL considers NULL to be the equivalent of UNKONWN.)
Likewise for concatenating ‘foo ‘ and SQL NULL: The answer is not ‘foo ‘ as you might expect if you were concatenating ‘foo ‘ and nothing; the answer is SQL NULL, because we are concatenating ‘foo ‘ and “I have no idea”. And when we have no idea what we are concatenating ‘foo ‘ to, we cannot predict what the resulting string would be, so the only logical answer is “I have no idea!”
In a sense, you could argue that Java null and Python None also mean “I have no idea”, it’s just that, in those languages, when you try to add 1 to “I have no idea”, you get an error. The compiler is basically stopping and asking for a time out: “Just what are you asking me to do here? I can’t add one and ‘I have no idea’!” Wouldn’t it be nice if SQL did that? But it does not. SQL happily returns the result: “I have no idea what one plus ‘I have no idea’ equals.”
My next blog post will be an appreciation of why Joe Celko says to avoid nulls in SQL whenever you can, and why C. J. Date says nulls should not even be part of the relational data model. I want to keep on typing, but I want to leave this blog entry with only one major idea: that nulls in your code’s business logic layer are not the same as nulls in your RDBMS!
From J2EE to Django: Observations from Porting a Web App 8 July 2009
Posted by manniwood in Django, J2EE, Java.15 comments
I ported a database-backed web application from Java Servlets to Python/Django, and I’m so very happy that I did. I was nearing the end of work on a medium-sized web app when one of my programmers left for greener pastures. I decided that I could make up for the missing programmer by porting our J2EE app to Python, and then finish adding the final features to the Python port. The assumption was that Python would make me so much more productive that I’d finish faster even including the porting time.
It turns out I was right.
If you’ve taken to reading my blog at all, you’ll know that I love RDBMSs, and that my application designs use the RDBMs as the final arbiter of what the application’s data model is. So really, I wasn’t translating a huge amount of code for my port, because I could leave the database alone.
Of course, because I think the database is king, I opted out of using Django’s ORM on top of my carefully designed database. Instead, I ported iBATIS (which I was using in my J2EE version) to Pybatis, and used that for all of my database access needs.
I originally wanted to make Django’s templating system work with Pybatis (and maybe I still will some day), but I could not find an easy way to make Django’s templating system run well outside of Django, and I wanted Pybatis to be able to run in Python apps that were not neccesarily Django-based. So, I turned to the Jinja 2 templating engine, and liked it so much that I am now using it in both Pybatis and my Django app.
You may wonder what parts of Django this leaves behind, but, in my opinion, the parts of Django that I’m using are the parts that I had no desire to write. I love the way Django maps urls to functions, for instance.
I love the way Django renders templates to the browser. There’s no complicated forwarding from servlet to JSP as there is in Java-land; just a method call to the template engine, which you can hand whatever data structures you need for page rendering. It may sound like a small difference, but somehow, in practice, it’s a big difference. Like many things Java, Servlets and JSPs feel over-architected after using Django.
I also love using mod_wsgi and Apache with Django. It feels like a more natural fit than Apache with Tomcat. My production environment is Linux, so Apache is therefore process-based and not threaded. I prefer processes over threads as a general rule (I agree with Eric Raymond that threads are a performance hack; you can’t always avoid threads, but it’s nice when you can). So getting threaded Tomcat (or any other Servlet container) to talk to process-forked Apache always struck me as a bit of a mismatch.
With Django, there’s no mismatch: through mod_wsgi, each Apache process contains its own Python interpreter, and each Python interpreter contains a single copy of the web app. All kinds of good things come from this. For instance, my Python code does not have to be thread safe: each Apache process handles one request at a time, and each Apache process contains exactly one instance of the web app, so there’s no contention for resources. (Except on the database, but databases are designed to deal with that.)
With this setup, you don’t need connection pooling. Because Apache processes handle one request at a time, and because each process contains its own copy of the web app, each web app instance only needs to be configured with a single connection to the database. You just write your code to use The Connection, and the rest is taken care of for you by Apache’s pre-forking goodness. You just need to configure your database to handle as many open connections as your Apache setup will fork.
So not only does all this feel cleaner and simpler (though perhaps a tad more resource hungry—there are always tradeoffs), it’s also got horizontal scaling built in!
Well, mostly. There’s the problem of sessions. Apparently, Django can be configured to persist session data to shared memory, so that it doesn’t matter which Apache process responds to a user’s request, it has access to that user’s session. I decided to write my own session implementation that persists all session data in the database. (I don’t imagine this would work with large traffic volume, but for our product’s projected traffic volumes, this was fortunately an approach we could take.) That way, it wouldn’t matter if a user established a session on one Apache process and then returned to another Apache process on a different machine in our server farm: with sessions being stored in the database, they would be findable by any Apache process on any machine.
All in all, I’ve been very happy with the switch from J2EE to Django. Although there aren’t always Python equivalent to Java libraries I got used to using, I also found that porting to Python only the parts of Java libraries that I used took very little time.
The realities of the market are such that my next project may be a J2EE project: it’s still the most popular stack, so the opportunity to use Python is not always there. But if I’m in a position to choose, I’ll choose Python. If I’m in a position to offer a recommendation, I’ll recommend Python if I think the library support is there, and the project can benefit from that choice.