PDA

View Full Version : C vrs OOP



Yarin
08-13-2007, 12:25 PM
Maxorators sig cought my eye...


C: EatThis(pointer); OOP: pointer->EatThis(); Revolutional.... NOT.


I have noticed that while most people make classes with functions built in to handle stuff. I usually do it the C way, use a struct, and pass it's pointer to seperate handling functions, much like window handles work. Is this like a bad thing to so or somthing, why did the thing about putting handling functions in classes ever become 'standard'?

indigo0086
08-13-2007, 12:56 PM
I think he meant "Revolutional...NOT a word".

And I think it's just two different ways of looking at it. C comes from the idea that you have functions that control the data, while OOP has the data controlling itself, providing an interface to others on how it should be used.

maxorator
08-13-2007, 01:04 PM
I think people like classes because then everything is declared in one place (inside the class element) and that the definitions of those functions have the ClassName:: in front of them. That way people can easily see what is what. Classes do have some special features but all of them can be done without classes by using some creativity. What I wanted to say was not that classes are bad or anything, I just wanted to say they're not so much different from the ordinary C-style and OOP should not be worshipped as it was something revolutional. It's just an alternative way with some extra features.

indigo0086
08-13-2007, 01:07 PM
I use openGL and have to use both ways, while the C style stuff is ususally bound to the OpenGL specific stuff, I put everything that uses the openGL in classes, seperating them by what they do, and encapsulating it as such. I think when using a library such as that which has no object oriented point of view, and a lot of the declaring handlers, pointers, and modifying them using functions, I find it a lot easier to use by creating objects.

maxorator
08-13-2007, 01:10 PM
I use openGL and have to use both ways, while the C style stuff is ususally bound to the OpenGL specific stuff, I put everything that uses the openGL in classes, seperating them by what they do, and encapsulating it as such. I think when using a library such as that which has no object oriented point of view, and a lot of the declaring handlers, pointers, and modifying them using functions, I find it a lot easier to use by creating objects.
Exactly my point. When C-style seems to get too messed up to understand anything, you can use classes. And it isn't bad to do it C-style - it's about how you like it. :)

Indigo0086, you just made your 1000th post!

prog-bman
08-13-2007, 01:29 PM
There is so much more to classes than just hiding the implementation.

What about inheritance, virtual functions, etc. Now these things used in excess are not needed, but in my experience these things are very useful.

maxorator
08-13-2007, 01:37 PM
Derived classes indeed simplify things, but there is also a C alternative - include the other struct in the new struct. So there is nothing you can't do in C, just that in C it does not look so straight-forward.

JaWiB
08-13-2007, 03:33 PM
It sounds more like you're comparing C and C++ than comparing C programming with object oriented programming (which seem to me like apples and oranges).

>Derived classes indeed simplify things, but there is also a C alternative - include the other struct in the new struct.

Yes, so you'd be implementing an aspect of OO--just in an ugly way. So what's your point? Obviously you can use OOP concepts in C, but you say it doesn't provide an advantage.

QuestionC
08-13-2007, 03:54 PM
C++ is a bad framework for OOP discussions. If you want to discuss the merits of OO and whether it is a 'revolution', consider the task of taking a Java Application into an Applet, and consider how hard that would be to do without Java's run-time polymorphism facilities.

More importantly, the distinguishing (imo) features of C++ really don't have anything to do with OO. The following is a paper written by Bjarne Strostrup entitled "Why C++ is not just an Object-Oriented Language"
http://www.research.att.com/~bs/oopsla.pdf

laserlight
08-13-2007, 08:46 PM
Actually, maxorator's signature is just referring to syntactic sugar. That, of course, is very much language dependent and not revolutionary at all (though it may make things more fun/easy/messy/silly etc).

CrazyNorman
08-13-2007, 09:08 PM
I'd argue that saying OOP in C++ isn't a huge step over emulation of it in C using structs, functions, structs within structs (it will really start to get to be a big pain and mess with a large project), is like saying that C isn't a revolution over ASM, because all the nice constructs can be implemented with memory offsets, along with JMPs and CMPs.

Of course you can implement one paradigm inside another, after all, it all boils down to some hex, but a concept makes a difference when the average programmer can take advantage of it

robwhit
08-13-2007, 09:28 PM
The advantage of C compared to asm is portability. C++ compared to C doesn't have that advantage.

C is kind of like a portable ASM.

maxorator
08-13-2007, 11:40 PM
OOP doesn't make the developing much faster, it makes it look clearer. Big and complex systems have been programmed in C. All the ways of handling data like classes do were used long before classes were invented.

Assembly isn't actually a programming language. It's human-readable machine code.

jwenting
08-14-2007, 02:39 AM
OOP can make development faster, depending on the proficiency of the people using it and the type of system under development.
Same with any other paradigm, if used in the wrong context by people lacking understanding of the context and/or the paradigm you're asking for trouble.

Sadly many people diving into OOP have no idea what they're getting into nor do they have any idea about the problem domain they're writing software against.

C seems more productive therefore because it's less used by inexperienced people with little knowledge about their problem domain, simply because it's not a language that (these days) is taught to inexperienced programmers.

matsp
08-14-2007, 07:39 AM
Assembly isn't actually a programming language. It's human-readable machine code.

And of course other languages aren't? There is only one thing the processor(s) can execute: Machine code. Anything else has to be translated first. Whether you translate it DIRECTLY from assembler, macro assembler, C, Pascal, Fortran, Cobol, ADA or whatever is irrelevant - they are all "computer languages" - just more or less directly translated from what the programmer wrote to machine-code (and not ALWAYS obviously so, compilers sometimes produce not-so-obvious code). [Of course, there are languages like Java that is commonly translated to a pseudo-machine-code - but that's just a way to "commonalize" the compiler so that code can be compiled but not be machine/architecture dependant - and then translate the pseudu-machine-code to native code either by interpretation or some form of "compilation"].

By the way, I can pretty much predict the output of GCC or MS VC for a piece of C-code - I'm not always 100% spot on, but most of the time I get it very close to the actual output of the compiler.

Of course, assembler isn't particularly portable from one processor (macro-)architecture to another, but that doesn't make it less of a language ;-)

--
Mats

CrazyNorman
08-14-2007, 07:42 AM
Sorry, I knew that C has portability over ASM, but even if there was an assembly type language, with universal opcodes such as JMP and CMP, and some sort of portable memory model, etc., I'd say that C would be a large step up over the "OPERATOR operand, operand" format, despite the fact that anything implementable in C would be implementable in said language.

I do remember there being a portable ASM, called Linoleum, but I have yet to examine it.

matsp
08-14-2007, 07:54 AM
Sure, I'll write code in C unless it's impossible (such as context switch code or using instructions that can't be generated by the compiler for some reason - e.g. VMRUN instruction for Xen in "entry.S" - which was the last time I did some major assembler work).

But it still doesn't mean that assembler isn't a language.

The whole idea of a higher level language is of course that you can express things in a more abstrac way: a = (b + c) * (d - e) is much easier way than doing the same in assembly code, for sure. I'm not arguing against that. And in some languages, that may also mean that you take a bunch of arrays and do the corresponding math on it.

--
Mats

QuestionC
08-14-2007, 08:09 AM
C is not just high level assembly. C introduces some high-level concepts foreign to assembly such as scope and structured control flow. I believe we just take it for granted because this stuff was all 'invented' over 20 years ago (computing antiquity!).

QuestionC
08-14-2007, 09:07 AM
The following paper gives, IMO, a pretty good glimpse at how different 'thinking in C' is from how people were thinking beforehand.
http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf

matsp
08-14-2007, 09:18 AM
It was not my intention to say "C is a giant Macro Assembler", but rather to say that anything that translates from human readable "language" into machine code IS a language.

Language constructs such as "struct", "union", "while", "for", "do - while" and "switch" are very useful to describe what you want done in an easy to understand way (to other readers - or oneself later on). Of course, if all of those keywords are necessary to qualify asa language, then none of Cobol, Fortran or Lisp would qualify as "languages" (in it their traditional shape - more recent versions may even support "Object Orientation" - although I, too, agree that object orientation and languages are two separate subject, although some languages are better at implicitly supporting object orientation than others) .

--
Mats

DavidP
08-14-2007, 09:58 AM
I don't want to spoil the thread or anything, but shouldn't it be "Revolutionary" and not "Revolutional"? I don't think "Revolutional" is even a word.

BMJ
08-14-2007, 11:40 AM
It never ceases to amaze me how ostentatious nerds can be about mundane things.

QuestionC
08-14-2007, 01:50 PM
It never ceases to amaze me how ostentatious nerds can be about mundane things.

Ahhh, crapping all over native tongue... can't take it....

VirtualAce
08-16-2007, 12:58 AM
I can't believe we are arguing about C and C++. And, no, revolutional is not a word.

Mario F.
08-16-2007, 07:00 AM
It's not C over C++ now. I think it's OOP over non-OOP... but then and again I may be wrong. Maxorator entertains me so much I forget to listen.

indigo0086
08-16-2007, 07:11 AM
I lika de OOP.

brewbuck
08-16-2007, 11:13 AM
OOP is MUCH more than simply syntax. The C++ version:



object->do_it();


And the C version:



do_it(object);


Can BOTH be viewed as "object oriented." C++ just uses a different syntax which makes it more apparent that the object is the important concept. C focuses on the function, not the object.

Pointing to the method call syntax as the most salient difference between C and C++ misses the point entirely.

The real advantage of C++ is the ability to easily derive from classes to create new classes. You can do this in C, but you have to do it manually. Also, you can easily implement polymorphic classes using virtual functions. Again, in C you can do it, but you have to do it manually. Further, C++ supports templates, which in MY opinion are the most valuable piece of the entire language.

Templates, inheritance, polymorphism, and exceptions work together to give you a language that simply WORKS DIFFERENTLY that C. It encourages a different way of thinking about the problems.

simpleid
08-17-2007, 12:36 PM
*erased*

brewbuck said it well enough. :-)


It encourages a different way of thinking about the problems.

Rashakil Fol
08-17-2007, 12:40 PM
Object oriented programming (don't know why people here are capitalizing it the way the Bible capitalizes The Lord) is wonderful if all you've been exposed to beforehand is C or Pascal.

simpleid
08-17-2007, 12:43 PM
Object oriented programming (don't know why people here are capitalizing it the way the Bible capitalizes The Lord) is wonderful if all you've been exposed to beforehand is C or Pascal.


OOP isn't any different in concept based on your exposure to languages, and your connection of an acronym to religion is absurd...

Mad_guy
08-17-2007, 04:45 PM
OOP isn't any different in concept based on your exposure to languages
He didn't say it was 'different in concept,' he just said it's something nice if all you've had before is something like C or pascal.

maxorator
08-20-2007, 04:05 AM
And of course other languages aren't? There is only one thing the processor(s) can execute: Machine code. Anything else has to be translated first. Whether you translate it DIRECTLY from assembler, macro assembler, C, Pascal, Fortran, Cobol, ADA or whatever is irrelevant - they are all "computer languages" - just more or less directly translated from what the programmer wrote to machine-code (and not ALWAYS obviously so, compilers sometimes produce not-so-obvious code).
Programming language means features. Assembly doesn't have features - it does exactly what you tell it to do and nothing more nor less. You write one instruction - it is one machine code instruction after linking. Assembly is a human-readable form of machine code with no modifications (only storing used registers on the stack). It changes with the processors, it can't be developed as a language. Macros and other "features" sometimes used in Assembly code are totally assembler-specific stuff, not part of assembly.

Assembly can't be compared as a language. It is not portable because it is basically machine code, which is different for most devices.

Object oriented programming (don't know why people here are capitalizing it the way the Bible capitalizes The Lord) is wonderful if all you've been exposed to beforehand is C or Pascal.
It's the same thing what we've done in C, just looks a little different.

Can BOTH be viewed as "object oriented." C++ just uses a different syntax which makes it more apparent that the object is the important concept. C focuses on the function, not the object.
What you think is important IS important. People rely too much on the syntax.

It's not C over C++ now. I think it's OOP over non-OOP... but then and again I may be wrong. Maxorator entertains me so much I forget to listen.
You got that right. :D

I never wanted to say anything is better. My point is that OOP is not The God, it's just a form of syntax. If you like the syntax, go ahead, use it. But worshipping it is just silly. It is just another form of syntax like any other. The only thing that really matters is the programmer (of course I like to remind once in a while that performance of the program is important too), other things affect very slightly. Code is not better or worse depending on the language's syntax. Programmer is not better or worse depending on the syntax of the language (s)he uses mostly.

Have fun. :)

indigo0086
08-20-2007, 06:13 AM
before you said so, no one was claiming it was "The God", no one important that is. Not even Bjarn Says so. Though he does find it an improvement on some of the antiquated constructs of C.

Also getting upset because someone capitalizes it is ridiculous.

maxorator
08-20-2007, 08:15 AM
I just noticed that the concept of OOP is frequently considered too important. It isn't. Programmers are important. The syntax doesn't really matter.

Mario F.
08-20-2007, 08:38 AM
OOP is not a syntax. It's a programming paradigm (http://en.wikipedia.org/wiki/Object-oriented_programming and http://en.wikipedia.org/wiki/Programming_paradigm)

As a concept it is responsible for major changes in the industry and one of the key players of most of what you use today as far as software is concerned. The problem with OOP is that those you criticize are those who tend to bring religion into these things.

The fact is that OOP doesn't need champions of the cause. It speaks for itself when used on those situations where it makes sense to use and it has nothing to say to its detractors either, because it doesn't pretend to be the solution to Life the Universe and Everything.

indigo0086
08-20-2007, 08:52 AM
I always learned OOP as more than just syntax.

brewbuck
08-20-2007, 11:21 AM
What you think is important IS important. People rely too much on the syntax.

How can a person "rely on a syntax?"

simpleid
08-21-2007, 07:42 AM
lol, rely on syntax, that would be every programming language in existence... even assembly. technically, in the most fundamental meaning of the term, even machine language probably could be said to have syntax.

http://en.wikipedia.org/wiki/Syntax

we do rely on syntax, but saying we rely too much on the syntax is like saying, "you worry too much about grammar."
yea well you sort of have to in -any- context to communicate anything in understandable terms.

MacNilly
08-22-2007, 04:41 PM
OOP has many advantages over Procedural Programming.

Some keys to OOP programming design:

1) Encapsulation. (Private members)
2) Inheritance. (Derived classes)
3) Polymorphism. (Virtual functions)

These 3 things allow programmers to write code that is easier to understand and maintain and also modify by adding new features on top of what already exists.

Procedural programming has gone by the wayside these days, because it has been shown to lead to hard to understand, unmaintainable, and unmodifiable code.

That's what they tell me, anyways.

Specifically, C++ has a lot of great features such as the powerful STL and templates, while still allowing low level things like pointers and other things from C.

Personally, I think C++ is the best OOP language because of these reasons. I did some Java, but I didn't care for the increased class overhead and the lack of pointers (I am too used to straight C/C++). The problem with Java is you HAVE to make a class for EVERYTHING. Annoying, IMO. OTOH, Java has a GREAT built-in GUI (swing/awt) and toolkits for just about anything you'd ever want to do.

For testing algorithms and data structures, I like straight C w/o the class overhead. It's gonna be fast, simple, and reliable, w/o dealing with OOP syntax problems that will occur. Then, once my base code is tested, I can easily move that code directly into a class framework with some accessor functions and I gain the advantages of an OOP designed program.

MacNilly
08-22-2007, 05:03 PM
I just wanted to say they're not so much different from the ordinary C-style and OOP should not be worshipped as it was something revolutional. It's just an alternative way with some extra features.

Hmm, I'm going to have to strongly disagree with this.

First, OOP and "C-Style" (Procedural programming) are quite different. While OOP should not be worshipped (nothing should be worshipped. imo), it definately WAS something revolutionary when it was introduced, because it solved MANY problems that programmers were facing with large code bases back in the day.


It's just an alternative way with some extra features

In a way, yes. We could also say the same about C to some assembler language. Can anyone say that C was not a revolutionary step from assembly?

MacNilly
08-22-2007, 05:11 PM
The advantage of C compared to asm is portability. C++ compared to C doesn't have that advantage.

No, there is more than one advantage here. Portability is not "THE" advantage. Some other advantages include: production time, maintainability, and maintenance costs. Also, C is only portable only if some C compiler has been written in assembly on the base architecture.

MacNilly
08-22-2007, 05:14 PM
OOP doesn't make the developing much faster, it makes it look clearer. Big and complex systems have been programmed in C. All the ways of handling data like classes do were used long before classes were invented.

Assembly isn't actually a programming language. It's human-readable machine code.

Machine code is human readable. You just have to know HEX like the back of your hand and have a big reference manual next to you. :p

Yes, assembly IS a programming language. It has it's own syntax wherein one symbol means one thing, and another symbol means another thing, ect.. How is that any different than any other programming language?

MacNilly
08-22-2007, 05:20 PM
Templates, inheritance, polymorphism, and exceptions work together to give you a language that simply WORKS DIFFERENTLY that C. It encourages a different way of thinking about the problems.

I agree 100%. I posted some things above, but completely forgot about exceptions. Those and templates are awesome and powerful programming tools.

robwhit
08-22-2007, 05:36 PM
No, there is more than one advantage here. Portability is not "THE" advantage. Some other advantages include: production time, maintainability, and maintenance costs. Also, C is only portable only if some C compiler has been written in assembly on the base architecture.I agree with you on that.

CornedBee
08-22-2007, 06:30 PM
I disagree, but only with the last point. There is no need to write a C compiler in assembly for every architecture. Once you have a C compiler written in C for an architecture A and it runs there, you can write a code generator for another architecture B, still in C, and run it on architecture A to compile the compiler and code generator so that they run on architecture B. Voila, you have just used a cross-compiler to bootstrap the B architecture, without a bit of assembly.

maxorator
08-23-2007, 04:07 AM
lol, rely on syntax, that would be every programming language in existence... even assembly. technically, in the most fundamental meaning of the term, even machine language probably could be said to have syntax.

http://en.wikipedia.org/wiki/Syntax

we do rely on syntax, but saying we rely too much on the syntax is like saying, "you worry too much about grammar."
yea well you sort of have to in -any- context to communicate anything in understandable terms.
Stop quibbling.

And of course I have dealed with OOP and used most of those features. You don't expect everyone to fall in love with OOP once (s)he has used it, do you?

An example: when you tell a C++ programmer that he must do something in C then he may be like "Oh my god what am I going to do now!?" - that's relying on a syntax (or a paradigm, as you say). Just an example - can be related to any programming language. BUT, a real programmer can program in any syntax/paradigm that (s)he is given, as long as it has no restrictions.

And that has been the whole point - procedural and object-oriented are different, but neither of them is better. It's like which one is better - apple or pear?

indigo0086
08-23-2007, 07:30 AM
This thread is disturbing my sleep.

maxorator
08-23-2007, 09:18 AM
Yeah, let's LOCK it. :)

indigo0086
08-23-2007, 09:28 AM
I had a horrible joke about child, fork, etc.

CornedBee
08-23-2007, 09:46 AM
If I weren't a moderator, I'd ask if I could join you.

As it is, I'm afraid I must terminate this.