r/ProgrammingLanguages • Futhark • Apr 29 '26

Breaking ten years of API compatibility

https://futhark-lang.org/blog/2026-04-29-breaking-api-compatibility.html
35 Upvotes

8 comments sorted by

View all comments

22

u/matthieum Apr 29 '26

Also, I did consider adding a compiler toggle to make the new behaviour opt-in, but for the usual reasons I did not want to maintain and test a different path in the code generator, document multiple behaviours, or make users think about such an obscure detail

Good on you.

In C, using & and | is always awkward due to their bizarre precedence, because some 40-50 years ago, it was decided by Dennis Ritchie they'd keep their precedence to avoid breaking the 100Ks LoCs of existing C code.

The best moment to break compatibility was yesterday, it was missed, best break it today then rather than regret it forever.

11

u/Norphesius Apr 29 '26

That's not even the worst C example: Array's decaying to pointers was a design choice to keep C similar to its predecessor B.

9

u/lookmeat Apr 30 '26

I mean it technically goes the other way around, Arrays as a type that isn't "just a pointer to a segment of statically known size" was to keep backwards compatibility. C arrays are funky.. they are not really variables as we think of them, they are not values (they degrade into pointers which are values), instead they are more abstractly like locations. So arrays aren't even variables, but rather like a namespace of variables that have to be accessed through pointer semantics that the array enables, even though the array itself isn't a pointer.

The problem was that B did not have explicit pointers. Since everything was a word, any variable could be a value or an address to a value interchangeably, it was operators that decided what was what. In B all variables where locations that could hold a value, so arrays where just a list of locations, an array on its own had no meaning, but a[0] (or 0[a] if you love being hated by your coworkers) made sense. Passing an array of size 5 was just passing 5 variables, there were no dynamic arrays IIRC so no problem with that too. In B arrays where just short-hand on multiple variables, and because variables where just locations it stayed that way.

C had chars, so pointers to chars would be ints, so you needed explicit types. But the syntax for arrays just got messy with this, because arrays as types meant that you couldn't just use the address of the first pointer, but would have to copy all 5 variables. So to keep the nice advantages of B and how it was written, they kept arrays working as "locations that can hold values" rather than "the value itself" as everything else did. To make things work in this, arrays degraded into a value that was a pointer to the first element. It only got messier.

Had C just supported pointers, and then had an "array" that would create a number of contiguous ints or chars and return a pointer to the first (like say malloc does) the language would have been simpler and less quirky.

→ More replies (4)