Thread: Why C !

  1. #16
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Whether to use C or C++ is a pointless argument in that :

    C is more efficient than C++, but
    C++ offers Object-Oriented programming, C doesn't.

    To go from C to C++, you'll have to undergo a paradigm shift in order to 'fit in' C++ company.

    Programming in C is not the same as programming in C++.
    If you don't want to learn OOP, then stick to C, otherwise learn C++.

  2. #17
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    Posts
    140
    C was one of the first general-purpose high-level programming languages to gain almost universal use, and today you can program in C on almost any platform and machine. It was created by Denis Ritchie in 1971, as the successor to the "B" compiler, for UNIX systems.

    C++ allows programmers to leverage their knowledge of C with the use Object Oriented (OO) concepts, to create larger programs with easier and with better quality. Since C++ contains all of the concepts of C, a C program can be run using a C++ compiler...but only a C++ compiler can compile a C++ program. It was created by Bjarne Stroustrup in 1980.

  3. #18
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >>To go from C to C++, you'll have to undergo a paradigm shift in order to 'fit in' C++ company.

    i dont know waht paradigm means, but if u mean you have to go through alot of stuff, you dont
    most C Code will compile with a C++ compiler, there are just a few things you have to change, ie: typecasting
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Okiesmokie
    i dont know waht paradigm means, but if u mean you have to go through alot of stuff, you dont
    most C Code will compile with a C++ compiler, there are just a few things you have to change, ie: typecasting
    Basicly what they meant is:

    C is "procedural" programming. This bacicly means "line by line" or "thought by thought". Break it down into simple steps, or functions, that handle tasks.

    Really it means: break the problem into simple blocks that are executed one after another until the task is done.

    C++ is (trys to be) "Object Oriented".
    This means that you break things up into "Objects", and each "Object" contains all information for doing anything related to it.

    Code:
    class Car
    {
    public:
        SpeedUp( ) { engine.Accelerate( ); }
        SlowDown( ) { engine.Decelerate( ); }
        Crash( )
        {
            engine.GrindingHalt( );
            wheels.FallOff( );
            body.BendFrame( );
        }
    private:
        class Engine engine;
        class Wheels wheels;
        class Body body;
    };
    Then you do something like:

    Car mycar;
    mycar.SpeedUp( );
    mycar.SpeedUp( );
    mycar.SpeedUp( );
    mycar.SpeedUp( );
    mycar.Crash( );

    Where you'd do it differently in C++.

    Quzah.
    Last edited by quzah; 07-03-2002 at 08:33 PM.
    Hope is the first step on the road to disappointment.

  5. #20
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    Originally posted by dune911
    a C program can be run using a C++ compiler...but only a C++ compiler can compile a C++ program.
    There are valid C programs which are not valid C++ programs , typecasting a malloc is necessary in C++ not in C , character literals e.g., 'A' are of type int in C but are of type char in C++
    so sizeof('A') will always be 1 in C++ but it might not be true in C ,C is not a subset of C++

  6. #21
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    i dont know waht paradigm means,
    If I am correct, a paradigm is a way of thinking. C is a procedural language, desiging applications in such languages requires you to answer questions like:

    - what should the software do
    - how should the software do this
    - which functionality can be split up in sub-functionality

    In this way you create a lot of functions and sets of functions which perform the task.

    C++ is a hybrid language which enables you to do object oriented programming. Desiging object oriented applications requires you to answer questions like:

    - which objects do I have to deal with
    - which responsibilities do the objects have
    - how should the objects communicate

    In this way you create a lot of classes which result in objects which perform a certain piece of functionality.

    to create larger programs with easier and with better quality.
    Creating software with an object oriented language does not necessarily imply that this software has better quality and that it is easier to create.

    Object orientation has some advantages. Object oriented designs are easier to maintain, more flexible and reusable. The counts for the object oriented implementations.

    But on the other hand, procedural designs, when done well, can also be reusable, just like their implementations. But usually such designs are harder to maintain and less flexible.

    In my designs, I always use object oriented principles. But this does not mean that the language is a so called OOP-language. Currently I'm working on a project which is designed using object oriented principles, but the language is C.

  7. #22
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    Posts
    140
    If you can, I would learn C before learning C++. That way you will fully grasp the benefits of a language with built in Object Oriented Programming (OOP). Some people still haven’t made the switch from C to C++ so it’s always a good idea to have that knowledge in your back pocket in case you have to use C.

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by dune911
    If you can, I would learn C before learning C++. That way you will fully grasp the benefits of a language with built in Object Oriented Programming (OOP). Some people still haven’t made the switch from C to C++ so it’s always a good idea to have that knowledge in your back pocket in case you have to use C.
    No. Actually this isn't necessarily a good idea. It depends on your goal. In theory, knowing C++ could give you a perfect understanding of C also.

    The difference is what the focus of the learning/teaching is. If you want to learn Object Oriented programming, go with C++.

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #24
    Registered User
    Join Date
    Jul 2002
    Posts
    3
    because the linux kernel was written with it. when it goes to c++, then i'll use that.

  10. #25
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I would like to get a hold of a book that teaches you how to write OOP programs in C. I know that a file can be used to gather data and behavior (functions) together just like a class does. Certainly pointers to functions can exist as structure members.

    The problem with OOP is that there are many rules that you should be aware of called Heuristics, when designing an OOP program. I think that it takes much longer to gain C++ proficiency, and that learning the language syntax as well as basics OOP principals in definately not enough.

    I learned C first and I am not dissapointed. In some ways C is manditory even for the purpose of reading low level software architecture code such as the operating systems. They are all written in C.

  11. #26
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Can someone post some C code that cannot be implemented to run as fast in C++?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  12. #27
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >If you can, I would learn C before learning C++.

    Note that a C program is a C++ program. But if you want to learn C++, I would recommend to learn C++ only and not C. This is because the way of thinking. A lot of C programmers who go programming in C++, apply C-techniques within C++ and therefore don't use the full power of C++. Which is object orientation. Programmers who learnt C, learnt to program in a procedural way and that's very different from the object oriented way.

    A book on object oriented programming in C.

    www.planetpdf.com/codecuts/pdfs/ooc.pdf

    >Certainly pointers to functions can exist as structure members.

    That's correct, but there are more ways to implement object oriented designs in C. Also a very useful method is using a file as a "class".

    >The problem with OOP is that there are many rules that you >should be aware of called Heuristics, when designing an OOP >program.

    Also for good procedural design there are many rules to be aware of. Just think of reusability of modules.

  13. #28
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Originally posted by Shiro
    A book on object oriented programming in C.

    www.planetpdf.com/codecuts/pdfs/ooc.pdf

    >Certainly pointers to functions can exist as structure members.

    That's correct, but there are more ways to implement object oriented designs in C. Also a very useful method is using a file as a "class".
    Thanks for the link. Sure I read that files can be used as a class. I mentioned it above. I read it in a book by Arthur J. Riel. I can't say that I have used this style yet myself, however I believe that I will from now on.

    As far as providing some C code that cannot be implimented to run as fast in C++, there probably isn't any. A couple of the problems OOP programmers in general run into is a proliferation of classes, or else having a God class that does to much. A better OOP program will decentralize responsibilities and only use classes that apply to the domain. The speed of things like the STL was measured very carefully so that it was near or on even ground with C. They would never submit a design for the STL if it did not meet strict testing requirements. I think that the largest danger to an OOP programmer is not to be aware of OOP heuristics, and sure the same applies for procedural programming or any project that is ill planned. What you will hear about most is unfair comparisons or imaginary ones.

  14. #29
    Registered User
    Join Date
    Jul 2002
    Posts
    45

    Wink

    yes......... c is the beutifull language in the world.........i just love c..

  15. #30
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >I can't say that I have used this style yet myself, however I
    >believe that I will from now on.

    Why would you use C to do object oriented programming?

    When implementing an OO design in a non-OO language, you'll have to program a lot of things which an OO language would do for you. So there's a lot of overhead and I wonder if, but I never checked that, implementing an OO design in a non-OO language is as fast and efficient as implemented in an OO language.

    C++ has a lot of constructions which make implementing OO-designs easier, more efficient and safer then implementing such design in C.

Popular pages Recent additions subscribe to a feed