OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 2:26 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Why is code so long!
PostPosted: Wed Feb 03, 2021 4:49 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Wed Feb 03, 2021 6:48 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
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();}


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Thu Feb 04, 2021 3:20 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Thu Feb 04, 2021 1:55 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Fri Feb 05, 2021 2:23 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
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


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Fri Feb 05, 2021 10:08 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1590
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!


Top
 Profile  
 
 Post subject: Re: Why is code so long!
PostPosted: Mon Feb 08, 2021 11:35 pm 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 811
Location: Hyperspace
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group