News for hackers. Stuff that matters.
Re:Almost Always Unsigned by virtualritz on Sunday January 02, 2022 @05:19AM (#29767459)
> Unsigned does not mean "not negative", it means "modular arithmetic".

It does mean "not negative" in languages with bounds checks. Like Rust.

Re:Almost Always Unsigned by whattheactualf3 on Sunday January 02, 2022 @07:22AM (#29768155)
Is it called "unsigned" though?

In Racket (and in mathematics) we call those natural numbers. The very notion of "unsigned" was invented by video game programmers at Bell Labs. In mathematics positive numbers are still signed (they just have a positive sign).

Re:Almost Always Unsigned by masklinn on Sunday January 02, 2022 @08:51AM (#29768685)
> Is it called "unsigned" though?

Yes: https://doc.rust-lang.org/std/primitive.usize.html

> The pointer-sized unsigned integer type.

> In Racket (and in mathematics) we call those natural numbers.

Naturals have no upper bound. Most languages don't have naturals, because they do have upper bounds. Languages which do provide naturals (limited by the host machine) usually don't bother with signing segregation, and give you mathematical integers (again limited by the host machine's capabilities).

Re:Almost Always Unsigned by gumby on Sunday January 02, 2022 @07:52AM (#29768338)
> The very notion of "unsigned" was invented by video game programmers at Bell Labs.

PL/I had (has) unsigned integers back in the 60s, picking up the idea from earlier languages. I believe the novel datatype in PL/I was the CHARACTER type; into the 80s I was still programming machines with variable length bytes.

In many ways PL/I heralded the current Ordovician stage of programming languages, with the enormous Cambrian flourishing of hardware-specific (and company-specific) languages slowly dying out. Interestingly the only surviving languages older than it, FORTRAN and LISP, are also machine-independent.

Re:Almost Always Unsigned by ncmncm on Sunday January 02, 2022 @05:54PM (#29774978)
Unsigned types are supported in machine language.

Any language that offers access to features of the machine will support unsigned numeric types.

No language supports natural numbers. The best you can get is bignums. A language that calls its numbers natural is just lying. (Likewise, integers, and reals.)

"int" is not a lie, it is a hint.

Re:Almost Always Unsigned by cies on Sunday January 02, 2022 @09:47AM (#29769098)
Though, in idiomatic Rust I did not find the use of unsigned as mentioned in the article, signed for indexes is the norm.
Re:Almost Always Unsigned by tialaramex on Sunday January 02, 2022 @11:00AM (#29769783)
> in idiomatic Rust I did not find the use of unsigned as mentioned in the article, signed for indexes is the norm

Huh? If you write things[n] in Rust, and n isn't usize that's an error, you can't index things with the other primitive types at all out of the box.

Re:Almost Always Unsigned by berkut on Sunday January 02, 2022 @01:03PM (#29771502)
Wait, what?

Pretty much everything for indices (at least in the stdlib) seems to be 'usize' in my experience (i.e. Vec), which is unsigned.

Am I missing something?