4 ms·
Do types like 'int' and built-in operators like integer division smell bad too?
by rsc 4y ago
Do types like 'int' and built-in operators like integer division smell bad too?
- yakubin 4y agoYour question sounds provocative, nonetheless I'm going to give an honest answer. First, let me preface that with a disclaimer that those opinions are reserved for general purpose languages. Domain-specific languages should be judged differently. Built-in types like int don't bother me. Built-in string also doesn't bother me, because it is immutable. strings.Builder is part of the standard library on the other hand. I think this division is perfect, because I feel that anything that's denotable as a literal should be built-in. Algorithms on the other hand belong in the library. When it comes to integer division, it's an operation which has a pair of inputs and one output. In other words, it behaves like a function. On the other hand, its most reasonable implementation is a single machine code instruction and compilers usually have a bunch of optimizations for it, which turn it into something else. In other words, I think the best option here is for it to be an intrinsic, a bit similar to how it is in Standard ML[1] or Scheme[2]. The reason for those opinions is that I think implementing things in the compiler instead of the library signal that an instance of a legitimate general problem occurred which lacked a solution in the language, and instead of changing the language to solve the problem for all users, only the specific problem with, in this case, map and dynamic array was solved, and only those specific implementations of those concepts. As you obviously know, Go gained generics, so this is in large part irrelevant now. Also let me state that overall I think Go is a pretty good language. I like it (with generics and without). My comment just comes from the disagreement with the quoted argument. [1]: Tangentially, one thing I don't like in Standard ML is polymorphism of built-in operators. It's another example of a feature which language designers reserved for themselves, and did not give it to users. [2]: I'm basing this on my understanding of the Chez Scheme implementation, which implements the division operator in the library, in Scheme itself, but this implementation relies on an intrinsic. (Assuming it's implemented the same way as other operators I've checked. I haven't checked this one specifically.)
- rsc 4y agoApologies if the comment sounded like I was trying to provoke. My point was that there is a line, and different languages draw the line in different places. It's true that ints _can_ be made more library-like, but it's also true that most people don't complain about them being built-in to nearly the same degree as, say, built-in maps.
- yakubin 4y agoSure, no problem. I respect you and your work a lot, including Go.
- erik_seaberg 4y agoYeah, I should be able to use a third-party bignum library and have it feel natural. 2022 hardware is so powerful that it’s weird that so many languages still default to overflow and rounding semantics. Those are risky optimizations that we shouldn’t opt into without a good reason.
- xigoi 4y agoYes. I don't think a language creator should be given unnecessary special privileges over users.