I know that, I am just saying that for basic OO-like applications C can be good enough.
I know that, I am just saying that for basic OO-like applications C can be good enough.
Knowing this will prevent the programmer from programming in a naive way. The fact that you CAN emulate OO in C does not necessarily make it a good idea, most of the time, since the "performance advantage" is actually to NOT use a generisized class/object system. I would say the best idea is to completely forget OOP exists when writing in C. The extent to which your code resembles it will then not be influenced by some hazy notion that it should, or whatever it is that you think you are emulating.
Vis, LT's comments about C++, I guess he is being honest ("you being a person who should be disabused on any idiotic notions as soon as possible"). Since C++ is somewhat glamourized (IMO) for various reasons (such as complexity, which in and of itself is meaningless, but potentially "impressive"), there probably are a disproportionate number of arrogant but talentless C++ programmers around, and that is bound to be irritating If you are an "arrogant but talentless" type (aka, a pompous windbag), C++ (that sparkling diamond of mystique and complexity) will be much more appealing than C (the low level work horse), so maybe that is why some C programmers develop a "prejudice" and do not suffer fools gladly.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
What is it? When I saw your point about function pointers, I thought that you might be talking about an implementation of virtual functions in C, but of course a C++ virtual function implementation would have the same kind of overhead.Originally Posted by Elysia
Who challenged that fact?Originally Posted by Elysia
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It is totally silly to do OOP just for the sake of doing OOP, and AFAICT most programmers would not, so it is sort of a silly thing to discuss (I could ride my horse backward, what are they advantages and disadvantages).
OOP was intended to make programming easier, and it does. That's all.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Basic OOP is certainly possible and might be good enough. But then again, it might not offer the true advantages of OOP-ness, because C wasn't designed for it.
Instead, I'd follow MK27's instead.
Absolutely, and I sincerely agree.
(Another reason I dislike Obj-C.)
Ah, but to be fair, there are a number of arrogant C coders too. I know there was one on the board, but I don't remember the exact username.Vis, LT's comments about C++, I guess he is being honest ("you being a person who should be disabused on any idiotic notions as soon as possible"). Since C++ is somewhat glamourized (IMO) for various reasons (such as complexity, which in and of itself is meaningless, but potentially "impressive"), there probably are a disproportionate number of arrogant but talentless C++ programmers around, and that is bound to be irritating If you are an "arrogant but talentless" type (aka, a pompous windbag), C++ (that sparkling diamond of mystique and complexity) will be much more appealing than C (the low level work horse), so maybe that is why some C programmers develop a "prejudice" and do not suffer fools gladly.
I am thinking of:
Ie basic function calls through an OOP-way will even incur overhead, as opposed to C++.Code:struct blah { my_function_ptr Something; };
Naturally, the C++ virtual function do have an overhead.
Virtual functions in C sounds like a pain.
No one, I just wanted to type it because it sounded coolWho challenged that fact?
For posterities sake, it makes more sense to have one function that returns a struct, and other different functions that will accept such a struct and process or act on it, than to have a struct with function pointers in it so you can use OO style notation or something.
In which case it's not really OOP, it's C programming. IMO it's also true in other languages as well, OO or not.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
In my ignorance, I sometimes wonder if C++ is even goal-oriented (GO)...or if success is better measured by how much of the vocabulary you can successfully apply in any given situation.
For example, having only a vague idea of what a singleton is, my sneaking suspicion that a "anti-pattern singleton" is bound to be something better accomplished in another way is probably wrong, and there is good reason and real need behind the development of this apparent abomination...unless of course it sprang into being in a forest of such beasts, in which case just having another one might as well be reason enough.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I'm not entirely sure what you said there, but I'm impressed nevertheless.For example, having only a vague idea of what a singleton is, my sneaking suspicion that a "anti-pattern singleton" is bound to be something better accomplished in another way is probably wrong, and there is good reason and real need behind the development of this apparent abomination...unless of course it sprang into being in a forest of such beasts, in which case just having another one might as well be reason enough.
I should mention that it's possible to implement "virtual functions" in C: you can define something like
and have "derived types" use different structures for extra_data; and to implement a virtual function, you could just replace the function pointers like handle_normal_events() to handle_specialized_events() instead. Delegating to "base-class" implementations of the function would be a little trickier; you'd have to save the previous pointer somewhere, perhaps in a list of function pointers if you wanted to get extreme.Code:typedef struct Thing { int (*handle_event)(Event *event); int (*connect_observer)(struct Thing thing); /* ... */ enum type_t type; void *extra_data; } Thing;
Whatever, I'm just talking about things which probably have no relevance to this thread whatsoever. I really should read the whole thread before replying to it . . . .
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
That's a relief. I suppose it is good to have many possibilities in a language, since you do not have to use them. I would just worry that at a certain point, things that are more or less intended to sandbox incompetence (like the singleton) force intelligent and responsible programmers to learn syntax and methods that do not really seem to have much point, except to sandbox the other programmers Which maybe that is the most intelligent and responsible thing to do.
In C, I think the approach is more to provide a moat with a short plank instead of a sandbox.
I'm not anti-OOP at all, BTW, altho it is a strange term IMO (IMO the whole concept of "programming paradigms" is sort of half-baked). I totally like objects and classes. When I'm doing perl stuff and it looks like something will be best done as a class, I get all excited .I thought I would apply the same term to "OOP" in C. Anti-OOP.
Just that is not like, every five lines, since the combination of hashes/arrays/references is usually sufficient, so it seems strange to me that objects would be considered so mind altering. Put another way, Java always looks like some kind of perverse joke*. Why not "struct oriented programming" or "hash oriented programming"?
If you are not alone in your admission to having a "graphically oriented mind", Elysia, perhaps one day we can look back and remember the days of "text oriented programming"
*but I have no doubt I could get into it with enthusiasm, despite or maybe because of this...
Last edited by MK27; 09-14-2009 at 04:53 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
OMFG I must read that post, as it starts with the magical phrase -
Having read it, I must say that I pretty much agree with him. C++ Purists do tend to produce 'unmaintainable crap'. A purist design requirement leads inevitably to poor design choices.Originally Posted by Linus Torvalds
Last edited by abachler; 09-14-2009 at 05:50 PM.
You seem to be suffering from a common misconception; that programming language features dictate what kind of code you write in it.
All the features that C++ has for facilitating OOP are just that - features for facilitating OO programming. OOP is a programming paradigm, not a term that describes the features of the language.
You can write OO C code, like shown above. In reality, you could even do so without structs(Which is C's only way to create 'custom objects'). You could, in reality, use a char buffer for everything and then simply write functions for accessing members of object, that handle taking data and aligning it so that it fits into the buffer. Point being, the term "OOP" is a certain way of designing your programs.
But I agree whole-heartedly - writing OO code in a language that has no native features to facilitate it is insane. I have been writing something in C on and off for a while now, and I am, among other things using structs with function pointers, to implement an event queue. It's gnarly, nasty code. Seriously. I'll also have to write a lot a code to queue up data between worker threads and the sender thread of my application, which C++ could easily do in using std::queue or possibly std:riority_queue, with some code for thread synchronization.
Regarding Linus Torvalds' rant - I really lost a lot of respect for him. I was hoping he'd at least have done his homework to an extent that his statements would be irrefutable, but man, he is just spewing ........ and calling people names. He really shouldn't act like that, as he's a somewhat public figure. I don't know about you guys, or anyone else, but I can't help but imagine torvalds himself as angry as the rant sounds, and it's just hilarious. An angry, fat swede, frothing at the mouth.
His arguments for performance are stupid - like Elysia pointed out, games aren't exactly programs where performance is irrelevant. If the performance difference was that huge, C++ wouldn't be used as much as it is being used. On top of that, I cannot possibly see how C++ could do anything but make development much, much easier. Tracking down bugs in complicated C code where the logic is disguised by micro-managing mundane things like string handling and the like(And yes, this really does happen. I do believe that most of my aforementioned program's source code is either directly or indirectly code that parses strings.)
Sounds like Torvalds is just a childish man, full of anger and frustration due to not being able to understand OOP.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
Hey did you know Linus is married to a seven time national judo champion? I can't decide what I am more jealous of here*.
It must be the forearms: like "hey, do you spend 12 hours a day touch typing, or are you just happy to see me?"
*plus of course it is not like poor Dmitry can do much about LT's foul mouth now, unless he wants a REAL beating.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
No, I think I was more trying to mock the (mis)conception. Altho from the looks of Java in particular, I think it probably does "dictate what kind of code you write".
I totally admire LT for standing up for what he believes in, and for telling the truth. Without people like that, who would C programmers have to look up to?
*YOU* (IceDane) are exactly like the Dmitry character in the sense that you make a bunch of assertions that sound like litergy -- you do not seem to think it is necessary to actually back anything up by analyzing specific statements and providing evidence for your claims.
For example:
yet you could not bother to provide a single example here, implying to the reader that that you are either 1) uneducated and ignorant, or 2) a liar.Originally Posted by IceDane
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge