News for hackers. Stuff that matters.
Re:Warning: Implicit Backdoor by nayuki on Wednesday September 04, 2019 @02:47PM (#20880197)
> When you pass operands of different types, the language usually converts one of the operands to the other's type. (Sometimes it converts both operands to a different type instead.)

Indeed. The pathological example where both operands get converted to a different type is like this: Assume that ‹int› is 32 bits and ‹long› is 32 bits. Then ‹unsigned int› + ‹long› becomes ‹unsigned long›. This is because ‹long› has a higher rank than ‹int›, so the result must have the rank of long. But because ‹long› cannot hold all values of ‹unsigned int›, we must use ‹unsigned long›.

Re:Warning: Implicit Backdoor by ohazi on Wednesday September 04, 2019 @10:38PM (#20883401)
I've heard a lot about NULL being considered a multi-billion-dollar mistake, but not a lot about the wishy-washy integer types hierarchy.

The more explicit stdint types (e.g. uint32_t) are both safer and more portable. Modern languages like Rust seem to agree... (u8, i32, etc).

The argument I've always heard was that you want your program to use the sizes that the architecture can handle most efficiently. But actually, I don't. I'd rather my program run correctly, the way I intended, even if that means it runs a little slower on a sparc or powerpc.

The combinatoric explosion of size hierarchies is basically impossible for normal people to reason about or test for.

Re:Warning: Implicit Backdoor by Gibbon1 on Wednesday September 04, 2019 @10:57PM (#20883492)
Yeah things I would get rid of in c is 'int' and the wishy washy integer type non sense that goes with it. The whole thing was a big pain in the ass until pure 32 bit machines came along and everyone forgot. Now it's a pain in the ass again.

I'd also add range types ala Ada.

Re:Warning: Implicit Backdoor by BoiledCabbage on Thursday September 05, 2019 @07:35AM (#20885662)
Yet one more thing that LISP/Scheme got right: Number Towers. Avoid all of this craziness, and just works the way the user intends.

https://en.m.wikipedia.org/wiki/Numerical_tower

Re:Warning: Implicit Backdoor by noneeeed on Thursday September 05, 2019 @05:19AM (#20885116)
Range types were one of my favourite features of the Ada type system. Such a simple idea, but super effective, and really useful when doing static analysis. Being able to push constraints to the interface simplified a lot of things.
Re:Warning: Implicit Backdoor by account42 on Thursday September 05, 2019 @07:44AM (#20885707)
Something like that is what I am hoping we get with contracts when they make it into C++. Although the versions so far only add constraints to functions, having them on types as well sounds very useful.
Re:Warning: Implicit Backdoor by noneeeed on Friday September 06, 2019 @06:21AM (#20894431)
It's great. It allows you to push the responsibility for checking values are in type right out to the earliest point, reducing the need to sprinkle bounds checking code all over the place. If you are using static analysis like SPARK or one of the others, it then lets you do a load more of it automatically, the constraints it places on values makes it much easier to statically demonstrate runtime properties of the code before.
Re:Warning: Implicit Backdoor by comex on Wednesday September 04, 2019 @04:24PM (#20881044)
Yep. Also, if both operands have types smaller than int, they’ll both be converted to int as part of the “integer promotions” step. This is less likely to lead to surprising results since the conversion is value-preserving, but it’s inconsistent with the behavior of int-and-larger types.
Re:Warning: Implicit Backdoor by Dolores12 on Thursday September 05, 2019 @06:32AM (#20885372)
Explicit is better than implicit, viva Guido!