Standard library. The good news is that Java has libraries for almost anything you can imagine. The bad news is that dynamic languages tend to come with much more useful stuff built in:
- URL-decoding
- JSON encoding/decoding
- UU-encoding
- Joining strings
- Command line argument parsing
- CSV file parsing
- Complete HTTP client implementation (multipart POST, cookies, ...)
- Iterators: for loops over iterators, combinations (filter, append, etc.), conversion to collections
- Collection literals: Java 8 will have collection literals, so we will have to wait a while. In the meantime, Arrays.asList() is good enough for lists and a chainable put() (return type = Map) would be good enough for maps.
- Triple-quoted strings: If a string is triple-quoted in Python, it can contain multiple lines of text and single quotes.
- Raw strings: In Python, prefixing a string quote with an 'r' means it is raw and slashes are interpreted as is, and not used for escaping. This is very useful for text that contains backslashes (regular expressions, LaTeX).
- List comprehension: great in Python, easily added to Java, once it has closures.
- Accessing the n-th last element (arrays, strings, lists, ...): In Python, the index -n can be used for this purpose. In Java, you have to resort to mylist.get(mylist.size()-n).
- str() and ref(): Python has two kinds of toString() methods. str() returns a human readable representation, while ref() returns something that can be parsed (i.e. this method serializes to Python source code).
- Keyword arguments, optional arguments: useful, but might be too cumbersome to add to Java.
Most of the other Java warts, I can live with. That Java will have closures sometimes in the future is great, because currently it is difficult to encapsulate a way of iteration, where the operation that is applied to each element can be configured.
Related posts:
- Update 2010-10-25: BiJava: Backwards-incompatible Java
- Update 2010-11-13: Filling the holes of the Java standard library
2 comments:
You should try Scala. It has features similar to dynamic languages, yet it is statically typed, you can use many of your favorite Java libraries with Scala, and even a lot of Java tools and deployment apply (use Maven to build, deploy on Jetty or Tomcat, etc.). Another option is Groovy, but I prefer the speed of the statically typed languages and Scala has a lot of clever ideas. But both offer closures for Java.
I agree with 'aw': If you're looking for productivity, Scala is definitely worth a look. Oracle are looking at trimming the ugly corners of Java over the next two releases, but it seems they are really just moving it more towards what Scala already is: static, terse and functional (in both senses of the word). The toolset that makes your Java development so easy isn't quite there yet, but there's decent tools that are growing every day and, being a static language, they have the potential to become as powerful as the current Java tools given enough time.
Post a Comment