Thread: C or C++ ?

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    20

    C or C++ ?

    C Tutorial - Learn C - Cprogramming.com
    Learn C with our popular C tutorial, which will take you from the very basics of C all the way through sophisticated topics like binary trees and data structures. By the way, if you're on the fence about learning C or C++, I recommend going through the C++ tutorial instead as it is a more modern language.
    I was reading about XNU kernel which is written in C and C++, so I was wondering why not just C++ if it's more modern and efficient and object oriented, instead of both languages?

    I mean it's better to start with C if you want less foreclosures or you want to understand what's going on inside a machine in a better way ?

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Can you not learn both?

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    I believe the only valid reason anyone should start with C instead of C++ is due to the difference in complexity. C is quite simple, it uses only one paradigm( procedural programming ), and thus in my opinion can be easier to understand early on. That of course comes from a biased person, because I started with procedural programming in my high school( used an equivalent language to Pascal ), so it could be just as valid that someone who'd start working early with objects would find langs such as C++ and Java easier to grasp.

    But C++ has many paradigms incorporated into it: procedural, object-oriented and generic. Those could be more difficult to learn, but then again they may not...
    Devoted my life to programming...

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    C is unnecessary. It's too bad there are certain very high-profile people who refuse to let it go. Otherwise it'd be dead and buried by now.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by brewbuck View Post
    C is unnecessary. It's too bad there are certain very high-profile people who refuse to let it go. Otherwise it'd be dead and buried by now.
    It's still used because it's a lot nicer to say that as a vendor or project, you support all of C rather than a subset of C++. If, for example, Torvalds decided to migrate the kernel to C++ sans virtuals, exceptions, and what ever else, it would add a bit of pain to collaboration.

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    In most cases, you can rename a .C source file to .CPP, and compile a C program as a C++ program and it will compile and run just fine. So the main difference between C and C++ are which library functions you use, such as the STL (standard template library) for C++. When learning how to program, the complexity of the algorithm is more of an issue than whether you use C or C++.

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I will still wholeheartedly recommend learning C before C++. Learning C, you learn how algorithms really work because you go through them so mechanically. C++ is a much more complex language that can go from incredibly high-level to low-level within a single line. There's a lot going on and I think a lot of what makes C++ good would be lost.

    Then again, I think Elysia learned C++ first and they're amazing at programming so what do I know?

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by rcgldr
    In most cases, you can rename a .C source file to .CPP, and compile a C program as a C++ program and it will compile and run just fine.
    Funnily though, beginners who take the typical advice here to avoid casting the return value of malloc in C will find that their valid C programs are invalid as C++ programs

    Quote Originally Posted by rcgldr
    So the main difference between C and C++ are which library functions you use, such as the STL (standard template library) for C++.
    The difference in standard libraries is one that follows from a whole host of language differences that I consider closer to being "the main difference", e.g., RAII, native OOP support, templates.

    Quote Originally Posted by MutantJohn
    Learning C, you learn how algorithms really work because you go through them so mechanically.
    Algorithms need not be expressed in imperative form (though I'm really thinking of more thematically functional programming languages rather than C++), and if the student really did want to express algorithms with imperative programming, C++ supports a largely procedural programming style too.

    Quote Originally Posted by MutantJohn
    C++ is a much more complex language that can go from incredibly high-level to low-level within a single line. There's a lot going on and I think a lot of what makes C++ good would be lost.
    I would like to refer you back to Stroustrup's essay on Learning Standard C++ as a New Language (PDF). A beginner does not have to go about designing classes and writing templates; he or she can just start as a user of libraries that provide abstractions to help him or her along the path of learning how to solve problems by programming.
    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

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MutantJohn View Post
    Learning C, you learn how algorithms really work because you go through them so mechanically.
    That has nothing to do with C or C++. Algorithms are a subject unto itself. If you want to learn algorithms and data structures, then go learn them. You don't learn them by learning C. Algorithms and data structures are language independent. Plus algorithms also tend to be written in some sort of pseudo code, not C or any other language. Implementing algorithms can be done in the language of choice.

    The same is true for computer architecture. If you want to learn how a computer works, then go study a computer architecture course and assembly, not C.

    C++ is a much more complex language that can go from incredibly high-level to low-level within a single line. There's a lot going on and I think a lot of what makes C++ good would be lost.
    Why would that be? If I could send an email with a single line of code, I'd be extremely happy. I would be very unhappy if I had to write 1000+ lines of code to do it.

    Then again, I think Elysia learned C++ first and they're amazing at programming so what do I know?[/QUOTE]
    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.

  10. #10
    Registered User
    Join Date
    Feb 2016
    Posts
    20
    Quote Originally Posted by brewbuck View Post
    C is unnecessary. It's too bad there are certain very high-profile people who refuse to let it go. Otherwise it'd be dead and buried by now.
    very high-profile people you say ?
    it's possible but why do they refuse to let it go?
    you will have to rewrite many high-profile systems like OS kernels, web servers and even programming/scripting languages ..
    and if you do it and rewrite them in "new" "better" language called x, then by the time you finish, new language will be available and your x would turn to be "unnecessary" as well !!

  11. #11
    Registered User
    Join Date
    Feb 2016
    Posts
    20
    Quote Originally Posted by Elysia View Post
    Implementing algorithms can be done in the language of choice.
    really ? you need recursion for example to solve some problems algorithmically or solve in more efficient way.
    do all programming languages support that ?

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Just because you can't use recursion doesn't mean it can't be done. Yes, some languages can do it more efficiently than others, but that's not the point.
    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.

  13. #13
    Registered User
    Join Date
    Feb 2016
    Posts
    20
    Quote Originally Posted by Elysia View Post
    Just because you can't use recursion doesn't mean it can't be done. Yes, some languages can do it more efficiently than others, but that's not the point.
    how do you measure efficiency ? I'm not talking amount code but speed time those things.
    --linesOfCode = ++abstraction
    too much abstraction not good when you want to learn or when you make something sensitive / dangerous/very important !

    and like programming language, we also have special-purpose and general-purpose algorithms

    apart from efficiency, I think they're some algorithms you just can't implement in any language !

    what do you say about that ?

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by yvan View Post
    how do you measure efficiency ? I'm not talking amount code but speed time those things.
    --linesOfCode = ++abstraction
    too much abstraction not good when you want to learn or when you make something sensitive / dangerous/very important !
    Efficiency = the time it takes to run the algorithm.
    Abstraction is, again, not language specific. Any language can do abstraction. Any language can NOT do abstraction. A programmer is responsible for abstraction, not the language. The language provides the tools.
    Some languages do provide abstractions from the hardware automatically (e.g. garbage collection), but in most cases, they don't make it impossible to implement an algorithm.

    But my point has always been that if you want to learn algorithms, you shouldn't be learning a programming language. Most languages can implement most algorithms. Learn the algorithms you want to learn and then learn a specific language to implement that algorithm.
    You gain nothing by learning C first.
    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.

  15. #15
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by yvan
    you need recursion for example to solve some problems algorithmically
    Just because an algorithm is implemented with recursion does not mean your language of choice needs to support recursion. You can use an explicit stack to simulate the effects of recursion. Additionally, in algorithms that use "tail recursion" (calling the recursive procedure at the end of the procedure code itself) it could/should be rewritten as a loop, because nothing can happen until you reach the base case, and the stack of function calls unwinds. The only reason you see tail recursion is because it is simple to write.
    Last edited by whiteflags; 03-10-2016 at 01:43 PM.

Popular pages Recent additions subscribe to a feed