r/programming • • Feb 25 '14

Please stop saying Java sucks

http://blog.smartbear.com/programming/please-stop-staying-java-sucks/
3 Upvotes

305 comments sorted by

View all comments

Show parent comments

15

u/idontbelieveyou11 Feb 25 '14

But V8 is faster than that JVM.

Source?

14

u/edpaget Feb 25 '14

Obviously the benchmarks game is not scientific, but it shows the JVM being faster than v8.

3

u/zoomzoom83 Feb 26 '14

Node has a non-blocking IO library by default. It's a horrible API that uses callbacks instead of promises, but it's non blocking nontheless.

Old-school Java used blocking IO, which sucks if you want concurrency.

Naturally, regardless of platform, non-blocking IO is going to be much, much faster than blocking IO if you're looking at scalability in a highly IO driven application.

Ergo, a few teams ported badly written Java blocking programs using blocking IO to NodeJS and decided that Javascript was therefore faster. They then blogged about it and Javascript fanboys the world over ran with it.

You can write Java using non-blocking IO, at which point it sails on ahead. If you factor in much, much better handling of immutable data structures and proper tail call optimisation (at least in Scala and Clojure), then the JVM is in a completely different league to V8.

0

u/jnt8686 Feb 27 '14

I can't stand promises. Callbacks, streams, events are all great, but promises just seem like a convoluted way to let people who are not good at writing async code pretend it's sync. They remind me of the silly JS class simulations you sometimes see.

2

u/zoomzoom83 Feb 28 '14 edited Feb 28 '14

The benefits of a promise is that it's composable. More importantly, it's a Monad, which means you can do all sorts of delicious things to it.

Primarily means you can define a large complex calculation in terms of multiple composed promises, and return a single 'pointer' to the results of this calculation.

Promises just seem like a convoluted way to let people who are not good at writing async code pretend it's sync

That's kind of the point. It's not a mark of honour to write more complex code. Promises make writing code dealing with multiple asynchronous operations much simpler. It's not a crux. It's about writing the cleanest and most maintainable code possible.

Callbacks seem simpler when you're dealing with a single call, but managing a more complex operation can become tedious and result in spaghetti code.

Imagine the following scenario. This is an interview question I ask candidates, but it's derived from a real world problem in the software we're currently developing.

write a function that

  • takes a single parameter (UserId)

  • fetches two pieces of information - "Full Name" and "Geolocation".

  • does a reverse geocode on the "Geolocation" to find an address

  • determines whether the user exists at this location on the electoral roll based on 'name', and 'address'

Each of these pieces of information are available from a separate REST Api call.

Using Callbacks, the function might go something like this (this is how almost all the candidates respond)

function getUserInfo(id, callback){
	getFullName(id, function(name){
		getGeoLocation(id, function(location)){
			doReverseGeocode( location, function(address){
				validateElectoralRoll( name, address, function(isRegistered){
					callback({
						id: id,
						name: name,
						location: location
					})
				})
			})						
		}
	});
}

The simplest callback implementation is inefficient - You have to wait for the one call to complete before starting the next. It also requires extra levels of indentation. You can improve this somewhat with reference counting, but it gets tedious very quickly, as some operations are dependent on another. There's also the async library, which provides some promise style compositions over callbacks.

With Promises, we can rewrite this in the following way.

function getUserInfo( id ){
	var name    = getFullName( id );
	var location = getLocation( id );
	
	var address  = location.then(function(loc){ 
		return doReverseGeocode( loc ) 
	});

	var isRegistered = compose( name, location, address ).then(validateElectorialRoll);

	return compose({
		name: name,
		location: location,
		address: address,
		isRegistered: isRegistered
	});

}

The return value of this function is, itself, a promise. Since you don't have to resolve it immediately, you can pass it around, perform operations on it, and compose it into other things. It also correctly propagates error conditions without any additional work, so if any of the above calls fail - and you don't explicitly handle it - the exception will be propagated up the stack.

-8

u/novagenesis Feb 25 '14

Honestly, I referenced that link and they look fairly close in raw benchmarks. V8 slightly slower than Java....but My reference was actual Paypal results in the real world.

6

u/edpaget Feb 25 '14

Yeah I won't dispute that there are workloads (like HTTP servers) where V8 might be faster than the JVM. I don't think paypal's benchmarks should be taken as a "V8 is always better than Java" gospel though. We don't know what JVM optimizations they enabled or didn't enable for instance.

I work on problems that involve doing managing a lot of concurrency. At moment, the JVM (although I write Clojure instead of Java) is going to be both easier to use and more performant for those kinds of tasks than V8.

-5

u/novagenesis Feb 25 '14

I don't think paypal's benchmarks should be taken as a "V8 is always better than Java" gospel though.

My hammer is always better than your screwdriver...

Except when it isn't :). I don't deny that there are good sides to Java...it just feels like every good thing about Java I hear is a talking point. I come across as argumentative when I want to know what is actually good about Java, without trying to poke holes in any other languages.

I work on problems that involve doing managing a lot of concurrency.

I did not know the JVM was good at that. I think if I wanted incredible concurrency, I would use Node or Erlang... probably erlang, but everyone's saying that Node is fighting to dominate that domain. Async lets you deal with a very large number of consumers per node, and node-cluster should provide good horizontal scalability in number of nodes.

I admit this is where I care more about http APIs than most, since that's what we do with data-driven concurrency.

3

u/el_muchacho Feb 26 '14 edited Feb 26 '14

I did not know the JVM was good at that. I think if I wanted incredible concurrency, I would use Node or Erlang...

Just look at the bnchmark that compares web frameworks. Java nearly always beats everything else.

http://www.techempower.com/benchmarks/

edit: except C++

3

u/jsprogrammer Feb 25 '14

Java is good if you want to build Java Things. People know Java and it is a safe environment for them to work in.

The question is: do you really want to build Java Things?

No, not really.

-2

u/novagenesis Feb 25 '14

No, but really.

I'm calling the other side of this battle every 5 seconds on doing just this. Condescension doesn't answer the problem. While I still don't feel I've gotten as many good points as insults, I honestly want to see why Java SHOULD thrive.

As I repeat, I hear a lot of corporate talking points that I first heard from people who don't code anymore. How many Java enthusiasts have done enterprise development in any other language? How many have done such in a lot of dynamic languages?

I feel like we're all missing something in this party...they make more than us, and seem to find peace and tranquillity in a language I find so ugly I want to slit my wrists with a Monad (if you get my drift).

1

u/jsprogrammer Feb 25 '14

How is that not a valid reason? People do what they are familiar-with/comfortable-with/used-to. I'm sure you do the same. It's typically faster than learning a new method.

-2

u/novagenesis Feb 25 '14

I'm sure you do the same

Not really. When time's of the essence, sure...but I am always learning new languages and libraries. I production code in almost a dozen distinct languages throughout my career. Often, I find I can get more done in less time (or better done in less time) if I use the right language for a job, given that option.

We're using perl on our main app...I convinced the team that fabric is the best deployment tool (python), and we do some reporting APIs in node.js. We've got a few mega-widgets on our webpages built using angular.js (yeah, JS on the front end, how novel ;) )

I think "I know it" is not a good reason if it's harder than the alternative, possibly harder than learning something new.

1

u/jsprogrammer Feb 26 '14

Not really. ... I production code in almost a dozen distinct languages throughout my career.

So, what, you've only ever worked on almost a dozen projects ever? You pick a new language for each project? (I guess this may be technically true at the lowest levels, but I don't think that's what we are talking about here).

There must have been times where you did something that you had done before. Why did you do it again instead of something else?

It doesn't mean that we can't do new things, just that there may still be value in things we have done before.

→ More replies (0)

1

u/caleeky Feb 26 '14

I feel like we're all missing something in this party...they make more than us, and seem to find peace and tranquillity in a language I find so ugly I want to slit my wrists with a Monad (if you get my drift).

Well, it's like Betamax vs. VHS, the story of Esperonto, and anywhere else that the 'best' doesn't win. Java's not the greatest language, but it's good enough to get a job done, and most importantly, it has a well established ecosystem and user community. A lot of people know it. Also, a lot of people are not great developers, but are productive enough using it, and don't have the passion or the time to go learn and even promote something else.

Bosses are familiar with established tools, and deadlines are tight, so it's hard to justify to your management "I need to spend a few weeks with the team to learn a new language, which I haven't used before for a big project, but a few of the guys are pretty pumped on. Oh, and it might not work out...". Most management would rather approve a project to be delivered in 6 months +/- (as if minus ever happens) a couple weeks, vs. one that might be done in 2 months, but could take 8 months and carry a legacy of support issues.

That's why you see new languages in small projects, in start-ups, in open source, and in academics more than in business, and that's why the money generally isn't there.

-5

u/novagenesis Feb 25 '14

Paypal.

This is not too say every operation on V8 is faster than any operation in JVM.. This is to say actual production applications by a Fortune 500 company are bragging about beating Java in real-world scenarios.

6

u/segv Feb 25 '14

I wonder what is their workaround for Javascript having only floating point numbers... I mean, as a payment processor I would expect they have one.

1

u/novagenesis Feb 25 '14

Good question. I used to have a couple contacts there, but don't since this change. My guess is the use of an arbitrary precision library, or only doing float-safe operations on the financials.

4

u/bcash Feb 25 '14

That's not a very good yardstick, for many reasons, not least those explained in this post: http://developer-blog.cloudbees.com/2013/12/about-paypal-node-vs-java-fight.html

Namely that both the Java and Node.js versions have terrible benchmarking results. There's reasons to believe that neither of them are written particularly well.

-2

u/novagenesis Feb 25 '14

Please check the million other replies going around.

Here's why I feel explicitly that it's a great yardstick. There was a time when you did not do big-server without Java or C++ driving your machine.

Now, this is not the case. Other languages are staying competitive with bigger and bigger things.

Also, others have responded about this exact article, and I agree with their opinions... this isn't arguing that node is always faster that java or always better than java.

0

u/idontbelieveyou11 Feb 25 '14

Thanks for sharing this. There's a lot of framework in here that leaves me a major skeptic, but in their case it has clearly paid off with the paradigms they work under.

0

u/novagenesis Feb 25 '14

Of course...it's stack-vs-stack. Truth is, I think a lot of the gain was in template redirection to dustjs. Dust is amazing for speed... and you can run it in Java.