3 ms·
Java creators tried to avoid giving developers any sharp edges. Interactions between signed and unsigned integers can be surprising, so they disallowed unsigned
by toast0 1y ago
Java creators tried to avoid giving developers any sharp edges. Interactions between signed and unsigned integers can be surprising, so they disallowed unsigned integers.
Of course, not having access to unsigned quantities makes interaction with other programs difficult :(
- astrange 1y agoThe one that annoys me is that people think implicit type conversions are dangerous for some reason, so they also disallowed `char a = 10; short b = a;` without writing a cast even though this makes no sense.
- resonious 1y agoIt feels like "sharp edges" often means "I once had a horrible bug due to accidentally misusing this". But if you cut features based on that definition, you'd soon have an empty programming language.
- lukan 1y agoJava was apparently quite successful, though. So maybe they got the balance right for their goal?
- fooker 1y agoI'd like a 10pples please.
- pdw 1y agoThe signedness of `char` is implementation-defined, it is signed on x86 but unsigned on ARM. So assigning a plain char to a wider integer type is suspicious, did the programmer expect sign-extension or zero-extension?
- astrange 1y agoIt's not implementation-defined in Java because there aren't any unsigned types. Personally I think explicit typecasts are even more suspicious, because introducing explicit semantics is worse than implicit semantics if the explicit ones are wrong.
- Hendrikto 1y ago> Java creators tried to avoid giving developers any sharp edges. They failed.
- fhd2 1y agoWell, I'd argue they created a straight jacket. That prevents a number of self harm tactics. It also makes a lot of easy things pretty hard to do.