Live data from Hacker News

Ask HN: Why not Java?

news.ycombinator.com

51–60 of 112 posts

Re: Ask HN: Why not Java?

#51
There is a hate against Java, also against C#, C++, PHP (which I hate), C, and pretty much any other mainstream language.

Notice, though, that competent people have done great jobs using these languages. So you have some choices. Two of them are: wonder why people bash Java or go do something useful with it. I suggest you do the second.

The key to using programming languages is in trying to use the one which will help you the most, or get in your way the least. Sort of "the right tool for the job". Idk what jobs java is good at. If you found out that it's good for your project, then use it.

Take a look a this article: http://prog21.dadgum.com/143.html

Re: Ask HN: Why not Java?

#52
Java is a great platform to build on - and the sweet spot is definitely for server side applications like this.

You can safely ignore the people who bash Java - they are generally clueless. The Java language is perfectly fine: high performance, statically typed, OOP, relatively simple and maintainable. It may not offer the most concise code and it may not have all the "trendy" language syntax features but guess what - that actually doesn't matter much in the real world (i.e. outside the realm of language designers and fanboys). If saving a few characters of typing is your major concern when choosing a language, you have much bigger problems.

But the real strength in Java is not the language but rather the overall platform - the combination of the JVM (which is an amazing high performance feat of engineering), the library ecosystem (which is the best overall for any language), the tools (great IDEs, Maven, a host of other developer-focused tools), the fact that the OpenJDK itself and most of the libraries are open source and the portability (compiled JVM code is extremely portable, and importantly doesn't need a recompile unlike some other so-called "cross-platform" languages)

So overall you can't really go wrong with choosing Java for server side applications. Although I would also give Clojure or Scala a look - if you are after "powerful" languages then these two are pretty amazing and you still get all the benefits of being on the Java platform.

Re: Ask HN: Why not Java?

#53
post #32

Earlier quoted context omitted.

I noticed a lot of criticism of Java's verbosity in the comments and I'm a bit curious what people are referring to? I work primarily in Java, but also do quite a bit of Javascript and Perl, and I don't notice Java being especially verbose. Maybe internally I'm giving it a break because it isn't a scripting language? I'm honestly curious to see what you guys think.

The two areas that most frequently annoy me are processing collections and (lack of) first-class functions. Java: List firstNames = new ArrayList (); for(Person p : people) { firstNames.add(p.getFirstName()); } addCallback(new Runnable() { public void run() { doSomething(); } }); Python: first_names = [p.first_name for p in people] add_callback(do_something) Scala: val firstNames = people.map((p) => p.firstName); add…

This is, because you can't Java. How you will find out, where you use

   first_names = [p.first_name for p in people]
? More verbose, but right way in Java is like (you can do this better with enums and/or guava, it's just example):

    class PersonTransformer implements Transformer {
        public Object transform(Object o) {
            return ((Person)o).getFirstName();
        }
    }
and then:

    Collection firstNames = CollectionUtils.collect(people, new PersonTransformer());
You can reuse it and, more important, you can search for it. Same for second example.

Re: Ask HN: Why not Java?

#54
It's just that Java is very verbose, and actually I found it particularly horrible for data driven applications (by this I mean apps whose behavior is determined by data/config files, not "Big Data" - I have no experience with the latter). For complex data types you always need to create complex class hierarchies. In other languages you could just write

webInfo = {url: "bla.bla", title: "bla die blub", links: ["link1", "link2"]}

Notice that webInfo contains two different types, Strings and Arrays. In Java arrays or hashes you can not easily mix types - you'll end up just putting objects everywhere, then be forced to litter the code with type casts. Or you create the unwieldly class hierarchy. That is my prediction, anyway - I am too lazy to come up with a good example :-(

You can also not simply write something like the hash above. The nearest you can get is if you have created that class hierarchy with suitable constructors, you could instantiate that in one go. At least that is my memory - I have now avoided it for so long that I am not even sure how to instantiate an Array or a Hash with data on the fly anymore.

I think instantiating an array with data goes something like

links = new String[]{"bla", "blub"}, and there is nothing like that for Hashes - you are stuck with

info = new HashMap();//generics are particularly ugly and annoying

info.put("links", new String[]{"bla", "blub"});

info.put("title", "some stupid web site");

info.put("url", "undisclosed");

And so on - a far cry from the example above. (Note the Java syntax is probably wrong, created from memory - but it is something like that).

Even if you went through the mind numbing work of creating appropriate classes, you'd be stuck with

info = new WebInfo(title, url, new String[]{link1, link2,...});

And that is just for two different types, and notice that there is no way to see what the name of the parameters of the WebInfo constructor actually are from that snippet of code.

title: someTitle

is actually much more readable because you can instantly see that someTitle is supposed to be a title.

Also if you want to use NoSQL, I suspect converting java classes to JSON could be a pita, too.

Re: Ask HN: Why not Java?

#55
I personnally dont like Java because of API complexity and this is why ended up with python. I have implemented many crawlers by using Scrapy framework and I believe it speed up development. We have crawled millions of pages without any problem.

Python is very powerful in terms of string manipulation because it has very good language constructs (like slice syntax) which makes development easy. At the beginning it might be a little bit confusing but once you mastered it you really feel power.

Twisted like frameworks also makes good job at this point. It is well-designed, asynchronus and it suits well for multi-tier network applications.

Re: Ask HN: Why not Java?

#56
post #52

Java is a great platform to build on - and the sweet spot is definitely for server side applications like this. You can safely ignore the people who bash Java - they are generally clueless. The Java language is perfectly fine: high performance, statically typed, OOP, relatively simple and maintainable. It may not offer the most concise code and it may not have all the "trendy" language syntax features but guess what…

I don't think Java-the-language is "perfectly fine". It's extremely verbose, the type system is mediocre at best, it's actively hostile to functional programming (and lets not even consider anything else like logic programming!), the syntax is extremely inflexible.

Your tirade against "fanboys" is nothing but a straw man--the point of having more expressive, concise code is not "saving a few characters of typing" but making your program easier to write and easier to read (and, therefore, easier to maintain). Sure, you can get stuff done with Java, but you can generally get it done faster and better with other languages.

High-level features absolutely matter in the real world--they allow you to write code faster and give you more confidence that it is correct. Code written at a higher level is not only shorter but also more declarative and clearer. The idea that only "language designers and fanboys" care about having these features in their languages is patently absurd and rather arrogant.

To me, it seems Java is a compromise--it ignores decades of research and progress in programming language design in favor of catering to people who knew C++ and didn't want to learn something radically different. Thanks to being widely taught, it is now essentially a lowest common denominator: practically any programmer you meet will have at least learned the basics of Java at some point. But I think this is exactly the sort of compromise any good programmers should not take!

Now, the JVM is, admittedly, a good platform. It has some glaring weaknesses--poor support for functional programming, poor interoperation with native code, long start-up time and so on--but, on the whole, is very strong. Happily, you aren't bound to Java if you want to be on the JVM and you can use some of the great alternatives like Scala. But this does nothing to defend Java-the-language--having a good implementation does not make a language well-designed or particularly usable.

Re: Ask HN: Why not Java?

#57
post #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 c…

I agree, java is completelly ok for implementing a crawler. For example the well known mercator crawler was written in java and it's authors stated:

Although our use of Java as an implementation language was somewhat controversial when we be- gan the project, we have not regretted the choice. Java’s combination of features — including threads, garbage collection, objects, and exceptions — made our implementation easier and more elegant. More- over, when run under a high-quality Java runtime, Mercator’s performance compares well to other web crawlers for which performance numbers have been published.

source: [Mercator: A scalable, extensible web crawler (1999)](http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.151.5...)

Re: Ask HN: Why not Java?

#58

I've written two crawlers in Java and found it quite well-suited. I think most people on HN who hate Java are talking about creating websites, and for good reason. Back in the bad ol' days, people would use Java frameworks like Struts for web apps, and it was quite painful. For my latest project I'm using Play Framework for front-end Java, and it's quite delightful.

Play framework is definitely a good Java framework to use. In my current projects I am finding it very useful.

Re: Ask HN: Why not Java?

#59
post #51

There is a hate against Java, also against C#, C++, PHP (which I hate), C, and pretty much any other mainstream language. Notice, though, that competent people have done great jobs using these languages. So you have some choices. Two of them are: wonder why people bash Java or go do something useful with it. I suggest you do the second. The key to using programming languages is in trying to use the one which will hel…

Just because you can do something with a language does not mean you should. Sure, lots of people make stuff with poorer languages. Lots of people also never write tests, skimp on documentation and copy and paste half their code. It works for them! The best choice would be to think about the problems people have with Java and find a good solution for them (e.g. Scala).

People use all sorts of distinctly sub-optimal tools and technologies for various reasons unrelated to those technologies' merits. One of the biggest reasons is familiarity--many people do not like learning radically new things and so stick to what they know. Popularity does not imbue any sort of quality to programming languages any more than it does to anything else like music. There's a reason that trained musicians respect classical music--even if they're making pop--and there's a reason programming language people respect ML.

In short: just because many people manage to use Java does not mean it is in any sense optimal or even good.

Also, I think the oft-repeated "right tool for the right job" bromide about programming languages is deeply flawed. Programming languages overlap far more than most tools--they are all general-purpose programming languages, after all. The difference between a hammer and a screwdriver is far greater than even the difference between Java and Haskell. Choosing a programming language is more like choosing the best power drill--they overlap almost completely and can do the same jobs. It's quite plausible that some are almost always better than others, but that you could ultimately do the job with either. It will just be more difficult with one than the other.

Also, even if languages did differ significantly, there is no guarantee that any particular language has anything it's best at--it can be strictly worse than other languages for every conceivable use.

Finally, I think that surrendering to familiarity and choosing something you know over something you need to learn is rarely a good choice. Sure, if you have a hard deadline, it might be a reasonable compromise. But learning a language is essentially a constant expense where its affect on your productivity is linear to how much you program. Just because it might take more effort to get started with Scala does not mean you should immediately consign yourself to the drag on productivity that is Java.

You should be learning something new all the time, and programming languages are some of the most important things to learn in CS--they affect not only what you write but how you think. So strive to find the best one you can rather than settling for something that works--in this day and age, expecting your language to be somewhat usable is too low a bar to set.

Re: Ask HN: Why not Java?

#60
post #59
post #51

There is a hate against Java, also against C#, C++, PHP (which I hate), C, and pretty much any other mainstream language. Notice, though, that competent people have done great jobs using these languages. So you have some choices. Two of them are: wonder why people bash Java or go do something useful with it. I suggest you do the second. The key to using programming languages is in trying to use the one which will hel…

Just because you can do something with a language does not mean you should. Sure, lots of people make stuff with poorer languages. Lots of people also never write tests, skimp on documentation and copy and paste half their code. It works for them! The best choice would be to think about the problems people have with Java and find a good solution for them (e.g. Scala). People use all sorts of distinctly sub-optimal to…

> In short: just because many people manage to use Java does not mean it is in any sense optimal or even good.

Nobody is saying the contrary. I suggested him one of the many options he has (from which I mentioned 2), which is using java. And said that using java is better than going around looking for why people bash java. Which happens to be true.

Consider how he would choose a better language though.

It's surprising how cumbersome it may get to write a simple loop in a more "elaborate" language.

> Also, I think the oft-repeated "right tool for the right job" bromide about programming languages is deeply flawed. Programming languages overlap far more than most tools--they are all general-purpose programming languages, after all. The difference between a hammer and a screwdriver is far greater than even the difference between Java and Haskell. Choosing a programming language is more like choosing the best power drill--they overlap almost completely and can do the same jobs. It's quite plausible that some are almost always better than others, but that you could ultimately do the job with either. It will just be more difficult with one than the other.

There is more to choosing a language than "the language". Here are some reasons why he may wanna use java:

1) He has books about java, but not about anything else.

2) His co-workers use java.

3) He needs to work with the JVM.

4) He really wants to use java.

5) He has a bunch of minor reasons to use java.

6) Libraries, Libraries, Libraries.

7) Development tools.

8) Good implementations.

9) There is a standard for the language.

10) There is a huge community around the language.

11) He doesns't really have a choice. His boss wants him to use java.

12) He's in academia and most people in his institute uses java.

(there are more!)

The "right tool for the job" sure is true. And very much true. It is complicated to select it though. That's why I didn't try to tell him HOW to select that tool. I really think he'll be better off with java if he saw java is good enough (another point is that a "known good enough" is usually better than a "unknown perfect").

We choose "a language" but rarely because of "the language". As you said yourself, a lot of times, these languages are general purpose languages and overlap a lot.

Have you ever noticed that a lot of the languages used today are really tied up to their implementations/running systems? C and UNIX, Java and JVM, C# and CLR, Python and CPython, PHP, Ruby, Objective-C (this one is a really good example), JavaScript, etc. This was true in the past too, think of delphi, vb6 and windows, lisp and the lisp machines, fortran and cobol and the IBM systems.

A lot of what was "language design" in the past, is libraries and implementation design today. Choosing a language is more than looking at "the language", its syntax, semantics, idioms, patterns, etc.

Some other important stuff. Like building a GUI is important, communicating over a network, accessing files, dealing with the data base, doing graphics programming. You can either use, for example, c# and have lots of these from .Net CLR with little effort, or pick OCaml, for example, and have it, but having to do a lot of work that you'd not have to do in c#. Even if you port OCaml to run on the CLR, it's unlikely to be as much CLR friendly than C#.

But, also, there are "local" reasons to choosing a language. These are stuff you or I don't know because it's specific to him or his group of people.

> You should be learning something new all the time, and programming languages are some of the most important things to learn in CS--they affect not only what you write but how you think. So strive to find the best one you can rather than settling for something that works--in this day and age, expecting your language to be somewhat usable is too low a bar to set.

Learning new stuff is good advice, generally. But programming languages are one of the most irrelevant things in CS. In the long run, they are irrelevant.

"We" already teach/learn a lot of programming concepts and techniques without specific programming languages, but with concepts shared by a class of programming languages (as you even said it, lots of them overlap). Concepts and techniques that, in the past, were highly specific of particular programming languages.

Languages get obsolete. Those which remain do so usually because of practical matters (like C, or Java, or C++).

The idea, sometimes new, a programming language may bring is important though. The language itself is not. For example, closures are really catching on now, but it was invented much in the past, and first implemented in languages that people do not use much (I guess it was scheme, but I am not asserting it)

And, so I can end this reply...

I'm sorry for arrogance, but you should not lose the ability to separate interesting from the practical, which I got the impression you cannot do very well. Some things are both (I guess haskell is one of these), but it's not usually the case.

What some people (fortunately, it doesn't seem that it's most of them) don't understand is that lots of programming do not require the sort of elaborate constructs and idioms that, for example, scheme allows you to use. I once talked to a guy who did lots of "business" software. I mentioned scheme to him. Told him lots of cool stuff about recursion, clojures and macros, told him a little about lambda calculus; showing how you could do it in scheme. And he told me "It's cool, but it's also like people don't know what is useful anymore.". Well, that got me thinking back then.

You can argue all you want if he's right or not; if the software he writes is difficult or not, but it's not that he didn't see the advantage of those things. But turns out that most repetitions do not require and are not good with recursion (they just loop over a collection or a range of values; a for+iterators or numbers would usually do), most functions do not return other functions (not that you couldn't do it that way, but it's usually the case that your program is simpler if you don't), and minimalism is not really that much convenient in writing software for $$ (many people seem to reach this conclusion). Lots of applications are still single threaded, and runs in only one process. Immutability is a lot more interesting in theory than in practice for a large class of programs. Static typing still catches a lot of problems, and people usually do not bother that much about having to write down the types. Beautiful techniques for managing large programs are very interesting ... for large programs. It turns out that lots of programs are not that large. And the list goes on and on.

Post reply on HN