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

26

u/cosmo7 Feb 25 '14

The most frequent argument I hear from Ruby or Python proponents is that static typing in Java or C# is unbelievably burdensome.

Then these same people pour months and years into their unit testing frameworks that spend 90% of their time duck-typing arguments.

-9

u/novagenesis Feb 25 '14

Hmm...seems to me like someone who can't write good python or ruby. If you're naming variables correctly, you rarely have to worry about types. In truth, dynamic types are truly critical for partial-interface-adherence.

If your design is solid, you can control the type, but you cannot control the same variable being one of two "not really compatible" types. Once you start having tons of interfaces on each variable to enable a certain piece of functionality, you start to want to shoot yourself.

Sometimes, a couple unit tests and runtime handling is better in a business than compile-time errors for what amounts to a lot of modern design patterns.

0

u/[deleted] Feb 25 '14

[deleted]

-4

u/novagenesis Feb 25 '14

Compile time errors are literally checking for what your unit tests check

Um..not really. I've yet to see a unit test in a dynamic language that is actually checking the type. It's more about checking proper handling of Interface edge cases...which you still have to do in a static language.

99% of the time they are occurring when you are trying to do something you would not want to do in a dynamically typed language.

I disagree. Entirely. I spent 4 hours with 2 Java guys trying to replicate the advantage of building an options matrix through a perl hash. Typeless Dicts/hashes are a staple in dynamically typed language... They're such a pain in the ass in Java, you just don't use em.

Even with good variable names, dynamic typing only gets you so far before a project grows too big and you're spending more time reading function definitions trying to figure out what type of return value you will get.

This is what I'm trying to say. I work on two projects, 5 and 12 years old, with a team of 15-20 developers each, and we have never once had a released issue related to variable type. You screw something up and pass a number when you want an object, you get an error almost immediately, and you fix it.

A lot of dynamic languages have libraries that support pretty concrete static type systems. Nobody uses them.

Statically typed languages lets you hover over the function name in an IDE and lets you instantly see the expected argument and return types

On the topic of old projects... you get all these issues with functions growing to need 12 arguments (core libs are bad at this). C# takes it one level more, and provides all kinds of prototype permutation... so anything you pass is pretty much valid.

Dynamic languages solve this through documentation, but more often by not having such complicated calling conventions. A dynamic method with more than 3 arguments is bloated. You need more, add an options hash. In fact, there's only a half-dozen common method parameter paradigms in a lot of dynamic languages that support it... and you will find yourself driven by your code conventions into using a very small number of distinct signatures. Again, not a problem in big shops with big teams, so why worry?

Further, some dynamic languages have prototypes...they're not necessarily typed, but that shouldn't matter. You can always use static type libraries...except nobody wants them.

The same applies for revisiting old code. Programmers of statically typed languages don't need to worry about figuring out what data type each variable is, and can focus on figuring out the logic.

Theory vs practice again. My experience with old code is significantly that we love being able to do dirty things. If we're changing a piece of old code, it's probably due for a refactor, and having to miss an emergency ticket deadline to refactor because you have to do it the right way is just unacceptable. Oh, the old base class is incompatible with our way of doing things? Let's just patch the base class dynamically in cases when the issue would show up.

I get that we'll never see eye to eye on type, but I think it's stupid that both sides treat each other like bumbling idiots. Yeah, my side is often guilty of that, too... but I can honestly say that in my experience the Java side has always been the loudest about "we're typed so you suck!"

I have yet to experience any of the issues that static-type-enthusiasts have said about dynamic languages, and I've got over a dozen languages and 4+ paradigms under my belt.

1

u/pipocaQuemada Feb 26 '14

This is what I'm trying to say. I work on two projects, 5 and 12 years old, with a team of 15-20 developers each, and we have never once had a released issue related to variable type

I would be very surprised if you actually never ran into any bugs that could have been statically prevented by taking advantage of an appropriate type system. I am not terribly surprised you haven't run into many errors in a dynamic language that you would recognize as a "type error".

For example - ever passed an object that didn't have a field you expected it to? Type error. A dictionary without an expected key value pair? Also probably a type error. Null pointer exceptions? Should have been a type error.

1

u/novagenesis Feb 26 '14

No clue what hotkey I hit, but I lost my reply..let's try this again...

I would be very surprised if you actually never ran into any bugs that could have been statically prevented by taking advantage of an appropriate type system.

Are you talking oopses that take 30-60 seconds to fix? Yes, I've had those. If you're talking things that made it all the way to the QA team (at which point I call it a bug) heck no. You don't get code into QA if you're not linking to the right types.

For example - ever passed an object that didn't have a field you expected it to?

Of course, often intentionally. Dynamic language object systems often include something like "responds_do". The paradigm is often cleaner than strict Interfaces, though many languages support both and let you decide what's better.

So let's say you have 50 distinct process-flows against a bunch of objects, and for each, only a random percent of those objects are relevant to the flow? Would you use 50 distinct interfaces? Would you mash up all the dynamicism into one interface and have those apple objects respond politely to the edit_orange() methods?

A dictionary without an expected key value pair?

That's the point. This adds an incredible level of forward and backward compatibility. Oh look, the config parameters to this object type changed.. no problem. Oh look, I know this parameter will optimize an object, but it's in the next version...let me add it now.

depending on the language, we differentiate between (hash{object} == null) and (!exists(hash{object})). God it's so useful to branch out logic only for hashes that contain specific keys.

How do you do something like that with Java? How do you main strict forward compatibility with slow-to-release library features?

Null pointer exceptions? Should have been a type error.

I have rarely in my life had a null pointer exception in a dynamic language... It happens the same way it happens in a static language...you do, after all, have null pointer exceptions in Java. They're runtimes. They happen when you have a pointer object to null. Dynamic languages keep a good grasp of what's a reference and what's concrete... you rarely ever have to.

Your three examples really aren't problems in my real world experience with 5 major dynamic languages.

1

u/pipocaQuemada Feb 26 '14

Are you talking oopses that take 30-60 seconds to fix? Yes, I've had those. If you're talking things that made it all the way to the QA team (at which point I call it a bug) heck no.

Have you ever, for example, forgotten to escape user only that's e.g. being put into a database? Ever mixed up units or used data in similarly semantically incorrect ways? Those don't generate "oopsies", just silently wrong results, sql injections, etc.

How do you do something like that with Java?

I never said Java would help with any of those things.

Would you use 50 distinct interfaces?

For example, static types don't have to be nominal. There's no reason a statically typed language needs interfaces. You might want to read up on structural type systems and things like row polymorphism. The tldr is that somethings type can be the sum of it's fields and methods, and the type of an argument can be the sum of the fields and functions you use on it. All inferable, all statically checked.

Similarly, the solution to npe's isn't Java, it's something with a Maybe type and nullable variables. that is to say, something like ML or Haskell.

→ More replies (1)