Remix.run Logo
teo_zero 2 hours ago

I agree on the former two (std::string and smart pointers) because they can't be nicely implemented without some help from the language itself.

The latter two (hash maps and vectors), though, are just compound data types that can be built on top of standard C. All it would need is to agree on a new common library, more modern than the one designed in the 70s.

ninkendo an hour ago | parent | next [-]

I think a vec is important for the same reason a string is… because being able to properly get the length, and standardized ways to push/pop from them that don’t require manual bounds checking and calls to realloc.

Hash maps are mostly only important because everyone ought to standardize on a way of hashing keys.

But I suppose they can both be “bring your own”… to me it’s more that these types are so fundamental and so “table stakes” that having one base implementation of them guaranteed by the language’s standard lib is important.

uecker 2 hours ago | parent | prev [-]

why not std::string?

teo_zero an hour ago | parent | next [-]

You can surely create a std::string-like type in C, call it "newstring", and write functions that accept and return newstrings, and re-implement the whole standard library to work with newstrings, from printf() onwards. But you'll never have the comfort of newstring literals. The nice syntax with quotes is tied to zero-terminated strings. Of course you can litter your code with preprocessor macros, but it's inelegant and brittle.

direwolf20 2 hours ago | parent | prev [-]

It's a class, so it doesn't work in C.

uecker an hour ago | parent [-]

Sure, but you can have a similar string abstraction in C. What would you miss? The overloaded operators?