3 ms·
Ask HN: What would a better C look like?
- gabrielblack 8y agoProbably nobody needs a "better C" being possible to use C++ in procedural way, avoiding that C parts considered error prone, ugly or dangerous (i.e. using C++ string, smart pointers, etc). However, if we are talking about a different language, not a C improvement, I think Go could be the answer.
- caspervonb 8y agoWhile it's possible to avoid the shitty parts of C++, libraries and community isnt there as there's a pretty huge divide between Java style C++, C style C++ and "modern idiomatic C++". Also a better C would have to be as simple as C, C++ is the definition of complexity. Might look simple on the surface but heck even Meyers can't make heads or tails of the spec ;) As for the need, there are plenty of contenders like Zig, Odin, Jai, etc. For the most part tho they seem to be about fixing the tooling pipeline, module system and standard library. Syntax might differ ever so slightly but feature set is more or less the same.
- krapp 8y agoA better C would be C with a few features of C++: function and operator overloading and references. Also metaprogramming... maybe not exactly C++ templates but some sort of macros. Also lambdas. I would also remove the distinction between 'class' and 'struct' and just have 'struct'. I would add the bracket shorthand [] for arrays and {} for maps (and add a map type, maybe.) And honestly, the more I think about it, the more a "better C" starts to look like a "better Lua," with the ability to return multiple values from a function.
- NonEUCitizen 8y agoD with -betterC flag: https://dlang.org/spec/betterc.html https://dlang.org/spec/betterc.html
- Gibbon1 8y agoThe three things I can think of are. 1. Eliminate all UB 2. Ability to strictly define memory layouts 3. Ability to safely construct ABI stack frames.
- iamNumber4 8y agoAs already mentioned. It exists, D Lang. It’s a better C and a better C++. It has a runtime, which you can choose or not use. It is ABI compatible with C, and C++ ABI is a work in progress. You can switch from writing C to D, and still use all of the existing C libraries and code you do today. You can even use D libraries in your C projects. There is the betterC flag that can be used as well which essentially turns off the D Lang runtime. The runtime allows garbage collection and other memory safety that more modern languages like Java and C# have spoiled use with. Also allowing for write once, compile every where. Making it a very portable language. http://www.dlang.org http://www.dlang.org The other benefit is it is a language not owned and developed by a corporation like Java, C#, objective-C and go. So there is no ulterior motive’s or agendas by said corporation.