To object or not to object...

Programming, for all ages and all languages.
dudeman
Posts: 21
Joined: Tue Jan 15, 2008 12:30 pm

To object or not to object...

Post by dudeman »

I've been programming in C/C++ for a few years now and I have only recently begun looking in to OS development. Following the advice of many here and some of the tutorials (which are primarily written in C) I'm beginning to wonder:

Is it ever completely neccessary to write something in C++ as opposed to the more procedural C?

The question hit me during my last school programming project where I was designing a Karnaugh-Map-Solver.

No matter how I structured my program, it became very clear that i didn't need to design any user-defined-objects to solve the maps. Simply using procedural methods and arrays was more than sufficient.

Prehaps the only REAL benefit to using objects is for the programmers and not the programs --meaning: it may be easier to organize parts of your program with classes, easier to read through lines of code that use classes, etc.

Am I missing the point of user-defined-objects?

My world has been completely turned on its head...
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

The point is to make bigger projects clearer and to be able to put logic away behind what it should look like for you.

Of course, some people invert the thought and hide the nice algorithms behind a horrible interface but the idea is sound.
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post by Tyler »

Any lesser featured language that is powerful enough, can achieve the same goal. I could use the assembly language of a stackless system, or at least one without a built in CALL function to build programs comparitable to C ones. I could work on the same programs to build equivelant functionality to C++ software, and even emulate the class concept through a series of control procedures. Most programming paradigms are designed for the benefit of the developer, whether it be for structure, speed or other reasons.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: To object or not to object...

Post by Alboin »

dudeman wrote:Is it ever completely neccessary to write something in C++ as opposed to the more procedural C?
I would suggest you look into how compilers work, and learn assembly. You'll realize that all languages produce, more or less, the same assembly code. (Not 'exactly' the same, but you get the idea.)

To note: Any language can do objects, even C. Albeit in C, they are either less intricate (ie. a struct and functions to manipulate the struct.) or large intricate frameworks. (eg. GTK)

...

Watch out for overzealous OOP! ;)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: To object or not to object...

Post by Solar »

dudeman wrote:
Prehaps the only REAL benefit to using objects is for the programmers and not the programs --meaning: it may be easier to organize parts of your program with classes, easier to read through lines of code that use classes, etc.

Am I missing the point of user-defined-objects?
No, you got it 100% right.
Every good solution is obvious once you've found it.
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

i would recommend c. :)
that is enough. oop in c is possible.

otherwise, if you involved in it industry, i recommend java or c# or mfc than c++. :)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Jesus, can we stop these language wars, please? It's getting really tiresome.

"OOP in C is possible." You can mimic OO in C, if you e.g. program your own virtual function pointers, remember to call your constructors manually, and rape the vararg mechanism into something resembling function overloading. C is not object-based, let alone object-oriented.

MFC isn't a language but a class library.

As to why C# and Java can't go everywhere C++ goes (and vice versa), see any of the hundreds other language flamefests on this board.

If you don't like C++, fine, don't use it. If you want to discuss shortcomings of the language, feel free to do so, although comp.lang.c++.moderated or a C++ committee member is probably a better place to take this.

But if all you have is an axe to grind or some time to kill, take a second and contemplate if not posting might make the world a better place.
Every good solution is obvious once you've found it.
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

Solar wrote: 1. "OOP in C is possible." You can mimic OO in C, if you e.g. program your own virtual function pointers, remember to call your constructors manually, and rape the vararg mechanism into something resembling function overloading. C is not object-based, let alone object-oriented.

2. MFC isn't a language but a class library.
sorry, both of them i disagree.

1. But c++ is written in c after all.

2. it is framework, not just another library.
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Post by Laksen »

As already said in the thread, it's never necessary to use OOP, but it depends on your preferences

I for one, enjoy OOP. I find it get's the job done faster and more elegantly for me. My kernel is now completely object oriented and will continue to be so
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post by Tyler »

binutils wrote:
Solar wrote: 1. "OOP in C is possible." You can mimic OO in C, if you e.g. program your own virtual function pointers, remember to call your constructors manually, and rape the vararg mechanism into something resembling function overloading. C is not object-based, let alone object-oriented.

2. MFC isn't a language but a class library.
sorry, both of them i disagree.

1. But c++ is written in c after all.

2. it is framework, not just another library.
Sorry, but your wrong on both.

1. Metal Gear Solid is written in C/C++, but i'd like to see you shoot virtual terrorists in it with a Playstation controller, without writing a single line of code to control the action.

2. Framework is just a name, it is a library of classes.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

1. But c++ is written in c after all.
C++ is not "written" in any language. It is a language itself. Perhaps what you meant to say was that "The GNU C++ compiler is written in C". Which would be correct, because G++ is a front end addon to the GNU compiler collection which, as you stated, is written in C. But there is no reason why g++ *can't* be written in c++, c.f. Javac is written in java (@see bootstrapping).

I'm not certain what language the microsoft c++ compiler is written in - it could possibly be c++.
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

Tyler wrote:
binutils wrote:
Solar wrote: 1. "OOP in C is possible." You can mimic OO in C, if you e.g. program your own virtual function pointers, remember to call your constructors manually, and rape the vararg mechanism into something resembling function overloading. C is not object-based, let alone object-oriented.

2. MFC isn't a language but a class library.
sorry, both of them i disagree.

1. But c++ is written in c after all.

2. it is framework, not just another library.
Sorry, but your wrong on both.

1. Metal Gear Solid is written in C/C++, but i'd like to see you shoot virtual terrorists in it with a Playstation controller, without writing a single line of code to control the action.

2. Framework is just a name, it is a library of classes.
1. i don't know Metal Gear Solid, but it seems only available on ms windows or playstation1/2?

2. Perhaps
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

binutils wrote:
2. Perhaps
Pray, show me code written in MFC. Not C, C++, C# or anything using MFC, but the language MFC. (Which was the original point.) 8)
Every good solution is obvious once you've found it.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

Smalltalk FTW!

(This is now my default response to all language pissing contests.)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

No nononono... LISP it must be! :-D
Every good solution is obvious once you've found it.
Post Reply