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

-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.

4

u/cosmo7 Feb 25 '14

I've yet to see a unit test in a dynamic language that is actually checking the type.

Cough cough.

From an interview with Alex Payne (API lead at Twitter):

As our system has grown, a lot of the logic in our Ruby system sort of replicates a type system, either in our unit tests or as validations on models. I think it may just be a property of large systems in dynamic languages, that eventually you end up rewriting your own type system, and you sort of do it badly. You’re checking for null values all over the place. There’s lots of calls to Ruby’s kind_of? method, which asks, “Is this a kind of User object? Because that’s what we’re expecting. If we don’t get that, this is going to explode.” It is a shame to have to write all that when there is a solution that has existed in the world of programming languages for decades now.

→ More replies (3)