Live data from Hacker News

Linux eliminates the strncpy API after six years of work, 360 patches

phoronix.com

111–120 of 340 posts

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#111

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Partly agree but there would have been squabbling on the data type of the size, unless it was variable length. The latter would have had other issues too.

For a while, 16bit would probably have seemed too extravagant. Now 32bit would probably seem too small.

For a “strongly typed” language, C is pretty damn loose where would have mattered.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#112

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Partly agree but there would have been squabbling on the data type of the size, unless it was variable length. The latter would have had other issues too. For a while, 16bit would probably have seemed too extravagant. Now 32bit would probably seem too small. For a “strongly typed” language, C is pretty damn loose where would have mattered.

No, there would not have been and this is most likely not the reason. size_t exists for precisely this use case. It has existed since C89.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#114

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Partly agree but there would have been squabbling on the data type of the size, unless it was variable length. The latter would have had other issues too. For a while, 16bit would probably have seemed too extravagant. Now 32bit would probably seem too small. For a “strongly typed” language, C is pretty damn loose where would have mattered.

I like the D approach where arrays are just `struct { size_t length; T* ptr; }` internally --- and strings are just arrays of `immutable(char)`.

It has a big advantage over the Pascal approach in that you can do zero-copy slicing, since the length is separate from the actual data.

And `size_t` makes perfect sense for the length here. If your strings are longer than the address space (which `size_t` technically isn't, but is practically very strongly correlated to it), then you're going to have a problem regardless of the number of bits for the length anyway.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#115
post #108
post #103

Earlier quoted context omitted.

To be clear my original statement was that the bottleneck was most likely not mechanical code changes (where CC would have the most direct speedup) but everything else involved in the process (testing, discussion/approval, inclination towards caution, deliberately narrowly scoped changes, etc). Not that the Linux kernel approval procedures couldn't be streamlined, work couldn't be parallelized, or anything else like…

Right. And what I'm saying is I refuse to believe the Linux kernel approval procedures are that inefficient. Therefore, your belief "bottleneck was most likely not mechanical code changes" is most likely incorrect. It would be interesting to get the actual answer to this question. EDIT: Substantially changing your argument after posting isn't nice. But to answer your charge - no - I never made that claim.

Sorry, I didn't feel like this thread needed to be dragged out any longer since it's going in circles at this point and expanded my comment, but I didn't realize you had already replied.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#117
post #9

Earlier quoted context omitted.

I think it was NULL itself. It was a long way until we realised we don't want invalid values and could use the type system to help us use special values safely.

Compared to scripting languages with actual tagged types, C doesn't really have a type system, and that's readily apparent to anyone who has written C in the last 43 years and debugged a program written in it. C pretends types exist with you, but once bytes hit the road, it's all real-life and segmentation faults.

By that logic, no natively-compiled language has a type system.

Though I should note that in a way, even some ISAs have one, what with e.g. separate float vs integer registers.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#118
post #113
post #109

A lot of pain and suffering to avoid having a string datatype.

What's a way they could get a strong data type here? Wouldn't that also require a large refactor of the code around strncpy to use the type and its functions?

Today yes, but 40 years ago someone made the decision that a string was a char array and that every string manipulation going forward would require manipulating arrays. Talking about costly decisions.

It’s actually interesting to compare the pain and suffering of switching to a string datatype in the 80s (refactoring the limited code base then) vs the next 40 years of unnecessary boiler plate syntax and bugs for not having this type in key APIs.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#119
post #118
post #113

Earlier quoted context omitted.

What's a way they could get a strong data type here? Wouldn't that also require a large refactor of the code around strncpy to use the type and its functions?

Today yes, but 40 years ago someone made the decision that a string was a char array and that every string manipulation going forward would require manipulating arrays. Talking about costly decisions. It’s actually interesting to compare the pain and suffering of switching to a string datatype in the 80s (refactoring the limited code base then) vs the next 40 years of unnecessary boiler plate syntax and bugs for not…

Linux doesn't exist in the 1980s, Linus started this work in the 1990s.

But yes, the string slice type should have existed in C89 and it's very obvious from here that not having something of this sort - maybe what Rust would call &[u8] the reference to a slice of bytes - was a big problem for C.

The correct way to represent this is what's called a "fat pointer". A pair of values, one is a conventional "thin" pointer to the start of the slice, and the other is a count. Your register pressure increases in the compiler backend but problems are significantly reduced because you have fewer bounds misses.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#120

wow, very humbling. I'm actually amazed how many people contributed to this. It's easy to get attribution for "cool new features", but arguable removing bad features is even more important for something as fundamental as the kernel. Cudos! I'm sure these are the sorts of things that will go down as folklore from the "founding ages", when everyone will have forgotten how to understand source code in 50 years and the C…

Reminds me of Deepness in the Sky (Vernor Vinge) where a guy maintains a ship by doing software archeology. He is the only guy who knows what the Unix epoch is.
Post reply on HN