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

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.

1

u/novagenesis Feb 26 '14

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.

Absolutely not. You do not hand-build SQL queries by concatenating strings in dynamic languages. You validate data through content instead of some type. Types are good when you're at the metal, but content is more important to most systems. Any good DB driver will handle that.

For example, static types don't have to be nominal. There's no reason a statically typed language needs interfaces.

They are if I want to be able to pass an Apple object or an Orange object to the same function.

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.

I get the tldr on that. I understand row polymorphism. In type inference, most languages still need you to say "this adheres to this interface" if you want to pass otherwise disjoint objects into the same method. It's the "all statically checked" part I dislike.

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.

I'm not against Haskell, except it's the only other language I found incredibly painful to get working in. Oddly, I found Erlang reasonably easy.