Jump to content

C Or C++


Jamo
 Share

Recommended Posts

Hi,

I recently got interested in programming. I have earlier started with Python, but I learned just the basics. Now I got interested on C. Iv read some tutorials, and it seems to be quite simple language - at least all the basic stuff. However I was a bit concerned whether is c the best choice for me. I have also thought about learning java. Since Im interested on linux/ubuntu I think c/c++ might be good language for me to learn, ain't linux eventually based on it (which one)?

Whats the main difference of c and c++ which one you think that I should learn, if any.

Thanks in advance Jarmo

Link to comment
Share on other sites

Go here: http://learnproglang.couch.it/

If you're just beginning with programming you should definitely learn C, not C++. C++ is a terrible language for teaching or learning computer science.

The Linux kernel and most of the core userland utilities are written in C.

C++ is often described as an extension of C, but in reality it's more like a ground-up rewrite with a similar-looking syntax. It adds more than it keeps, and as a result it's a every large, complicated, and convoluted language. It could easily take you a decade to learn the C++ language in its entirety, and even then it will still surprise you.

Don't worry about which language will be most useful. All languages are equally capable so the most useful language is the one you know the best.

Also, don't fall into the trap of thinking that a language with more features is "better". Those features only help if you know how to use them and they're relevant to the problems you're trying to solve. To make an analogy, a Swiss Army knife has more features than an Axe, but it won't cut a tree down any faster.

Link to comment
Share on other sites

The Linux kernel (as well and BSD and Windows kernels) are written in C because they have to be. The alternative would be assembly. C++ won't compile to bare metal.

C is still a good language to learn, but in terms of jobs, C++ developers are often more sought after.

Link to comment
Share on other sites

I have to agree with Sitwon, if you are new into programming, you should first learn C and become proficient at it. I wouldn't want to go jumping around languages, as they will differ from one another and will only cause frustration and confusion for you.

Choose one you are comfortable with and learn it until you understand it, before attempting to move onto another programming language.

Edited by Infiltrator
Link to comment
Share on other sites

If you are new to programming, i would suggest you learn something like java first, this is more true if you do want to learn c++, as with java you dont have to worry about memory management where as in c/c++ you will. Plus with java it will allow you to just focus on learning how to code in an oop language. And you also have the other fact that a java application will run on just about any system (as long as they have a java vm installed).

C++ won't compile to bare metal.

Are you sure about this? There are a few hobby OS's out there that have been coded with c++ over c, but they do have there own headaches when it comes to compiling and everything.

Clicky

Edited by Hyperant
Link to comment
Share on other sites

If you are new to programming, i would suggest you learn something like java first, this is more true if you do want to learn c++, as with java you dont have to worry about memory management where as in c/c++ you will. Plus with java it will allow you to just focus on learning how to code in an oop language.

Actually, that's exactly WHY I think you should start with C. Learning how memory management works under the hood is critical to understanding and debugging applications even when you're working in a language that doesn't allow you to mess with it directly. Trying to learn about memory from a language like Java/Python/Ruby is like trying to learn English by reading Dr Seuss books.

Furthermore, you can learn about OOP just fine in C. People were writing object-oriented code in C long before Java or even C++ had been developed. However, it can also be argued that the emphasis on OOP has been grossly overstated in recent years. Increasingly I am seeing programmers turn away from the "pure-OOP" that was so highly desired a decade ago. Instead, Functional Programming (FP) is becoming far more prominent as it offers effective and efficient solutions to our modern concurrency problems. There is also some amount of abandonment back toward procedural programming, as some have discovered that the abstractions of OOP simply don't provide enough benefit to warrant the implicit costs. So more and more you'll be asked to write FP or FP/OOP or even just procedural code rather than pure OOP. But all of outside the scope that a beginner should bother trying to follow.

TL;DR: Don't learn Java first. Learn C first. Java is "easier", but teaches you much less of value. It would likely retard your understanding of important concepts and principles .

Link to comment
Share on other sites

Actually, that's exactly WHY I think you should start with C. Learning how memory management works under the hood is critical to understanding and debugging applications even when you're working in a language that doesn't allow you to mess with it directly. Trying to learn about memory from a language like Java/Python/Ruby is like trying to learn English by reading Dr Seuss books.

Really? I beg to differ, Java isnt that hard to find memory leaks in, and yes you do get memory leaks in java applications. Java is just as easy to debug as a C application is ;)

The good thing about learning something like java over a language like c is that with java it allows you to just focus on learning the logic side of programming. With out having to worry about language specific things like did i free this memory? The really good thing about functional languages is that it doesnt actually matter what language you start out with the logic is all the same, the only thing that will change is the syntax, so yes you should learn a language like java before you go out and learn a more lower language like c. hmmmmm, i wonder if that is why they teach Java over C at uni as the first language they introduce you to ;)

Link to comment
Share on other sites

Really? I beg to differ, Java isnt that hard to find memory leaks in, and yes you do get memory leaks in java applications. Java is just as easy to debug as a C application is ;)

Not the point.

The good thing about learning something like java over a language like c is that with java it allows you to just focus on learning the logic side of programming.

I see this argument a lot, but you do realize that the "logic" side you're talking about is only the most trivial an superficial layer of programming, right? I takes the average student only a day or two to figure out how the "logic" side works. That's not where the challenge is, so optimizing for that is wasted effort.

With out having to worry about language specific things like did i free this memory?

Except that's not language specific. The syntax for doing it may be language specific, but all languages need to manage memory. It's a function of the computer, and that's what you need to learn if you want to be an effective programmer.

The really good thing about functional languages is that it doesnt actually matter what language you start out with the logic is all the same,

Uh, not really. Yes, there are several FP concepts which are common between the different functional languages, but there are many important differences as well. Tail-call optimization, pattern matching, macros, type-systems, there are a lot of important differences.

the only thing that will change is the syntax, so yes you should learn a language like java before you go out and learn a more lower language like c. hmmmmm, i wonder if that is why they teach Java over C at uni as the first language they introduce you to ;)

Oh wow... what a FAIL argument. You don't even want to get me started on how retarded Java classes are at most universities. Not only is it a poor language for teaching computer science, but most university programs I've seen in the US and Canada teach Java wrong. All too commonly I see Java being taught through the lens of C++, but they don't have the same OOP model. If you're teaching Java as C++ with garbage collection then of course it won't make sense to students and they'll find it confusing, frustrating, and start hating it. Few professors actually understand the design decisions and world-view of the Java paltform, instead they just view it as "lazy C++" and based on that flawed understanding the teach it poorly leading to whole generations of bad Java programmers.

For every competent Java programmer in the world there are 100 more who are just trained monkeys banging on their keyboard. It's not Java's fault, it's the education system that is failing to teach it properly.

Yes, I'm pretty passionate about this because Java is one of my favorite languages, but it's really not a suitable language for teaching the principles of computer science which every competent programmer (and especially hacker) needs to know.

Edited by Sitwon
Link to comment
Share on other sites

I wonder if that is why they teach Java over C at uni as the first language they introduce you to ;)

Most computer science degree's will introduce students to more than one language in their first semester. Perhaps Java is used as a counterexample, "Here is how you shouldn't be programming" :)

Personally the language which taught me the most on my degree was x86 Assembly (taught in the first year at the same time as Prolog and Pascal). I had already taught myself C, along with BASIC and Pascal, many years before I started my degree but having learnt Assembly really made a difference to my understanding of the memory handling in C and helped me take my abilities to the next level.

Would I teach Java to first year computer science students? No, partly because I don't really like Java and partly because I think that C and Assembly should be taught early on as it helps tie the programming side to the hardware side of computer science. Having said that I think students should be introduced to Java in their second year as it is now almost impossible for them to have a career where they won't have to deal with Java at sometime.

Link to comment
Share on other sites

Having said that I think students should be introduced to Java in their second year as it is now almost impossible for them to have a career where they won't have to deal with Java at sometime.

Increasingly, interest is turning away from the Java language to the Java platform. Rather than running Java code on the JVM, people are turning to Scala, Clojure, Groovy, JRuby, Jython, and other languages which target the JVM and allow access to the Java Classpath without actually being Java code.

Link to comment
Share on other sites

Im back, a week with no internet, except at uni.

So I started my first year at University of Helsinki, thats in Finland :D, and they do start computer science studies by teaching us java, so I than its Java. However I studied C programming for a couple of weeks myself and it helped me a lot whit Java.

Last year they started by teaching Scala and java, but luckily this year its only java. Next year its possible to learn basics of C.

Link to comment
Share on other sites

I see this argument a lot, but you do realize that the "logic" side you're talking about is only the most trivial an superficial layer of programming, right? I takes the average student only a day or two to figure out how the "logic" side works. That's not where the challenge is, so optimizing for that is wasted effort.

Really, you just said that? The logic behind anything that you code is the same regardless of the language you use (im talking about functional languages here, look it up)

The logic behind how one would implement say an algorithm for say something like md5 is the same regardless of the fact its done in c, c++, java. It doesnt change. The only thing that does change is the syntex nothing else. If you dont understand that then i would hate to see your code.

So I started my first year at University of Helsinki, thats in Finland :D, and they do start computer science studies by teaching us java, so I than its Java. However I studied C programming for a couple of weeks myself and it helped me a lot whit Java.

Last year they started by teaching Scala and java, but luckily this year its only java. Next year its possible to learn basics of C.

they teach Java over C at uni as the first language they introduce you to ;)

Link to comment
Share on other sites

Really, you just said that? The logic behind anything that you code is the same regardless of the language you use (im talking about functional languages here, look it up)

The logic behind how one would implement say an algorithm for say something like md5 is the same regardless of the fact its done in c, c++, java. It doesnt change. The only thing that does change is the syntex nothing else. If you dont understand that then i would hate to see your code.

I think you're misusing the term "logic" to apply to a much larger concept than I was referring to. I'm not talking about the logic of a program from the colloquial definition of "logic". I'm talking about the logic operators and structures in a programming language.

Learning how the logic operators and structures used in programming work takes less than a week. Learning how to apply them to solve non-trivial problems can take considerably longer. However learning how to apply them efficiently and effectively requires understanding and insight into the underlying implementation. Languages like Java are intentionally opaque about the implementation to the detriment of the learner.

And I never said that Universities don't teach Java to first years, I said that they SHOULDN'T teach Java to first years. I stand by that. Java is fine if you're studying Software Engineering, but not for Computer Science. Computer Science isn't about learning to develop software, it's about understanding computation (developing software is just a useful byproduct, not the end goal).

Link to comment
Share on other sites

Don't worry about which language will be most useful. All languages are equally capable so the most useful language is the one you know the best.

What? No the most useful language is the language the is best for the job. Really like i said, functional languages all the same. The only thing that changes is syntax not hard to pick up from language to language.

Actually, that's exactly WHY I think you should start with C. Learning how memory management works under the hood is critical to understanding and debugging applications even when you're working in a language that doesn't allow you to mess with it directly.

Once again, if you are starting out, learning how to program, it is much better to be using a language that will allow you to implement the logic side of thing for you with out you having to worry about memory management. It makes it a lot easer to learn how to program this way. Once you have an understanding of the logic behind what you are doing then you can start to focus more on the language side of things. Like memory management, but i wont say code optimization here as this comes under the logic side of things. If you need to speed up something then look at how you are doing it (logic look it up)

Trying to learn about memory from a language like Java/Python/Ruby is like trying to learn English by reading Dr Seuss books.

Yeah sure it is. The same principles come into play when you are debugging memory problems in java

Furthermore, you can learn about OOP just fine in C. People were writing object-oriented code in C long before Java or even C++ had been developed.

C isnt meant for OOP so why use it, use C++, once again this comes down to how well of a programmer you really are. You should be able to switch in and out of c and c++ very easily if the application needs objects then use C++ its the better language for the job, i have already explained this above.

However, it can also be argued that the emphasis on OOP has been grossly overstated in recent years. Increasingly I am seeing programmers turn away from the "pure-OOP" that was so highly desired a decade ago. Instead, Functional Programming (FP) is becoming far more prominent as it offers effective and efficient solutions to our modern concurrency problems.

Really? I would love to see some examples.

There is also some amount of abandonment back toward procedural programming, as some have discovered that the abstractions of OOP simply don't provide enough benefit to warrant the implicit costs. So more and more you'll be asked to write FP or FP/OOP or even just procedural code rather than pure OOP. But all of outside the scope that a beginner should bother trying to follow.

Yeah, are you sure about this? It is a lot easer to maintain a large project that has been done in pure OOP if it is done right, have you heard of the MVC modal? Im pretty sure this is becoming the industry standard.

TL;DR: Don't learn Java first. Learn C first. Java is "easier", but teaches you much less of value. It would likely retard your understanding of important concepts and principles .

Yes, the universities have it wrong. You are right. learn C first jave will retard your thinking

I see this argument a lot, but you do realize that the "logic" side you're talking about is only the most trivial an superficial layer of programming, right? I takes the average student only a day or two to figure out how the "logic" side works. That's not where the challenge is, so optimizing for that is wasted effort.

Except that's not language specific. The syntax for doing it may be language specific, but all languages need to manage memory. It's a function of the computer, and that's what you need to learn if you want to be an effective programmer.

I think you're misusing the term "logic" to apply to a much larger concept than I was referring to. I'm not talking about the logic of a program from the colloquial definition of "logic". I'm talking about the logic operators and structures in a programming language.

Learning how the logic operators and structures used in programming work takes less than a week. Learning how to apply them to solve non-trivial problems can take considerably longer. However learning how to apply them efficiently and effectively requires understanding and insight into the underlying implementation. Languages like Java are intentionally opaque about the implementation to the detriment of the learner.

Need i say more

Link to comment
Share on other sites

What? No the most useful language is the language the is best for the job.

Which is the language that the implementing programmer is most comfortable with.
Really like i said, functional languages all the same. The only thing that changes is syntax not hard to pick up from language to language.
Which is true to a point, but if you don't understand the low level then you can't make the jump from one paradigm/family to another. You will only be able to jump around within whatever language family you learned first. If you happen to learn one of the ALGOL-descended languages then sure, that covers 90% of languages out there, but it also trains you to artificially restrict your thinking to the lowest common denominator of those languages.
Once again, if you are starting out, learning how to program, it is much better to be using a language that will allow you to implement the logic side of thing for you with out you having to worry about memory management. It makes it a lot easer to learn how to program this way. Once you have an understanding of the logic behind what you are doing then you can start to focus more on the language side of things. Like memory management, but i wont say code optimization here as this comes under the logic side of things. If you need to speed up something then look at how you are doing it (logic look it up)
I disagree. I teach (yes, I teach) from the bottom up, rather than from the top down. I start by teaching people the basic principles of how the language is working, and that especially includes how memory is addressed and, later, managed. Understanding memory (and everything else that is happening under the hood) is critical to becoming a computer scientist or even just a good programmer.
Yeah sure it is. The same principles come into play when you are debugging memory problems in java
I see students get far more confused when trying to learn about pointers with Java than when learning with C. Java intentionally obfuscates and abstracts what's happening, which makes it unnecessarily challenging to teach those concepts with.
C isnt meant for OOP so why use it, use C++, once again this comes down to how well of a programmer you really are. You should be able to switch in and out of c and c++ very easily if the application needs objects then use C++ its the better language for the job, i have already explained this above.
I disagree with this. C's syntax might not be optimized for OOP, but that doesn't mean you have to jump to C++ just because you need some OOP in part of your application. GTK+ is an obvious example of a OOP toolkit that was written in C and the C API is perfectly usable. There are hundreds of GTK+ applications written in C.

C++ is a great language, but it's not a good language for teaching beginners. It's simply too complicated and convoluted for a beginner. How many different meanings are there for the keyword "static" in C++? Why are there so many? C++ has even more "gotchas" than C does, and many of them are even harder to explain.

Really? I would love to see some examples.

Here are bunch. (That didn't take much.)

There's also the vast majority of the LISP community as well as about half of the FP community.

Yeah, are you sure about this? It is a lot easer to maintain a large project that has been done in pure OOP if it is done right,
have you heard of the MVC modal? Im pretty sure this is becoming the industry standard.
Sure, it's becoming the standard in the Web App industry. An industry that is dominated by PHP, with occasional appearances from Java, Ruby, and Python. Notice how all of those are languages which grew up in the past few decades stressing how OOP they were (because OOP was the buzzword back then).

Look at the new crop of languages that people are talking about: Erlang, Haskell, Clojure, Scala, Nemerle, F#. What do they have in common? They're FP languages. Now that's not to say you can't mix OOP and FP (as Clojure, Scala, Nemerle, Ruby, and several other languages do well), however

Yes, the universities have it wrong. You are right. learn C first jave will retard your thinking
Many Universities seem to be operating under the impression that it's their role to prepare students for a "job" in the "programming" industry. As a result they're looking at trends and seeing that C# and Java are the "in demand" programming jobs. So what do they do? They go to all their professors and tell them to start teaching Java instead of C++. And what happens? You get a bunch of C++ professors teaching Java from a C++ perspective and getting it WRONG. Java and C++ have different OOP models and if you try to program Java like it's C++ with garbage collection you will wind up with ugly, slow, buggy code. And that's exactly what the Universities pump out into the workplace. I've been on both ends of this, I was one of the last generations to learn C++ as an introductory language and helped professors to switch the curriculum to Java when I was still a student. It wasn't until later that I realized what a bad idea that had been. I've also been in the position of interviewing and hiring students who had been damaged by such inadequate instruction.
Link to comment
Share on other sites

Which is the language that the implementing programmer is most comfortable with.

Any good programmer will be comfortable with a number of languages, which as you say will be good enough for most things they have to deal with, but there will be those times when a programmer would be better off spending the time learning a new language rather than tackling a problem with a language that just isn't suitable. (e.g. if you are needing to customise a WordPress theme you are better off learning PHP rather than trying to use C.)

I disagree. I teach (yes, I teach) from the bottom up, rather than from the top down. I start by teaching people the basic principles of how the language is working, and that especially includes how memory is addressed and, later, managed. Understanding memory (and everything else that is happening under the hood) is critical to becoming a computer scientist or even just a good programmer.

This statement shines quite a bit of light on where you and Hyperant differ. Hyperant seems to like learning/teaching top down (i.e. knowing how the big picture works before worrying about the detail) and you seem to like learning bottom up (i.e. knowing how the internals work before worrying about the bigger picture).

I was one of the last generations to learn C++ as an introductory language and helped professors to switch the curriculum to Java when I was still a student. It wasn't until later that I realized what a bad idea that had been. I've also been in the position of interviewing and hiring students who had been damaged by such inadequate instruction.

I had a similar experience myself. When I was at college I helped a lecturer convert their C tutorials/examples/coursework to C++. Of course due to the simplicity of the original C code the resulting C++ ended up being mostly procedural and not OOP. Did this help the lecturer, who knows? it did help me though understand a lot more about when OOP is a benefit to development and when it is a hindrance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...