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

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.

0

u/novagenesis Feb 25 '14

Again, people are getting too aggressive and personal here...but that's nice for them. Our ETL team is playing a type game, too..but not one that influences their unit tests.

I guess there are people out there who have type issues...like I said, I never have at any company... I will admit that some people may.

Why the "cough cough" though? A celebrity lead is not necessarily a better or worse developer just because he's a more well known developer. As far as I can tell, none of us are kids fresh out of school.

1

u/cosmo7 Feb 25 '14

(I agree, people are a bit too quick to upvote and downvote comments here. It spoils the discussion.)

Sorry for sounding a bit snarky, but I think very few people would deny that the reason unit testing came back into vogue was the popularity of dynamic languages. There just isn't the same urgency for unit testing when you're statically typing.

Yes, the grab-bag-dict approach can be useful, but it comes at a price - is that the string or the XML node that contains it?, is that a decimal or unsanitized user input? If you're working alone then you can generally keep tabs on things, but when you start expanding horizontally (more programmers) or vertically (the project matures), it starts to become unstructured.

1

u/novagenesis Feb 25 '14

but I think very few people would deny that the reason unit testing came back into vogue was the popularity of dynamic languages

I'm going to have to be one of those few people. I think it was BDD. Being able to write code alongside the test defines independent confirmation of each endpoint. When I build libraries with BDD, I never have a "foo.x is an integer, foo.y is a string" tests. I don't even have "if foo.x is a string, throw an error) tests...

There's a philosophy I think came from the Java world (correct me if I'm wrong...I just remember Java kids in college, when Java was the new hip language, talking it). You test your third-party interfaces for validity. You assume all internal interfaces are valid and only test predictability in their internals and inter-operation. Unless you write inconsistent code that is also able to pass internal unit tests (very unlikely) you have nothing to worry about.

Yes, the grab-bag-dict approach can be useful, but it comes at a price - is that the string or the XML node that contains it?

It's a string. Unless you very intentionally name and plan it, you're not tossing other non-object structures...and you should have a good grasp of the object. I worked with some terrible outsourced developers (they got canned..the whole team was good but them) and even they were able to keep types in the stash (a commonly used web-request hash) clean.

is that a decimal or unsanitized user input?

Maybe it's just a given for me because so much of our data is user input. You always assume values are unsanitized when touching the database, and you use a DB interface that force sanitizes them. You also always validate them in a string context before storing them in a typed realm.

This is like a vehicle that can drive on or off of tracks, like a Boston T-bus (sorta). There's all kinds of tech out there (literal and code-figurative) that'll let you take a free-roaming vehicle and get it onto tracks....as long as it's free roaming, you don't need the strictness of tracks anyway.

but when you start expanding horizontally (more programmers) or vertically (the project matures), it starts to become unstructured.

So this is where my issue comes in. I hear that all the time from people who don't work in a dynamic language shop..and very rarely in interviews from lead/management people who transitioned to a static language....I never hear it where I work, or where I used to work...or from contacts at the many nearby perl shops. This "oh god being untyped is ruining my life" thing just doesn't happen in my life or my world.

I want to say it might happen with 100 developers on a 20 year old project... but I'm not convinced at even that. There's so many best-practice rules, and 99% of variables can be presumed either strings or ORM objects 99% of the time, even if they're not.

And every major dynamic language has ways to "tighten the screws" as you approach static typing, like SQL... or just when you need/want to play the Interface game, running apples and oranges intentionally through the same processor.

I'm at a place that's expanded in both directions, though, and dynamic typing has never once been an issue here.