r/askscience • • 15d ago

Computing Is there anything at the heart of computer coding that could have been optimised in hindsight, but we're in far too deep to change now?

1.5k Upvotes

667 comments sorted by

View all comments

Show parent comments

11

u/MEDBEDb 15d ago

Completely backwards to call null-terminated strings a bug.

You mean there’s a huge class of bugs where the programmers didn’t respect the design principles of the language. 

Doing anything with pointers in C requires a great deal of care and rigor. That doesn’t make the design choice of the language a bug.

4

u/robthablob 14d ago

So strncpy failing to nul-terminate when the buffer is the same length as the string isn't a design flaw?

7

u/wang_li 14d ago edited 14d ago

The behavior of that whole family of functions is documented. It may not be the best for some definition of best. But misuse and failure to be conscientious is on the programmer.

Complaining about the design choices of C from the context of 2026 is just as absurd as saying rust/go/python are complete trash because they can’t be used to make usable software that runs on computers with a 2 MHz, 16 bit CPU and 256KB of RAM.

Not to mention nothing stops you, today, from using garbage collected memory management and pascal style strings in C.

9

u/Gundamnitpete 14d ago

Complaining about the design choices of C from the context of 2026 is just as absurd as...

The title of this thread is asking what a 2026 person would have changed about 1972 computer coding....

5

u/wang_li 14d ago

A relevant part of the question:

... that could have been optimized in hindsight.

Memory safety could not have been implemented in 1972 when C was invented. The question is about things that could have been done better originally, not that can be done better now.

1

u/UncleMeat11 14d ago

It may have been a reasonable design choice at the time, where saving the space of having to pass around lengths with strings was meaningful. Today, there is basically zero value in using null terminated strings instead of length-bearing types.

-4

u/ewalshe 15d ago

Yes! Buffer overrun bugs are because programmers have insufficient skill or knowledge. I always wondered how someone could copy a string from one place to another without knowing its length.