I want to create an OS, but I don't know what is better:
OOP, no OOP or a mix
OOP or no OOP
- matthias
- Member
- Posts: 158
- Joined: Fri Oct 22, 2004 11:00 pm
- Location: Vlaardingen, Holland
- Contact:
OOP or no OOP
The source of my problems is in the source.
- chase
- Site Admin
- Posts: 710
- Joined: Wed Oct 20, 2004 10:46 pm
- Libera.chat IRC: chase_osdev
- Location: Texas
- Discord: chase/matt.heimer
- Contact:
Re: OOP or no OOP
I think it really depends on what language(s) you want to use. You're going to have to use Assembly so you're already using one none OOP language. Now when program logic gets a little hard to manage with Assembly you'll need to start using a High Level Language. Looking at all the HLLs, C was designed/created so that UNIX didn't have to be recoded in Assembly for each new system type. C is really the only language designed for system programming/Operating System development so that's what most people will tell you to use for OS development.
OOP adds some overhead but I think it really depends what your language preference is. When you look at it even UNIX based OSes have an OO flavor given that everything is a File. Personally I'd lean towards Asm and C for the core OS and OOP for applications and utilities, I think it really depends on where you draw the line between the OS and the apps.
OOP adds some overhead but I think it really depends what your language preference is. When you look at it even UNIX based OSes have an OO flavor given that everything is a File. Personally I'd lean towards Asm and C for the core OS and OOP for applications and utilities, I think it really depends on where you draw the line between the OS and the apps.
Last edited by chase on Fri Oct 22, 2004 11:00 pm, edited 1 time in total.
- matthias
- Member
- Posts: 158
- Joined: Fri Oct 22, 2004 11:00 pm
- Location: Vlaardingen, Holland
- Contact:
Re: OOP or no OOP
Thanks Chase,
I think I'm going to use C, first I wanted to write it in C++, but now I'm convinced that it's better to write it in C. Because it's true about the overhead.
I think I'm going to use C, first I wanted to write it in C++, but now I'm convinced that it's better to write it in C. Because it's true about the overhead.
The source of my problems is in the source.
Re: OOP or no OOP
Yeah, C is a wise choice. I tried to port my C OS project to C++, but stopped really soon. The problem is, that the most of the advantages of C++ are lost in os development because they need an existing system for e.g. exceptions etc. One more problem is that it's hard to link ASM code into your code (espacially classes), 'cause in the ASM part you don't know the this pointer, so it's hard to access class members and so on.
Re: OOP or no OOP
You can be "object oriented" using C (and even assembly.) Remember, the OOP is about the idea of objects, not necessarily the syntactic sugar defining them. Personally, I prefer C++, though I do not mind one bit using C and assembly for the initial bits of an OS. C++ indeed has quite a bit of support overhead. You can do an OS in Java (or some other language,) but the native architecture support must include, at its lowest level, some assembly and possibly C/C++.
I suggest you check out the JOS or SANOS. At the lowest level they're ASM/C, but after that it's all Java.
I suggest you check out the JOS or SANOS. At the lowest level they're ASM/C, but after that it's all Java.
Re: OOP or no OOP
Hey,
Finally the site is back.
OK I think I'm actually in favor of an OOP design (in c++). I'm not really sure about it yet. I have a very basic OS in C and I already made a more complex OS a year ago. I stopped with my first OS, because my code became unreadable and to cluttered (not really an non OOP problem, but a sign of my lack of documentation).
However I noticed that to make an OS you use a LOT of pointers to pointers to pointers etc. When you use classes you can do without some pointers to pointers but use member functions instead. An other pro of classes is that you can use overloading. I think that writing in C++ can help making your code be more readable. And I really love the idea behind OOP, and I love the ?"feeling"? of OOP code (I know this is a personal one).
The overhead of good written OOP isn't to bad, there are a number of sites wich demonstrate that OOP (C++) can produce code wich is faster than non OOP code (C), but not as fast as very good ASM though.
So I would say that using or node using OOP depends on your own taste, but I think that OOP code is more clean than non OOP (mainly because the main task of an OS is to handle data and data is the central thing in OOP)
That was my opinion,
MZZLS Lont
Finally the site is back.
OK I think I'm actually in favor of an OOP design (in c++). I'm not really sure about it yet. I have a very basic OS in C and I already made a more complex OS a year ago. I stopped with my first OS, because my code became unreadable and to cluttered (not really an non OOP problem, but a sign of my lack of documentation).
However I noticed that to make an OS you use a LOT of pointers to pointers to pointers etc. When you use classes you can do without some pointers to pointers but use member functions instead. An other pro of classes is that you can use overloading. I think that writing in C++ can help making your code be more readable. And I really love the idea behind OOP, and I love the ?"feeling"? of OOP code (I know this is a personal one).
The overhead of good written OOP isn't to bad, there are a number of sites wich demonstrate that OOP (C++) can produce code wich is faster than non OOP code (C), but not as fast as very good ASM though.
So I would say that using or node using OOP depends on your own taste, but I think that OOP code is more clean than non OOP (mainly because the main task of an OS is to handle data and data is the central thing in OOP)
That was my opinion,
MZZLS Lont
Re: OOP or no OOP
Personally, I'd almost use C++ just for namespaces.
But, at some point I realized that I was mimicing OO techniques in C, and it made more sense to just write it in C++. Yes, that's just syntactic sugar and can do most any of it in C, but sugar does make it nicer to code in.
I use stuff like function overloading, inheritance with virtual methods, etc. all the time.
As with anything in this subject, it's entirely a personal preference.
But, at some point I realized that I was mimicing OO techniques in C, and it made more sense to just write it in C++. Yes, that's just syntactic sugar and can do most any of it in C, but sugar does make it nicer to code in.
I use stuff like function overloading, inheritance with virtual methods, etc. all the time.
As with anything in this subject, it's entirely a personal preference.
Re: OOP or no OOP
I think doing OO stuff in C with #ifdefs for private class members etc. is a possible way, but you just reprogram what C++ would give you, and you choose a language to help you programming, or don't you?
On another hand, the overhead depends on what you use. If you don't use exceptions and rtti, you need far more less run time support, however this is already a cut in functionality.
To the overhead of the rest, using templates gives you more code, so your executeable will be bigger, and using virtual functions will use functions pointers in a table, give you a penalty when calling, but in general you would use pointers in C in that situation then, too.
Or do you have any other overhead? I guess not ...
On another hand, the overhead depends on what you use. If you don't use exceptions and rtti, you need far more less run time support, however this is already a cut in functionality.
To the overhead of the rest, using templates gives you more code, so your executeable will be bigger, and using virtual functions will use functions pointers in a table, give you a penalty when calling, but in general you would use pointers in C in that situation then, too.
Or do you have any other overhead? I guess not ...