3 ms·
People love to trot out examples like this while remaining totally silent about why they're trying to add/subtract numbers and strings in the first place or art
by cxr 4y ago
People love to trot out examples like this while remaining totally silent about why they're trying to add/subtract numbers and strings in the first place or articulate what they expected to happen when they did it.
On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" [...] I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
- kamranjon 4y agoOh I absolutely ran into this because I had a bug, I had forgot to parse the number into the correct format, but it still feels odd that the language behaves this way. Here is an example of what Ruby outputs: "4" + 4 : `+': no implicit conversion of Integer into String (TypeError) "44" - 4 : undefined method `-' for "40":String (NoMethodError) The funny thing being the implicit type conversion that javascript does. This is likely why typescript has become so popular. Are there other languages that have implicit type conversion for basic types like javascript?
- plugin-baby 4y agoJava?
- mekoka 4y agoWhy? Because type errors are a fact of life in programming. They're not evidence of programmers trying to be eccentric. What was expected? Regardless if static or dynamic, it should be strongly typed. Just throw the error. All languages that have tried to salvage the situation when the programmer's intent became ambiguous end up creating problems down the road.
- cxr 4y ago> type errors are a fact of life in programming ...and anyone who cares, therefore, uses a typechecker. What makes it such a weird criticism is that, in order for it to make sense, you have to satisfy all three of 1) being someone who is annoyed that the operators have these well-defined semantics for mixed types, 2) actually mixing types and doing so by accident rather than intentionally, but 3) nonetheless someone who refuses to use a typechecker. That's a special case of someone insistent on putting the wrong figures into the machine altogether... > Regardless if static or dynamic, it should be strongly typed. Just throw the error. Java and C# are two of the most popular and widely used strongly typed languages. They don't throw errors for this.