|
|
|
|
|
by Jach
4067 days ago
|
|
For your example bug I think you're wrong that static types would have made the bug impossible. What you need is strong type checking and a lack of auto-conversion. For example, in Java, this compiles: int[] bodies = {1, 2, 3};
for (int body : bodies) {
String formatted_body = "<p>" + body + "</p>";
callMethodWithStrArg(formatted_body);
}
And if in this hypothetical case it was previously a `String[] bodies` and a `String body`, I bet a lot of programmers would use an auto-refactoring tool because "static types and auto-refactoring go together for being confident in changes like apples and pie" and I bet the error wouldn't have been noticed even at review time. God help you if you're using a static language without generics that has implicit type conversions. In Python, though, this raises an error: bodies = [1, 2, 3]
for body in bodies:
formatted_body = '<p>' + body + '</p>'
The error is: "TypeError: cannot concatenate 'str' and 'int' objects".Dynamically typed languages still have types. |
|
I had totally forgotten that Java does it too, despite having done `""+i` lots of times as a cheap and easy and evil way to convert numbers to strings.
...I am currently rewriting a big chunk of the primary data storage to use immutable data structures, because it makes implementing Undo easier. I am having to fight the urge to redo it all in Haskell.