Live data from Hacker News

Ask HN: Why not Java?

news.ycombinator.com

1–10 of 112 posts

Ask HN: Why not Java?

#1
I am building a web crawler to access data to be processed. All the code is fairly high level, so I am drawn to Python, but there are certain bits of it that require data manipulation that is much easier in a C-like language (arrays are a big part of it).

Java seems to fit this role very well. It is statically typed, object-oriented, and doesn't delve into memory. However, it seems to get a lot of hate (or, at least, dismissal) from many programming communities, so I am asking, why not Java? Why is it so horrible as a systems language above C? Is there any other language that fits this role in a better way?

I am in particular asking this because I have been banging my head against the Python syntax for awhile, but I am trying to expand what languages I can program in.

Re: Ask HN: Why not Java?

#2
You can always do the speed-critical parts in C and link that from your Python code. Or, if your analysis is something already done, use a library already written in C (such as NumPy).

Another approach could be Jython (or any other JVM language closer to the desired level of abstraction) and Java.

I don't have much love for Java the language. It's not much easier to program than with C, isn't faster and is very verbose. Still, what you are doing looks like a good match for it. And all the respect I don't have for the language, I have for the JVM.

I wouldn't use if for web app development as there are much more productive options around.

Re: Ask HN: Why not Java?

#3
It's perfectly fine to use Java for this kind of software.

The hate against Java comes from using Java for application development: this is largely due to the kinds of applications that are typically written in Java (line of business software) and (this is the most important reason) accidental complexity and low quality of APIs like Spring or J2EE.

Recipe for programming happyness is to use the right tool for the job:

* Python (or Ruby) for web application development, development tools, and "devops" scripting.

* C (or C++) for pieces that need deterministic performance[1], provide a "native" feeling user interface, or require control over memory layout.

Note: performance and efficiency are relative to what your throughput and latency requirements are. Google's crawlers and indexers will remain in C++ for the foreseeable future, but (for example) crawlers for an intranet can get away with being in Java (or Python for that matter).

* Java (or Scala, Haskell, OCaml, Go, Erlang, or one of the many Lisps) for "userland" systems programming. If the majority of the system fits under the last bullet point, use C++.

* Avoid JNI or Swig if you can. Use JSON + REST for cross-language RPC. If you need performance guarantees of a tight binary protocol use Thrift or Protocol Buffers. If you have to use JNI, consider using JNA first.

* No matter what language you use, stick to high quality libraries and tools. For Java, you'll absolutely want to use guava, Guice, and either Netty (or NIO.2 if you are using Java 7) or Jetty + Jersey + Jackson (for REST APIs).

Pick up either emacs and cscope, netbeans, Eclipse, or IntelliJ for navigating a large Java codebase.

All Java build tools suck. Maven sucks less and is the de-facto standard in the open source community. Twitter's "pants" is also worth looking at.

* Don't touch Spring with a 60-foot pole: in the mildest terms it's unequivocal and absolute garbage. Ditto for any other buzzword you may see in a job listing for an "enterprise" Java development job (with 20 years of experience required, naturally).

[1] Java performance can be quite high, but a JIT-ted and garbage collected runtime implies a lack of determinism.

Re: Ask HN: Why not Java?

#4
Nothing's wrong with Java. Commercial and research-quality crawlers of tens of billions of web resources have been written in Java for over a decade. Its threading/concurrency support and extensive well-optimized libraries make it easier for you to make your code fast over large datasets... if you're good at Java. (If you're not, there are plenty of ways to sabotage yourself.)

But, Java's a bit verbose, has gaps in concise support for higher-level constructs, and sometimes the static typing gets in the way. So if you don't find those parts helpful -- some do -- and think your performance targets can be met with other later optimizations/design-choices/selective-reimplementations, stick with whatever more concise language you're good at.

Or, use any of the more concise languages available on the JVM allowing intermixing of the occasional Java facility, like Jython, JRuby, Groovy, Javascript, Scala, Clojure, and others.

(If efficiently handling massive numbers of concurrent net/IO streams is a priority, the recent JVM-based project vert.x may be of interest. I haven't used it for anything but toy tests, but it seems to combine some of the best-practices for maximum JVM IO throughput with a somewhat higher-level-language-agnostic top layer well-suited for servers/proxies/crawlers.)

Re: Ask HN: Why not Java?

#5
post #3

It's perfectly fine to use Java for this kind of software. The hate against Java comes from using Java for application development: this is largely due to the kinds of applications that are typically written in Java (line of business software) and (this is the most important reason) accidental complexity and low quality of APIs like Spring or J2EE. Recipe for programming happyness is to use the right tool for the job…

I wish HN had the ability to pin posts. This is great. Absolutely what I was going to write, so naturally I think it is brilliant ;)

The right tool for the job. Java has it's place and it just where strlen said it should be.

Re: Ask HN: Why not Java?

#6
Why is it so horrible as a systems language above C?

It's not "horrible", it just has many slight-to-moderate deficiencies and annoyances that make development more work than it should be.

Is there any other language that fits this role in a better way?

Scala is strictly superior when used as a "better Java". (If you go deep into its functional capabilities you get a different set of tradeoffs). C# is better as a language, but then you're tied to .NET.

Really we'd need to know more details of what you're doing and why you believe Python may not work. Are you concerned about performance, or do you need to do things that Python doesn't have convenient APIs for?

Re: Ask HN: Why not Java?

#7
Nothing wrong with using Java and there is something to be said for using the language you are most productive in. But if you are thinking of building a web crawler in Java, I would recommend taking a look at the Heritrix project: https://webarchive.jira.com/wiki/display/Heritrix/Heritrix It's robust, open source and easily extensible. Might be easier to write a custom module for it than to roll your own web crawler.

Re: Ask HN: Why not Java?

#8
post #3

It's perfectly fine to use Java for this kind of software. The hate against Java comes from using Java for application development: this is largely due to the kinds of applications that are typically written in Java (line of business software) and (this is the most important reason) accidental complexity and low quality of APIs like Spring or J2EE. Recipe for programming happyness is to use the right tool for the job…

What does "userland" mean?

Re: Ask HN: Why not Java?

#10
It's a lousy language (IMO) with some excellent libraries and very fast compilers. If you're comfortable with the limitations of the language, and you're having trouble with Python, it's worth a shot, I guess.
Post reply on HN