News for hackers. Stuff that matters.
Re:Making Wrong Code Look Wrong by ajanuary on Monday August 22, 2011 @02:13PM (#2913420)
I'm sure I'm just missing something, but I'm struggling to come up with a reasonable case where you couldn't just have a and b be different types and provide an operator for typeof a - typeof b but not typeof b - typeof a (or vice-versa).

Of course, that would upset Joel on account of not knowing what - did without knowing the types.

Re:Making Wrong Code Look Wrong by masklinn on Monday August 22, 2011 @02:28PM (#2913479)
Depends what you mean by "reasonable" I'm guessing. Manually encoding a semantic analysis would have a very high overhead, and you might be able to do it via dependent types instead (not sure though, they tend to hurt my brain when I try to actually understand them), but I don't think they're considered practical (yet).
Re:Making Wrong Code Look Wrong by vilya on Monday August 22, 2011 @11:02PM (#2915157)
Just because you can, doesn't mean you should. :-)

Forcing a and b to be different types could cause a different problem - maybe a worse one, depending on how many subtractions your code requires.

Re:Making Wrong Code Look Wrong by JadeNB on Tuesday August 23, 2011 @11:33PM (#2919338)
It's maybe not very realistic, but you'd have trouble with this approach if you were trying to code the distance function `(a, b) \mapsto |a - b|` in a language that didn't have an absolute value.