Why C is the best language that ever sucked.
The depths of dullness to my mid is trying to figure out some part of a computer progam which is somewhat like plotting a chess move 8 plays ahead. I can sit staring like an idiot to figure something out for ages. After a career of doing this it's easy to sit back and figure out what did I spend too much time doing and what would be a better way to say it. A shorter way at least.
I recently decides that as much as I LOVE C TO BITS, it's the worst language ever for string manipulation. LISP is better, Javascript is way better.
Now I understand the wonderful revelation the stack and the pointer did to programming languages, for I too grew up on FORTRAN... which, if you want to do most sorts of mathematical modelling or fancy shmancy matrix math then you'd be isane to use anything else. But for systems programming to build these things - and keep in mind that until C, no progamming langauge ever ran on system written in itself, all operating systems were up to that point written in assembly language.
And no lnguage at the time had a concept of a stream, where you can just read a bunch of bytes that come fling in from deviced OTHER than a punched card reader.
SO pointers in C were a very good thing. You could - very efficiently - walk thriugh a seres of bytes which would have been a nightmare in FORTRAN. Pointers good.
But in this rush to crrate a new langyage and make variabels easier, no float or double float, just integrs and floarts and thay's that.
The ironic part was, Dennis and the gang at Bell Labs who ivented C, were so obsessed with streams that the idea of a string variable got lost. Now streams are great for I/O drivers and reading data from scientif instruents. But we have to use these same mechaisms with simple text strigs and what C does is not useful. SPend any time with javascript and you have some idea what strings should be and work like.
The great irony in this is that the reason they got permission to take the rest of their careers off and just screw around in a computer room is that they had convinced management they could develop an online document processing system to essentially digitize their manuals. One presumes they meant Unix manuals, this developijng an lmot Diobertlike ecosystem of a system being built just so it could docuents itself.
So they were developing a text processing system, a system that deals with strings, but it never occured too them to make it easy on themselves (and certainly the rest of us) by making it a bit easier to deal with string variables.
So thye produced C and Unix and eventually produced Roff and Troff to drive printers and typesetting machines. This led to the implementation of digital typesetting machines and we no longer had to use the very very very danagerous hot lead methods of typography.
But, Troff was not written in C by the time it reached the University of Waterloo where I was in the 1970s, it was written in BCPL. I applied to an ad from the Waterloo Typesetting Task Force ("WTTF") and got the gig to convert Troff from BCPL to C for a grad student named Rob Beach who went to Xerox in Palo lto, while I had a very close association with Digital in Palo Alto (although I lived in the Los Angeles area, by 85 I was telecommuting) and while I never used Troff again, most of my interests were with publshing systems nd watched as Apple, Postscript and cheap laser and inkjet printers chanaged again the printing idusry that only 12 years before were using hot lead.
I think I have identified one thing that would be the least effort to gain the most efficiency, at least with string intensive - as opposed to numerically intensive - applictions. Stop using an array of char to represent strings!
It is easy to demonstrate the problem. Say you're given a string or arbitrary lebgth and have to pluck out the first seven characters. Easy right? Set a pointer to the strt of the string - you know where that is - just copy a byte and incrment that pointer so it points to the nexgt byte. Indeed easy. And quick. It only took 7 instructionns one for each ot the 7 characters.
The problem is the other end ot the string. Try to take the last 7 chaaracters. Or better yet, nd this isn't even the worst example, but it's an annoying real worls one - sy you have a guant URL and you know what the first 20 characters are, or a worse case, you need to find the seconf last slash in string. Again, kowig where the beginning of the stirng is is helpful but not as much as you might think.
Lisp has the idea of CAAR and CDR which were aactually naes of registers on some old experimental computer, long gone, yet the idea it was built to deostrate worked very very well.
Consider any sentance of words, and you wan the last one. Knowing only the address of the start of the string you have to examine each letter from front to end, then back up and look backwards at the sentance, starting at the end and workign back until the first space is found. Now y9ou have the last word.
In Lisp, CAR yields the left side of a strnig except the end bit. CDR gives the last word on the right.