3 ms·
I think that if you want that, you're working with the wrong language.
by becquerel 3y ago
I think that if you want that, you're working with the wrong language.
- coldtea 3y agoOne could say that for any feature that a language got later on and everybody feels fine with it added. Go/Java and generics for example. C++ and auto or closures. Javascript and async/await ("just learn regular Javascript async patterns"). The thing is C could have had a string type that knows its length since day one, with known performance tradeoffs, and also allow for everybody to build their own type in the more rare cases where it's needed. And most of buffer overflow and string handling bugs would have been avoid, as most of the programs using them don't need the performance or special handling of C strings (or don't need them where the bugs occur, e.g. when reading some configuration file).
- pjmlp 3y agoIndeed, stuff like sds should have long been available as vocabulary types.
- throwaway894345 3y agoGo/Java is a weird one. I don't see many instances of generics in the wild. Honestly the biggest benefit I enjoy is that people who never intended to use Go in the first place are slightly less loud about Go's position on generics. Beyond that, it's a small quality of life improvement to only have to define min and max once for all of my integer types (incidentally, this is really only a problem in Go because it's so dang easy/convenient to create your own int types, whereas in Rust, Java, TypeScript etc it seems like everyone just uses the standard int types for everything).
- hgs3 3y ago> I think that if you want that, you're working with the wrong language. Maybe yes, maybe no. Walter Bright, the creator of D, has a nice article on the subject [1]. I think Zig's approach which allows slices to decay to pointers and pointers+lengths to create slices is ideal. The real benefit of slices is the implicit bounds checking which some C folks might object to since one of the appeals of C is no "hidden magic". [1] https://digitalmars.com/articles/C-biggest-mistake.html https://digitalmars.com/articles/C-biggest-mistake.html
- pjmlp 3y agoThe thing is, many times we aren't the ones to chose the language, rather the ecosystem we need to integrate with. So working with C or C++, it is.