Live data from Hacker News

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

retrocomputing.stackexchange.com

21–30 of 170 posts

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

#21
post #13

Earlier quoted context omitted.

In a way it became the complete opposite of how it started. At first one OS for many users, ea with many processes. Now, with containers, micro services etc. we have an OS per service/process. Still the original abstractions work surprisingly well though makes it me wonder how a complete redesign of would look like aimed at modern usage.

Most of the time the OS is just overhead now. Look at unikernels for one possible future.

> Most of the time the OS is just overhead now.

And they became so good at it that we added more OS' on top, with our VMs and OS-like web browsers...

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

#22
post #4

I think mindset plays a role as well. Back in the day, there was a restraint on adding features, at least when they would make the logic more complicated for only a tiny or imagined benefit. Part of that was memory/storage limitations. But I think the pursuit of an abstract idea of elegance was equally important. After all, these systems were primarily written for other computer people. This idea is completely gone f…

> This idea is completely gone from the world of software engineering. Systems become overloaded with the implementation of every crappy idea under the sun -- if a PM in a fever dream can think of it, and an overworked dev can hack it together, it goes in.

That's a very developer-centric point of view. Elegance and simplicity are great, but if a program is missing crucial features, it becomes less useful or even useless for users. Like it or not, but the vast majority of software is written for the benefit of its users, not that of its developers.

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

#23

Earlier quoted context omitted.

Especially the features we don't consider. Try replacing your "ls" command with the one found in the original Unix, sure it's 90% smaller, or more, but I guarantee that it doesn't do colors.

Is that an example of the 80/20 rule... with some creativity? 80% of code being for the 80% of the functionality that aren't strictly necessary ;).

"Strictly necessary" is too strict a criterion. For me, ls without colors to distinguish between files and directories sucks ass, as would an ls which doesn't sort by name (also not "strictly necessary").

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

#24
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 expense of succinctness. The more foresight you have when you're writing code, the fewer lines you will end up with. Unfortunately, developing that foresight requires time spent not coding; it means choosing the best option out of all viable alternatives. When developers are pressed for time, even if LOC is not used as a metric to judge them, they will not have the time to look ahead in the near future to minimize the lines of code.

Workarounds tend to require a lot of lines. When code is rushed, it ends up getting littered with workarounds which require additional checks, additional tests, etc... A bad foundation with sub-optimal abstractions can force developers' hands and lead to even more bad code being produced on top.

Before I start working on a feature, I simulate how it's going to work in my head and try to identify all the hurdles and alternatives; sometimes several levels down in the hypothetical component/module hierarchy. I do brainstorms, draw diagrams and make lists of pros-and-cons. I use as many visual aids as I can get. I play devil's advocate with my own ideas until I'm at my mental limit and I cannot visualize the solution (and requirements) in any more detail and cannot identify any other hurdles. It actually feels like playing chess. You need a strong understanding of your tools and environment to be able to do do this kind of adversarial brainstorming and most importantly, you need time. Especially in the early stages of the project. The further along you are in the project, the less foresight you need.

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

#25
post #16

Earlier quoted context omitted.

With virtual memory and demand paging, memory management (done efficiently) becomes a much harder problem, too.

Unix V7 had virtual memory, at least, I can remember the PDP-11 disk unit throwing itself around violently when somebody started nroff.

> the PDP-11 disk unit throwing itself around violently when somebody started nroff.

That was the overlays… the early days substitute for the virtual memory proper. If I remember correctly, the first PDP-11 to have the true virtual memory and a MMU was PDP-11/70 which had 18-bit wide hardware addresses.

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

#26
post #2

Answer: smaller target to cover! Modern Linux has most code in device drivers to support so many different devices. Then, it supports many targets for other subsystems, like file systems. The original Unix provided one implementation for each subsystem. They relentlessly simplified the problem they were solving to make it doable.

But modern Linux is only the kernel. Early unixes included the userland as well which creates a different balance in types of code.

In fact traditional unixes still do, like FreeBSD. Linux is the odd one out with this separation. I think it happened because GNU was not very successful with Hurd but they made great userland so "Linux" became kinda a combo. And for Linus the userland was never really in scope anyway.

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

#27
post #11

Earlier quoted context omitted.

Features are, like it or no, where the value is.

Especially the features we don't consider. Try replacing your "ls" command with the one found in the original Unix, sure it's 90% smaller, or more, but I guarantee that it doesn't do colors.

Ls -l tells you whether it's a directory. (-l flag available in the first edition)

If you want colours you can pipe it through a sed script.

If you want to sort it in some way you could pipe it to sort or something.

No system is ever going to do everything everyone wants. The Unix solution is to allow you to easily add the things you do want.

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

#29

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…

Reminds me of Mark Twain's quote "I didn't have time to write you a short letter, so I wrote you a long one."
Post reply on HN