Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What I find quite unfair is how everyone compares "lines-of-code" for a Java app vs PHP/Python/Ruby.

IMO there's a big difference: A Java IDE like Eclipse probably writes half of the lines of source code for me - the tedious bits that are simply structure/sugar. PHP/Python guys write every single one in vim/e-macs. Perhaps "unnecessary boiler-plate" Java code gets in the way, but yet my IDE hides most of that for me automatically. And most importantly, when I do want to edit that getter - it's right there in my source code for me already.

I believe IDEs and compilers should become more powerful, rather than the languages, because you often want to drop down a level of abstraction to improve things.

For the record I use java, c#, php, python, etc.




This attitude scares me.

If the programmer does not need to write the code, it has no business being in the source code. Nobody wants to find all their slightly-modified boilerplate and modify it because the boilerplate generator had a bug. Sane programmers will fix the bug in one place, upgrade the library, and be done with it.

The less code to maintain, the better. The less repeated code, the better. This is what many programmers strive for, and why they eschew "my IDE will write it" in favor of more powerful abstractions.

Relying on your IDE is like using a shopping cart to carry around a portable generator, tower CPU, and CRT monitor instead of carrying a laptop. It's pretty easy to push around that shopping cart, right, so why bother with a laptop? The laptop doesn't have a 21" screen, after all, so it seems like a total waste of money compared to the shopping-cart-and-50"-TV.


eschew "my IDE will write it" in favor of more powerful abstractions

But he specifically said that this breaks down when you need to pierce the abstraction and he's right. You can often accomplish the same thing by doing the "non-abstracted" code in a lower level language and linking to it, but that's not always convenient or safe.

I'm of two minds on this topic. I like the "smarts" of a good IDE that hides stuff that I don't care about. But at the same time, I'm afraid that if it breaks (bug in the IDE or library), I don't have the ability to find the broken part and fix it or work around the problem. This was exactly how I felt when I started playing with WCF.


If you have to pierce abstraction by stripping away the IDE, you've got an issue with the design of the language.

Take python: I don't have to write getters and setters, but if I need to tinker around "inside" one, I simply write a function and decorate it with @property. But that code is only present if I need to create an exception to the general case, rather than having everything, including the common cases, present in source and hidden by the IDE.

Edit: Check out Project Lombok (http://projectlombok.org/), which tries to address some of these issues for Java (including the exceptional case, rather than hiding the general case). We discussed it a two months ago at http://news.ycombinator.com/item?id=738958


Python is not even the best example here, in Common Lisp and Perl (and probably lots of other languages) provide even better abstractions. If you want to modify the behavior of one accessor, you can modify it with method modifiers. If you want to create a new class of accessor-generation behavior, you can write a new metaclass that works exactly the way you want. (And of course, you can write your own "defclass" macro that always uses your own metaclass, if you desire.)

In Perl, we can even compose meta-roles into metaclasses; meaning that even tiny changes can be made easily reusable.

This is generally preferable to editing code in an IDE.


You can do the __metaclass__ thing in Python too. We'll find you and tut at you if you do, but you can do it.


It scares me a little too, but it's not much different than relying on 'rails init'. It's all code generation...


One thing that I think is often missed in the discussion around LOC and features like closures is that, while sometimes denser code is terser, often it's more expressive. For example, the code:

List<String> userNames = new ArrayList<String>(); for(User user : users) { userNames.add(user.getName()); }

is not just more verbose but also reveals the programmers intentions less than something like:

var userNames = userList.map(\u -> u.Name)

Java programs often devolve into a lot of for loops, which all kind of look the same regardless of what you're doing, and you have to read pretty closely. It's nice to replace a bunch of loops with explicit methods like "map" or "find" or "reduce" or "each" or other things that explicitly declare the intent of the programmer.

I write a lot of Java, and we also have an in-house Java-like language built on the JVM (that we're working to open source), and we added closures to it in order to gain those sorts of benefits. Even though IDEA or Eclipse can write my for loops for me, it can't read them for me.

There's no technical reason why you can't have a statically-typed language with excellent tools that isn't unnecessarily verbose: all you really need to add are type inference, closures/first-class functions, and properties, and a little bit of metaprogrammability (instead of code generation) is also both feasible and helpful.


In theory, why can't it read the for-loop for you? Why not summarize the above as eg:

List<String> userNames = users[@name]

Just showing the line in a different colour could mean it's "summarized". Clicking on it could reveal the complete loop and allow you to modify it. But common idioms such as map/find/reduce/each can be summarized.


actually, Intellij IDEA v.9 does just that. see: http://www.jetbrains.com/idea/nextversion/ And it has been open-sourced...


Def agree that Java is less readable, and there will always be shorter ways of expressing things (such as a for-loop). But I do think an IDE does, and could do a lot more to help: hide the generated boiler-plate code from me, show me a visual map of the source structure so I can jump to places quickly, and perhaps even summarize certain code blocks for readability (eg why not summarize a standard MAP for-loop, so that it becomes editable if I click on the summary?)

There are many other things that an IDE could do beyond validating my code, function arguments, giving me hints, auto-completing variable names, code-blocks, etc. All those things make Java & C# much more productive than people think. The worst bit is actually dealing with libraries, whereas with Python/PHP much more stuff is built-in.


As someone who (fortunately) doesn't have to write a lot of Java any more, but does have to read and understand Java source code upon occasion I have to say that this is a totally bogus attitude - when I read Java code I seem to spend a great deal of time playing "hunt the code that actually does something".

I accept that things like Eclipse are essential to write Java but I still have to read vastly more code.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: