Re:Should I Use Signed or Unsigned Ints? (Part 2)
by chipsy on Tuesday September 01, 2015 @10:11PM
(#10157060)
It really shouldn't be this false dichotomy. We could have richer specifications for the bounds of numbers and the rules used to convert their formats. It's some kind of failure of imagination to not have that when arithmetic bugs traceable back to "implementation does not match representation" are so common.
[ Parent
| on HN ]
Re:Should I Use Signed or Unsigned Ints? (Part 2)
by amenghra on Wednesday September 02, 2015 @12:38AM
(#10157454)
Ada got this right. For example, you can do
type Day_Of_Month is range 1 .. 31;
Re:Should I Use Signed or Unsigned Ints? (Part 2)
by jmnicolas on Wednesday September 02, 2015 @04:50AM
(#10158090)
What happens when you try to pass an invalid number ? An exception is thrown ?
Re:Should I Use Signed or Unsigned Ints? (Part 2)
by ygra on Wednesday September 02, 2015 @08:00AM
(#10158606)
Yes.
Re:Should I Use Signed or Unsigned Ints? (Part 2)
by kabdib on Sunday September 06, 2015 @10:26AM
(#10177734)
Making this efficient at the machine level gets hard. Hardware engineers really want to do 32 or 64 bit add/subtract/etc. datapaths, and handling range types in pipelines is hard, so it's up to software to do anything more complicated. Suddenly you're talking half a dozen instructions to do an ADD and programmers no longer want to use your language.
Efficiency is a convenient god when you're not willing to pay for being correct.