Should I learn C++?
Should I learn C++?
I have been using C as my language for a while now and I have been considering learning C++ for its features and for my future kernel.For all C programmers who use C++ now does it help having object oriented programming apposed to procedural programming for projects like OS development?
Thanks in advanced for answering.
Thanks in advanced for answering.
I have been working on this program of mine, which I have been treating as if it was my child, and it was in C. I was using hashes, linked lists, and several other abstraction features. (Even to the point of slightly abstracting GTK. ) However, I got to the point where it became unbearable. There were void * everywhere and the thing was simply unstable. I spent two weeks searching it for this horrid bug that continues to crash the C version. I have since switched it to C++, and have begun rewriting some of the things using generic programming and a tiny bit of OOP. (Don't want to go over.) So far, it's just pleasant. Templates are just...a dream. Moreover, classes are probably the cleanest form of abstraction known to gold fish.
I still feel bad about using C++ and not C. I don't know why. I figure, C++ works better for my project, so I'm going to use it. That's all it really comes down to after all. I think it's that bloody mantra that 'cool' programmers only use C. Blah! I can barely shake it!
I highly suggest you learn C++ for the ideas you pick up from it. (Although don't over do it with the OOP-ness.)
I still feel bad about using C++ and not C. I don't know why. I figure, C++ works better for my project, so I'm going to use it. That's all it really comes down to after all. I think it's that bloody mantra that 'cool' programmers only use C. Blah! I can barely shake it!
I highly suggest you learn C++ for the ideas you pick up from it. (Although don't over do it with the OOP-ness.)
C8H10N4O2 | #446691 | Trust the nodes.
It's not so much the language as the way of thinking you really need. The language is only a tool that allows you to express your way of thinking. I would recommend everybody to learn imperative programming, object-oriented programming and functional programming, at the least.
I just like C++ a bit since all three are in it. It embodies C in full (for imperative programming), embodies object-oriented programming using classes, inheritance and so forth, and it implements functional programming in templates. Template metaprogramming is a form of functional programming.
I just like C++ a bit since all three are in it. It embodies C in full (for imperative programming), embodies object-oriented programming using classes, inheritance and so forth, and it implements functional programming in templates. Template metaprogramming is a form of functional programming.
I prefer using C++ in my kernel. There is just something about having a base class CDrive and being able to derive CFloppy and CHard_Drive from it and calling the right functions from a CDrive pointer. I like that classes really enclose all of the data that is needed for that class. I always hated passing around a pointer to a struct containing all of the data that a function needed.
If you prefer using C++ to C then you should write your kernel in C++.
If you prefer using C++ to C then you should write your kernel in C++.
I love most of C++....I of course, love the C part, and I love the way you can abstract by using classes and a "this" pointer is used so you don't have to worry about sending the actual class..
The thing I don't like is templates, I think it encourages code bloat, but that's just my opinion though..
Also, I like to avoid inheritance due to the virtual function overhead, though I don't think it's too much overhead, so just with anything speed-critical, I won't sue it..(but other times, I will...but make sure not to over do it!)
If I could get past the framework of a C++ kernel, I'd love to make one....but I just can't really make a malloc and such so early...I have to setup a lot of other things first, like GDT and IDT...(plus, due to my ideas, I have to write my own bootsector, which I am only 75% done with so far..)
The thing I don't like is templates, I think it encourages code bloat, but that's just my opinion though..
Also, I like to avoid inheritance due to the virtual function overhead, though I don't think it's too much overhead, so just with anything speed-critical, I won't sue it..(but other times, I will...but make sure not to over do it!)
If I could get past the framework of a C++ kernel, I'd love to make one....but I just can't really make a malloc and such so early...I have to setup a lot of other things first, like GDT and IDT...(plus, due to my ideas, I have to write my own bootsector, which I am only 75% done with so far..)
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Using C++ for kernel-land programming is not for the faint hearted. If you do not know C++ now, don't bother learning it for the sole purpose of OS development. You need to know the language inside out or it will come back to haunt you. The same holds for any other language you may want to try. (I will not ever push anybody to do OS development with Basic for the same reason)
Feel free to experiment with it, though. Learning a new language brings a greater understanding anyway.
If you haven't previously done OOP at all, you might want to consider Java as well.
And those are my $.02
Feel free to experiment with it, though. Learning a new language brings a greater understanding anyway.
If you haven't previously done OOP at all, you might want to consider Java as well.
And those are my $.02
I know almost nothing about OS development, but quite a bit, IMHO, about C++. But I would imagine that you could always mix (???) the two if you wanted (correct me if I'm wrong please!), Meaning that for a complex ADT you could use C++ and for lower architecture kind of stuff (I don't really know what I'm talking about) you could use C and assembly, i think. I just recently worked on a school project where we had to create a kind of file-system (the OOP side of it where it was set up like a tree and we also used stacks to keep track of different things) and I couldn't imagine writing that in plain old C. I guess wherever you need to design a complex linkable structure C++ would be much easier.
effective c++ 3rd Edition
I myself try to learn how to use c and c++ in same project.
http://kerneltrap.org/node/2067
http://www.boost.org/
I myself try to learn how to use c and c++ in same project.
http://kerneltrap.org/node/2067
http://en.wikipedia.org/wiki/C++0xLinus wrote:"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA."
http://www.boost.org/
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
I remember reading Linus' post about C++ in Linux. As usual, it's full of hyperbole and over-generalizations. I think I would summarize his argument as "it's a stupid idea to try and use C++ in Linux because it's already written in C and is so large that the cost of introducing C++ into the kernel far outweighs the benefits." If that's what he actually meant, then I agree with him, but I don't think he made the case that C++ in any kernel is a bad idea.eboyd wrote:interesting quote binutils. i'm wondering if linus said that because in 92 processors weren't quite what they are today and couldn't handle the overhead? wonder if he'd reconsider now?
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
srry, i hadn't read the link to the linus quote.
i guess i can't agree or disagree with what linus said. i'm not sure what makes c++ compilers untrustworthy. i've never dealt with exception handling in plain c (but c++ exception handling has always worked for me) and as far as writing OOP code in c somehow being better than in c++ seems
a little counter-intuitive to me.
but then again i didn't invent linux and i know c++ better than i know c, meaning i've done much OOP and designed ADTs in c++ and not c.
off topic but is exception handling any different in c as opposed to c++?
i guess i can't agree or disagree with what linus said. i'm not sure what makes c++ compilers untrustworthy. i've never dealt with exception handling in plain c (but c++ exception handling has always worked for me) and as far as writing OOP code in c somehow being better than in c++ seems
a little counter-intuitive to me.
but then again i didn't invent linux and i know c++ better than i know c, meaning i've done much OOP and designed ADTs in c++ and not c.
off topic but is exception handling any different in c as opposed to c++?
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
I remember his quote (which should and may be one of many) which he specifically stated the primary reason for not using C++ is that you will end up writing in C.I think I would summarize his argument as "it's a stupid idea to try and use C++ in Linux because it's already written in C and is so large that the cost of introducing C++ into the kernel far outweighs the benefits."
Take for instance the structure of drivers in Linux, where they are actually just a class. I mean each driver in Linux is really a model of a class in C++ with member functions. Yet they are written in C instead of C++.
I imagine there is definitely some where you could use one or more syntax sugars of C++ to make working with a mechanism in the kernel more comfortable, but still like he stated in the quote I read the main reason is no matter what you do you are still writing in C essentially.
So I guess he figures it is not fruitful enough to use the syntactic sugar C++ provides inside the kernel or drivers?
Well, we have narrowed it down to:
- it's already written in C and is so large that the cost of introducing C++ into the kernel far outweighs the benefits.
- there is not a big reason to use C++ and any borderline issue could be implemented in C just as easy.