Why is code so long!

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
nexos
Member
Member
Posts: 1078
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Why is code so long!

Post by nexos »

Hello,
I have been looking at code to other projects, and have realized that their code is much more complex and in depth then mine. How come that is? My code is generally short and to the point. Looking at other projects, I often wonder what they do to make theirs much longer. Am I missing something, or is short and sweet code better then big and complex code? What is your code like? My OS is very young, maybe that has something to do with it? Looking at Linux 0.0.1, it looks like it was pretty short. But whats your project like? I am just curious so I know whether I need to redo my coding style :) .
Thanks,
nexos
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Why is code so long!

Post by neon »

Hi,

Without looking at your code, can't really comment on it. Data structures and general architecture has a large effect on the resulting code and what it looks like. Code might be designed more complicated with the intent of using more sophisticated data structures or algorithms. Also think they just naturally grow as more features become needed over time. Could it be missing features? Could it something else? What do you think makes the code look different? I find that there are so many independent components in the system working together that I cannot see the code any simpler.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Why is code so long!

Post by iansjack »

I suspect that the projects that you are looking at are more developed, support a wider range of systems, and are more robust than yours.
nexos
Member
Member
Posts: 1078
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Why is code so long!

Post by nexos »

I guess as stuff gets more mature, it grows in size. I just want to be sure that I wasn't doing anything wrong with my OS.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Why is code so long!

Post by bzt »

nexos wrote:I guess as stuff gets more mature, it grows in size. I just want to be sure that I wasn't doing anything wrong with my OS.
Take a look at xv6. It has an insanely small code base (which also includes userland utilities), yet it is a fully functional operating system. According to the git history, it is at least 15 years old (the x86 port).

Cheers,
bzt
nullplan
Member
Member
Posts: 1766
Joined: Wed Aug 30, 2017 8:24 am

Re: Why is code so long!

Post by nullplan »

My best guesses are: Bugfixing and lack of proper design. Bugfixing (especially in a badly designed program) can often take the form of adding code to handle a specific case, rather than modifying code such that wrong assumptions are not made. This is usually effective (sadly), and so if a rotten codebase is left to stew a bit, it will grow all these case distinctions that are all necessary (because without them, the code is buggy), but that ultimately stem from a failure to properly model the problem in the first place.

Or maybe I'm just cranky because I just got off work, fixing a codebase that grew to enormous proportions due to lack of overarching design. I threw out 1000 lines of code today. I would quote Ken Thompson here, but I find myself throwing out 1000 lines of code so often, I'm wondering if I'm that good or the code is just that bad.
Carpe diem!
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Why is code so long!

Post by eekee »

I've spent literally years pondering this. And then I forgot most of it. :mrgreen:

Plan 9 gets an amazing amount done with astonishingly little code. The joke is "90% of the code implements externally-imposed standards." There's a lot of truth in that. It's far more powerful than xv6. For scripting tasks involving multiple machines, especially on a LAN, it's vastly more powerful than POSIX and yet much smaller and simpler than even a basic POSIX standard OS. But...
iansjack wrote:I suspect that the projects that you are looking at are more developed, support a wider range of systems, and are more robust than yours.
After about 5 years of full-time Plan 9 use, I had to conclude there's a lot of truth in this viewpoint, particularly the "more developed" part. Plan 9 does a suprising range of things, but I always found myself bumping into limits and awkward artefacts which I have to say result from trying to get too much out of too little code. More complex systems are often more comfortable. One huge example of such artefacts was excessive use of private namespaces to simplify the code. For instance, the kernel had no means of multiplexing the console between processes. The window manager, Rio, did it instead, using private namespaces to present a different virtualized /dev/cons in each window. Ditto for /dev/mouse. This means you can't simply mount a disk or service in one window and have it accessible in others. 9front supports a workaround, but any workaround is more code and, like so many other things in Plan 9, it requires yet more code (in the form of sophisticated scripting at the very least) if you want more than the minimum use out of it. "Plan 9 is not meant for non-programmers."

I am not, however, trying to excuse systems which are complex merely due to a lack of understanding or clarity of thought. Some of Plan 9's simplifactions may have been genuine all-round improvements which the computing world is worse off for not adopting, but I'm not entirely in a position to evaluate them.
nullplan wrote:My best guesses are: Bugfixing and lack of proper design. Bugfixing (especially in a badly designed program) can often take the form of adding code to handle a specific case, rather than modifying code such that wrong assumptions are not made. This is usually effective (sadly), and so if a rotten codebase is left to stew a bit, it will grow all these case distinctions that are all necessary (because without them, the code is buggy), but that ultimately stem from a failure to properly model the problem in the first place.
That's a lack of refactoring, or just "factoring" if it's Forth. It is a somewhat common problem but probably much less than it was not the importance of refactoring is understood. Charles Moore was promoting factoring in 1970 and onward, (and I don't suppose he invented the concept,) but I don't think the majority of programmers started taking it seriously until the '00s, maybe even the late 00s. No doubt the "agile programming" fad made programmers conscious of it. (Half of agile programming came straight from Forth good practice.)
nullplan wrote:Or maybe I'm just cranky because I just got off work, fixing a codebase that grew to enormous proportions due to lack of overarching design. I threw out 1000 lines of code today. I would quote Ken Thompson here, but I find myself throwing out 1000 lines of code so often, I'm wondering if I'm that good or the code is just that bad.
The code is massively overdue for refactoring and may have been the product of confused minds in the first place. ;) Some people have trouble expressing themselves clearly and concisely. I quite expect they also have trouble writing clear, concise code. (Incidentally, I factored those two sentences before even finishing them. :P Some days I'm good at factoring my posts. Other days not so much. Today is in-between.) In any case, I'm sure what you're doing counts as [re]factoring.

Sometimes, code bloat is due to bad dependencies, in which you could include languages like Java which require a lot of boilerplate. A friend who hates code bloat interned at a tech company and later went to work there. While interning, he wrote a 500-line utility and couldn't figure out how to integrate it into the build system, so he wrote a 10-line makefile. When he returned to work there the next year, he found someone had written a 150 line file to integrate it into their build system. In other words, the build script for this little utility had gone from 2% to 30% of the size of the utility itself!
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Post Reply