Dr. Axel Rauschmayer is a freelance software engineer, blogger and educator, located in Munich, Germany. Axel is a DZone MVB and is not an employee of DZone and has posted 246 posts at DZone. You can read more from them at their website. View Full User Profile

Does Java Make You Less Productive Than Dynamic Languages?

10.10.2010
| 11511 views |
  • submit to reddit

I still hear from many people that dynamic languages make them more productive, but my experience is exactly the opposite: I used to prefer Python to Java. But then along came Eclipse with its refactoring and code browsing and afterwards, I could not go back to simpler editors. Many of the advanced Eclipse features are possible precisely because Java is not dynamic. But in many ways, Python feels more polished than Java. The irony is that this has nothing to do with Python being dynamic. All of the following things could be easily added to Java.

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
Literals:
  • 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).
Slicing and dicing complex data structures:
  • 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).
Miscellaneous:
  • 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.
Exploring code: Having an interactive command line in Python helps. Eclipse has sheets, but I’ve always found them a bit awkward to use. I am thinking more along the lines of BeanShell, but it does not seem to be updated, any more. I would also love Eclipse to become even better at code browsing (ideas, more ideas).

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.

From http://2ality.blogspot.com/2010/10/does-java-make-you-less-productive-than.html

Published at DZone with permission of Axel Rauschmayer, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Mark Haniford replied on Sun, 2010/10/10 - 12:29pm

Some of the refactoring, code-completion,  and general semantic awareness that smart Java/C#  IDEs have are impossible in dynamically typed languages.    Sometimes it's easier to just whip up a little script in say Python or PHP because of the "batteries included" mentality or in the case of PHP the organic evolution of the language within the context of web development.

But I feel naked when working on large code bases in dynamically typed language.  I like having smart IDEs that remind me of stupid typos or other mistakes, or code completion, or the ability to have the IDE intelligently and methodically refactor code for me in a safe manner.   Yeah, I know all about TDD, but that's a compliment (or vice versa) to semantically-aware IDEs.

 The problem with Java is that it's just so verbose and doesn't have the syntactic sugar for literal collections.   But that has mostly nothing to do with Java being a statically-type language.

Otengi Miloskov replied on Sun, 2010/10/10 - 8:46pm

It depends sometimes Im more productive in Python and sometimes more in Java. When the codebase is big or huge Java, if the codebase is small Python. Strongly typed languages have their pro's and con's as the dynamic languages too.

Kirk Pepperdine replied on Mon, 2010/10/11 - 12:53am

The biggest gain in a language where the place holders (variables) are not typed is that you tend to need much less code to implement many algorthums. Consider this

add(y)

^ myValue + y.

This is an example of Smalltalk code that I can use and reuse this code to sum up longs, ints, floats and even concatinate strings. Without the typing information, the behavior is now dependent upon the reciever and how it implements the '+' method. That is the power of dynamic languages. All of the things you've mentioned are features and while they are important, they are not related to dynamic typing.

Axel Rauschmayer replied on Mon, 2010/10/11 - 3:19am

@Mark Haniford, @Otengi Miloskov: Yes, this matches my experience 100%.

Axel Rauschmayer replied on Mon, 2010/10/11 - 3:29am

@Kirk Pepperdine: Smalltalk is a very well designed language. I love its syntax. Optional argument types would be nice, though. I wonder how Newspeak is doing, these days.

IIRC, Bill Joy initially argued that Java should have code blocks (like Smalltalk). When the need came up to pass behavior around, inner classes were introduced to Java. Superficially, they seem more object-oriented, but I think code blocks (closures) would have been the cleaner solution.

Reid Atherton replied on Mon, 2010/10/11 - 7:36am

Agreed! My observation is that many people who use dynamic languages don't exploit the dynamism but just enjoy the niceties of quicker syntax that you mentioned. (Though this may not be as true of Ruby users, who appear to regularly harness open classes to achieve metaprogramming.)

 

Hate me for saying it, but an example for Java is C#. It's statically-typed (at least by default), but over the last few versions it's taken on quicker syntax in many different areas. And of course it now has closures.

Karl Peterbauer replied on Mon, 2010/10/11 - 9:48am

Writing own code and reading/understanding the code of others are quite different things. Understanding a large codebase is substantially easier when it's written an statically typed language with a decent IDE support.

In my case, following NetBeans functions are extremely valuable tools when I have to get an overview of several thousand lines of code: "Find Usages", "Go to Source", "Go to Declaration", "Go to Implementation". 

When it comes to refactoring, dynamic languages loose even more ground by design.

Nick Brown replied on Mon, 2010/10/11 - 10:51pm

Dynamic language != Dynamically typed language. When people say Python being a dynamic language makes it more productive, they are not just saying they don't have to type "int" or "String" all over the place.

Kirk Pepperdine replied on Tue, 2010/10/12 - 3:52am in response to: Karl Peterbauer

@Karl, Sorry but I have to disagree. The most important aspect of programming is to name things for what they are. If you do so, typing information isn't interesting or even needed for understanding. @axel, It would have been nice to see code blocks as first class citizens but I'm also have a feeling that adding them would have slowed down adoption as it would have resulted in a language that was too complex. Java benefited hugely in that poeple were looking for managed run times (ie, no one really wanted to build large business systems in C+ 'cos it's simply too difficult) but felt that Smalltalk was just too strange, too different than what they'd been taught to expect in a language. And, Cobol needs armies of developers with large iron to get anywhere where as Smalltalk did demonstrate that you could get more done with less. Java cut a path through the middle of C++ and Smalltalk by making compromises that neither group liked. It solved the Cobol productivity problem. So, Java successfully filled a gap. And now that the masses have been moved towards the center, adding additional complexity not only seems natual, it seems necessary.

Axel Rauschmayer replied on Tue, 2010/10/12 - 4:22am

@Nick: Naming in this case is kind of tricky, because boundaries are not always clear-cut. I could also have said "scripting languages". I agree 100% with the Wikipedia definition for "dynamic language".

Carlos Hoces replied on Tue, 2010/10/12 - 5:48am

I must agree to @Karl in the sense reading typed code makes for a better understanding for what it does.

Map aMap = new HashMap();

Map<String,Integer> aMap = new HashMap<String,Integer>();

I certainly understand much better the second line than the first one. Despite the fact the greater safety it offers.

Being productive, in my opinion, is not just a matter of "quick writting code" to achieve a design goal as fast as possible, which is usually interpreted as: writting as less as possible. Code has to be reviewed, enhanced, maintained by different people along code life span. So productiveness involves all that life cycle, and not just the first implementation delivering some results. That's why code easy to read, easy to understand, and using safe technics is more productive, on the mid and long term, than cryptic, although faster to write, coding.

David Lee replied on Tue, 2010/10/12 - 8:45am

The answer to your question is yes. For someone equally talented, coding in Java is less productive than coding in Groovy. This is true for me and I code in Groovy using nothing but a text editor.

Nick Brown replied on Tue, 2010/10/12 - 9:44am

But again, the term "scripting language" (which I don't like since it implies the language is only good for writing short scripts) does not have anything to do with the type system (which is what limits refactoring abilities for dynamically <i>typed</i> languages like Python).  And advantages you cite such as closures and an interactive environment do come out as typical properties of a scripting (or dynamic) language.  In fact, the latter is arguably the defining characteristic of a scripting language.

It may well be that dynamic/scripting languages are also dynamically typed, but they are still two completely different concepts defining different aspects of the programming language.

Erwin Mueller replied on Wed, 2010/10/13 - 3:06am

Short answer: No

It makes me less productive to look every time in the documentation to know what type a parameter should be. In makes me less productive every time I refactor things to run the tests that I don't break anything which the compiler could tell me right away. It makes me less productive to not have auto completion and it makes me less productive to run the application/the tests again and again until I finally get the method that wasn't implemented.

My Java code is clean and short. I can use external libraries and I use external resources for strings. When I see a complicated method my first thought is how can I break the method in nice small methods that are easy to understand and not that I need a dynamic language which so much smart code that one week later I don't understand it anymore.

Would be great if Java had closures. But I didn't encounter any problem that I couldn't solve with clean Java code.

Karl Peterbauer replied on Wed, 2010/10/13 - 3:43am in response to: Kirk Pepperdine

@Kirk: That's a purely academic view. Names are indeed important, but even a good name is never enough. Just take something which is called "emailAddress" or "url". Is it a simple string or a powerful datastructure representing a parsed string? Where is this thing used elsewhere? Which parts of the code are affected if I have to change it?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.