Live data from Hacker News

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

retrocomputing.stackexchange.com

81–90 of 170 posts

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

#81
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…

> Some code practices are what we now consider to be terrible, optimizing for the limitations of that time.

This. If you went back to 1972 when Dennis Ritchie was working on C and said "String literals should have an extra machine word for their length and strings should have yet another machine word for the capacity of their buffer" you'd be considered a moron for wasting so much memory.

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

#83
post #46

It's unsurprising when you consider that there are often several magnitudes of difference in code between what code grows to when you have the capacity and time and compounding user requests, and what a meaningful starting point that provides useful functionality above and beyond what you had without it looks like. As an extreme example here[1] is an article by Brian Kernighan about a basic regexp matcher by Rob Pike…

A classic example of diminishing marginal returns.

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

#84
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…

> Some code practices are what we now consider to be terrible, optimizing for the limitations of that time. This. If you went back to 1972 when Dennis Ritchie was working on C and said "String literals should have an extra machine word for their length and strings should have yet another machine word for the capacity of their buffer" you'd be considered a moron for wasting so much memory.

Depends if you managed to explain why

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

#85
post #66

Earlier quoted context omitted.

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.

I'm only speaking from impression, but I think early Unix's userland is probably comparable with busybox in terms of code size and features.

I’d be surprised if early Unix userland wasn’t even more barebones than busybox.

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

#86
post #76
post #62

Earlier quoted context omitted.

If you removed from a complex program any feature that was used by less than 2% of the users the program would be much smaller and simpler. However you also lose each 2%. In many cases every user uses a different subset of what your program does, and so the end result is no users at all because your program is useless.

Yes, but part of the argument was that you can often cut drastically without cutting features when you take the time to understand the problem properly. Sometimes everyone actually does use genuinely different features, but more often there are different ways of solving the problem that will still be more concise even if you keep everything. To take a somewhat concrete problem from a past job: We had an agency do a b…

Yeah, but do you really think any of that applies to things like the Linux kernel? You think with thousands of talented developers they have problems as simple as duplicate code?

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

#87
post #76

Earlier quoted context omitted.

Yes, but part of the argument was that you can often cut drastically without cutting features when you take the time to understand the problem properly. Sometimes everyone actually does use genuinely different features, but more often there are different ways of solving the problem that will still be more concise even if you keep everything. To take a somewhat concrete problem from a past job: We had an agency do a b…

Yeah, but do you really think any of that applies to things like the Linux kernel? You think with thousands of talented developers they have problems as simple as duplicate code?

absolutely. Any project with more than a couple dozen devs will have duplicated functionality (if not directly duplicated code). When you combine that with the loose coordination, I wouldn't be surprised if 20% of functionality in the linux kernel was duplicated.

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

#88
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…

> Some code practices are what we now consider to be terrible, optimizing for the limitations of that time. This. If you went back to 1972 when Dennis Ritchie was working on C and said "String literals should have an extra machine word for their length and strings should have yet another machine word for the capacity of their buffer" you'd be considered a moron for wasting so much memory.

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 compiler features as arrays. A pointer into the middle of a string was still a valid string. You could lex a string inline during parsing by adding termination to the end markers or whitespace, etc...

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

#89

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 and time it requires.

In many cases and companies, it might even require hiring highly sought-after engineers... in-house talent simply isn't up to it.

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

#90
post #25
post #16

Earlier quoted context omitted.

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.

The 11/70 had a 22-bit wide memory bus and an 18-bit wide unibus which was mapped to the high 256kb of the 4M physical address space.
Post reply on HN