On Sunday, September 20, 2015 at 9:07:36 PM UTC, Jesse Johnson wrote: > > In a thread about printing UInt variables, Milan Bouchet-Valat said: > > The point is, in Julia using unsigned ints to store values that should > > always be positive is *not* recommended. > If that is true, then shouldn't the type be called Byte?
No, at least not "Byte", as that means 8-bit (to most). > It seems the > type has been misnamed if it was never intended to store unsigned > integers. > > Further, calling the type UInt is misleading to devs from C lang family > who frequently depend on compile-time type checking (ex. int vs. uint) > to help ensure no unexpected signs show up. I am not suggesting > type-checking is a perfect defense against sign errors, and thorough > runtime testing is definitely necessary. In my larger projects combining > type checking and runtime tests is almost a practical necessity and can > seriously cut down on time spent bug hunting sign errors. > > That said, I am guessing the suggested solution in Julia is to rely > solely on runtime sign checking? I can't see how I could make that > practical for my use cases, but it would be good to know if that is what > the Julia devs intend. > > I'm not sure I'm getting all your worries, but Int will be 32-bit unless when it's 64-bit on 64-bit platforms (and most Unsigned literals will be smaller than 32-bit?), so I'm not sure there will be many runtime errors. The signed Int and UInt are separate types and of course not all of either will fit in the other so it seems to be a runtime error is the best you can do. Most of the time as the integers are big there is not much point for unsigned versions or converting. You may want to look up the convert system however, that is interesting. Most of the time converting to Floats will also be ok, but not for all integers. I'm sure there is a way to cast between signed and unsigned (I think Reinterpret may be it) without runtime checking, but I'm not sure if would be adviced.. -- Palli.
