Thread: Is Visual Studio C or C++

  1. #31
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    I know that, I am just saying that for basic OO-like applications C can be good enough.

  2. #32
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    Because it abuses function pointers, which makes an extra indirection, creating overhead at runtime.
    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

  3. #33
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    I wouldn't, but I wouldn't call it OOP either, because it isn't.
    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.

    Quote Originally Posted by Elysia
    C++ does OOP natively, but C doesn't, and that's a fact. Let no one challenge it.
    Who challenged that fact?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #34
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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

  5. #35
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MTK View Post
    I know that, I am just saying that for basic OO-like applications C can be good enough.
    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.

    Quote Originally Posted by MK27 View Post
    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.
    Absolutely, and I sincerely agree.
    (Another reason I dislike Obj-C.)

    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.
    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.

    Quote Originally Posted by laserlight View Post
    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.
    I am thinking of:
    Code:
    struct blah
    {
        my_function_ptr Something;
    };
    Ie basic function calls through an OOP-way will even incur overhead, as opposed to C++.
    Naturally, the C++ virtual function do have an overhead.
    Virtual functions in C sounds like a pain.

    Who challenged that fact?
    No one, I just wanted to type it because it sounded cool
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #36
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    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.
    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

  7. #37
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your approach is better, yes, and C programming... fits the bill, doesn't it? Perhaps it should be called anti-OOP, like the anti-pattern of singletons of C++?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    Perhaps it should be called anti-OOP, like the anti-pattern of singletons of C++?
    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

  9. #39
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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'm not entirely sure what you said there, but I'm impressed nevertheless.

    I should mention that it's possible to implement "virtual functions" in C: you can define something like
    Code:
    typedef struct Thing {
        int (*handle_event)(Event *event);
        int (*connect_observer)(struct Thing thing);
        /* ... */
    
        enum type_t type;
        void *extra_data;
    } Thing;
    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.

    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.

  10. #40
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MK27 View Post
    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.
    Well, I'll just say this... There is a pattern known as Singleton. But some people argue that this pattern is bad, hence it's also nick-named Anti-pattern.
    I thought I would apply the same term to "OOP" in C. Anti-OOP.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    Well, I'll just say this... There is a pattern known as Singleton. But some people argue that this pattern is bad, hence it's also nick-named Anti-pattern.
    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 thought I would apply the same term to "OOP" in C. Anti-OOP.
    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 .

    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

  12. #42
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by bithub View Post
    None of those things increase productivity...

    Everytime anyone brings up the C vs C++ debate, I am always reminded of Linus' rant. It makes me smile every time I read it (and I'm a C++ programmer, so I'm not biased towards his side).
    OMFG I must read that post, as it starts with the magical phrase -

    Quote Originally Posted by Linus Torvalds
    *YOU* are full of bull.........
    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.
    Last edited by abachler; 09-14-2009 at 05:50 PM.

  13. #43
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by MK27 View Post
    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.


    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 .

    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...
    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."

  14. #44
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by abachler View Post
    OMFG I must read that post, as it starts with the magical phrase -
    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

  15. #45
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by IceDane View Post
    You seem to be suffering from a common misconception; that programming language features dictate what kind of code you write in it.
    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:
    Quote Originally Posted by IceDane
    I was hoping he'd at least have done his homework to an extent that his statements would be irrefutable
    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.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM