Live data from Hacker News

How could the early Unix OS comprise so few lines of code?

retrocomputing.stackexchange.com

111–120 of 170 posts

Re: How could the early Unix OS comprise so few lines of code?

#111
post #88

Earlier quoted context omitted.

Not really. C was an iconoclast even at the time. Pascal was the en vogue language of the moment, and it used a length-prefixed string format. But sure: it's true that in (a half century of!) hindsight, C strings were probably a mistake. But don't sell null-terminated strings short either. C could play tricks that Pascal couldn't. Iterating over the characters of a string has a natural expression using the same compi…

So you just don't store the array's length near the arrays beginning but instead inside the slice-typed variable which lives somewhere else entirely. Boom, you got the best of the both worlds: trivial slicing and reliable bounds checking.

> instead inside the slice-typed variable which lives somewhere else entirely.

OK... where? Now you have a complicated heap-like semantic inside your compiler internals. But not everyone wants their string metadata in the heap. So now you need allocator semantics a-la C++, which ultimately leads to move semantics, etc...

Good luck getting that done in 1972. No, DMR was right, Pascal was wrong, and fancy modern string semantics were still two decades in the future. C was the best it could be given the constraints of the era.

Re: How could the early Unix OS comprise so few lines of code?

#112
post #107

Earlier quoted context omitted.

Pascal strings had the same size overhead as C strings. One using the "byte" for length, the other for size.

But C strings could at least be arbitrarily long, Pascal strings were extremely handicapped. It’s like they understood why length prefix is better, but then picked the worst possible implementation.

Pascal strings were a bad implementation of general strings, but were extraordinarily easy to implement.

Re: How could the early Unix OS comprise so few lines of code?

#113

I feel that most 100K line programs could be rewritten with just 10K lines and end up being more reliable. Feature creep is responsible for some of the code bloat but I can guarantee from experience that, in the vast majority of projects, you could keep all the features and still cut the code to at least 1/10th of its size. I think the reason for this is because developers who focus on development speed do so at the…

I know that 10% of my marketing spend gets me 90% of the benefit. The problem is, I don't know which 10%.

Re: How could the early Unix OS comprise so few lines of code?

#114

I feel that most 100K line programs could be rewritten with just 10K lines and end up being more reliable. Feature creep is responsible for some of the code bloat but I can guarantee from experience that, in the vast majority of projects, you could keep all the features and still cut the code to at least 1/10th of its size. I think the reason for this is because developers who focus on development speed do so at the…

> you could keep all the features and still cut the code to at least 1/10th of its size. I do not disagree. I feel like, in some cases that might even be the minimum reduction. In some cases it might be more like 1/20th. But does that cut require twice as many man-hours, or does it require x40 man-hours? More? Whatever the actual answer, I do not think it cheap. I don't even know how to guess how much added effort an…

I don't think its a question of time spent. it is certainly a matter of experience

Re: How could the early Unix OS comprise so few lines of code?

#115
post #104
post #97

Earlier quoted context omitted.

Toy solutions deal with small data inputs. How many lines of that 20k is just optimizing for large inputs (you can’t have long repeating sections in small inputs).

A lot of it is, but the point remains no matter where you set t he bar, you can usually get most of the benefit with a tiny portion of the code. Sometimes squeezing out a tiny bit more performance isn't worth much, sometimes it's worth 10x or 100x the amount of code - the point is not that it's inherently wrong to write all that extra code. But you should at least be aware when the returns are diminishing to a point…

Dealing with edge cases is where your code blows up. Once you find an edge case do you leave it unaddressed and the program generate a wrong/unexpected answer? Could it be a potential security flaw?

Unfortunately when we write initial specifications we almost certainly get them wrong in one way or another. Trying to deal with that after the fact commonly leads to application bloat.

Re: How could the early Unix OS comprise so few lines of code?

#116

Earlier quoted context omitted.

> you could keep all the features and still cut the code to at least 1/10th of its size. I do not disagree. I feel like, in some cases that might even be the minimum reduction. In some cases it might be more like 1/20th. But does that cut require twice as many man-hours, or does it require x40 man-hours? More? Whatever the actual answer, I do not think it cheap. I don't even know how to guess how much added effort an…

I don't think its a question of time spent. it is certainly a matter of experience

Experience it turns out, is massively expensive.

Re: How could the early Unix OS comprise so few lines of code?

#117
post #52

I disagree that it’s a human or subjective factor as others imply. Or at least to me it’s a secondary contributor. Back then, the hardware and peripherals were so much simpler. There was no graphical output for the original PDP where Unix was initially developed. Not even a terminal. There was no networking either. The features of the system were also rather basic (to us). And security wasn’t even a thing they though…

Heh, even error handling these days. We expect our applications to give reasonable feedback and debugging on what when wrong without finding a core file on a server somewhere.

I'll take a message "hey dummy, your configuration is wrong here" rather than SIGBUS any day of the week.

Re: How could the early Unix OS comprise so few lines of code?

#118
Same reason you can write a proof of concept in a weekend, but the production version can take years.

The web's best example is twitter. Anyone can write a twitter clone in a weekend. A reasonably competent programmer can create a multiuser twitter clone in under an hour.

But you can't write twitter in an hour.

It's amazing how much you can write when your requirements are much smaller.

Also if you write your Unix for exactly one hardware, then you don't need two serial port drivers. And therefore you don't even need a serial port driver abstraction API.

Re: How could the early Unix OS comprise so few lines of code?

#119
post #59
post #7

Earlier quoted context omitted.

They also didn't care nearly as much about performance. Or to be more precise, they had very different trade-offs to make. Back then, you could have a system call and context switch for every read and live with the overhead. Today we have something like io_uring.

I'd guess that back then system call overhead was lower than with modern CPUs with deep pipelines, speculation and their vulnerability workarounds.

I'm thinking most stuff was designed around single core performance. Lots of drivers had big'ole gigantic locks which really killed multi processor performance. These days with modern CPUs with a ton of cores the complexity has increased greatly.

Re: How could the early Unix OS comprise so few lines of code?

#120

Same reason you can write a proof of concept in a weekend, but the production version can take years. The web's best example is twitter. Anyone can write a twitter clone in a weekend. A reasonably competent programmer can create a multiuser twitter clone in under an hour. But you can't write twitter in an hour. It's amazing how much you can write when your requirements are much smaller. Also if you write your Unix fo…

Writing the POC takes 90% of the time, writing the code to deal with the edge cases takes the other 90% of the time!

Or another one I like to say. It takes a few lines of code to deal with the right answer. A few lines code to deal with the wrong answer. And an absolutely massive amount of code to deal with Russell's Paradox.

Post reply on HN