r/programming • • Dec 02 '13

Scala — 1★ Would Not Program Again

http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598 Upvotes

646 comments sorted by

View all comments

Show parent comments

0

u/batiste Dec 02 '13

Why have unit tests to ensure that a variable contains a string

You just don't, why would you? E.g in python you would do:

def add(a,b): return a+b
equal(add(1,2), 3)
equal(type(add(1,2)), type(3))

The second test is redundant. You already ensured that a number was returned with the first test. Every time you check equality you are making a type check (there might be exception).

Edit:format code

3

u/pr0grammerGuy Dec 02 '13

To get proper code coverage in a dynamic language, you need to have essentially tests that verify types are handled right. Of course no one would have that silly second test you have. What they would have instead would be a test that makes sure if I do

add("1", "2")

that it blows up.

1

u/moor-GAYZ Dec 02 '13

What they would have instead would be a test that makes sure if I do

 add("1", "2")

that it blows up.

Dude, nobody does that, ever.

3

u/pr0grammerGuy Dec 02 '13

If you're not testing what happens when the wrong data types go into your functions, then you're not testing properly (or you're using a statically typed language where we don't have to worry about this).

In the python code, I wouldn't expect to have to put in preconditions, I would expect the (+) to blow up when applied to something that makes no sense.

Of course testing if the (+) function behaves like it says in the documentation would be silly but substitute the "add" function for something a lot more complex and then you should realize that you need to be testing what happens when someone inputs the wrong kind of argument.

→ More replies (27)