Unfortunately not every programmer is or knows their limitations.
Unfortunately not every programmer is or knows their limitations.
And never make a mistake.
Honestly, it's probably just because I'm not good enough, but I prefer to use my focus on improving the functionality of my code instead of ensuring any change I make is correct.
I've successfully maintained some 100k lines C++ code in the past. I would rather avoid that in the future.
Additionally, if the project is owned or influenced by a corporation, the mythical programmers have little influence:
Some authoritarian ex-mediocre-programmer-turned-middle-manager calls the shots and is more anxious to "grow the team" than to ship robust software.
Are you seriously saying that this isn't also true for C, (and indeed for all programming languages)?
A challenge - try writing a program in C to read a text file containing lines of unspecified length, sort them, and output them in sorted order. Compare the C++ and C code and tell me which you think is the cleaner and safer.
To meet your challenge, think about the problem. How about this?
file size + 1 => s
allocate char buffer b[s]
read file to b (all data must be in memory, or merge sort. if on linux and allocation worked, read may fail! oom will get us, or we bail on read failure)
add final newline if missing
count newlines => n
allocate line pointers p[n] (if line pointers will not fit, we bail -- we could use offsets and fancy virtualization, if this is not a Z80)
fill pointer array p
sort => sorted[n] (if sorting fails, bail)
output sorted lines
Same for C and C++. UTF-8 is ok.Do you want more data than will fit into memory? Even then, C++ doesn't bring much to the table. Separating the sort algorithm? Yes C++ BEGINs to pull ahead by a bit.
safe? yes. easy to write? yes. no fancy bits? yes. Transcribe to C C++ as you will. Java? won't be as pretty. Rust, Go? don't know. Javascript. Not even close.
Since this is a "beginning programmer" problem, give a design that works for another language that makes sense to a beginning programmer.
I would argue that this is setting up for catastrophic failure. If not when writing, sometime later when maintenance happens.