3 ms·
The notion of types as type assertions is relatively new to C, and its syntax reflects that. Types in C are more storage specifications than they are type asser
by andrewla 8y ago
The notion of types as type assertions is relatively new to C, and its syntax reflects that. Types in C are more storage specifications than they are type assertions. When you declare an “int”, you’re not declaring a variable of type int per se; you’re declaring and int-sized hole where you can put values.
So the declaration on the left [ed: Was right] makes a certain amount of sense - you’re declaring an int, so that’s what you lead with. When you declare a “string” you have to think about how the string is stored; and that implementation detail bleeds into the syntax.
A C has matured the notion of incompatible types has seeped into the language to the point where now it becomes a little annoying that I can just go ahead and pass an int into a function that expects a typedef’d “type”; libraries often wrap them in very lightweight structs just to get an additional bit of typechecking. The expectations for what kind of errors the compiler can catch have grown over time but the language has only made small concessions.
- jolmg 8y ago> the declaration on the right makes a certain amount of sense - you’re declaring an int, so that’s what you lead with. I'm sorry, but that doesn't make sense to me. You say it as if it's the only sensible way to design a declaration syntax, but Haskell (and other languages) did it the other way just fine. I don't see how the differences in semantics between the 2 type systems give rise to a benefit in having the type expressed on the left. If the design came to be decided like that, it seems it's simply not something that was put much thought over. That's fine too, since the limitations of the type system do not give rise to cases where this syntax choice becomes too big of an inconvenience. Still, no benefits as far as I can see. Maybe it simply appealed to the designer's intuition more. Choosing because of that indicates that the choice was pretty arbitrary, though.
- andrewla 8y agoSorry -- I edited my reply above; the quoted sentence should be "the declaration on the _left_ makes a certain amount of sense". > You say it as if it's the only sensible way to design a declaration syntax I don't say that -- in fact, I'm replying to my own post saying that the declaration on the left was a mistake. My only point is that it is a design decision that has some historical grounding.