Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am a java developer (web app and standalone applications) who knows JavaScript, HTML, CSS and has mostly worked on Web applications. I have no knowledge of C/C++ or any other lower level languages.

I feel like I should strengthen my CS basics by learning a fundamental language. Should it be C or C++? I am also inclined to learn Objective-C. Does it need basics of C or C++? Or should I go for new languages like Python, Google's Go etc.

I know this is a cliche question asked very frequently, but I can use some help here.

share|improve this question

closed as off-topic by MichaelT, Oded Jun 14 at 16:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about what language, technology, or project one should take up next are off topic on Programmers, as they can only attract subjective opinions for answers. There are too many individual factors behind the question to create answers that will have lasting value. You may be able to get help in The Whiteboard, our chat room." – MichaelT, Oded
If this question can be reworded to fit the rules in the help center, please edit the question.

7 Answers 7

up vote 10 down vote accepted

If you're looking to get more fundamental knowledge, I'd suggest C rather than C++ (C++ isn't that far off from Java conceptually). C is much "closer to the metal" than C++ or Python is. Although if you really want to get down to basics, learn assembly language (but not many folks drop that low these days).

What advantages do you think C would give me over C++? I understand that it's close to hardware, but in today's world, how advantageous would it be?

Using C will force you to think and code at a lower level. All those nice things like lists, queues, hash tables and such that are part of the standard libraries of Java/C++ you'll have to roll your own. There are many examples out there, but you'll have to pick one and understand how it works to use it. Also since C lacks an object system, you won't be able to use tricks like smart pointers to handle memory management and thus be forced to manage that too. Mind you, you can graft all these things onto C through the use of macros and some creative programming (after all, the first C++ compilers were just C pre-processors) but you'll learn a lot about them in the process if you do so.

As for advantages in the real world. Well I'd say that the main advantage is getting a better understanding of just what is involved in many of the higher level objects you use and take for granted every day in Java. Like I can tell you that doing str + str + str is a bad thing in a tight loop in Java, but until you actually see all the memory allocation that doing a chain of string concats in C entails, you might not grasp just how valuable it is to use StringBuilder in these cases.

After you've gotten enough of fiddling with bits, I'd suggest you go the other direction and look into functional language concepts. From Java a good choice of functional language to get into would be Clojure, but for learning the basics of functional programming it might make more sense to look at a pure functional language like Haskell or Scheme (in the form of DrRacket) both of which have some very good introductory material freely available online.

share|improve this answer
1  
What advantages do you think C would give me over C++? I understand that it's close to hardware, but in today's world, how advantageous would it be? –  Sid Jun 24 '11 at 17:09
1  
After C, doing a little assembler can be good. Knowing how a function call works is good, as well as being able to break your code down to the most basic steps. No need to do a big project with it though - just implement strcmp or something :) –  Michael K Jun 24 '11 at 17:10
    
Can't agree more, thanks. –  Sid Jun 24 '11 at 17:32
4  
Even though C++ and Java have some common syntax, Java's overall design is much closer to Smalltalk than to C++. C++ is (or can be) exactly as "close to the metal" as C -- the only difference is that it does more to provide and support higher-level abstractions when you want them. –  Jerry Coffin Jun 24 '11 at 17:55
1  
Yeah, I'm with @Jerry on this one: C++ is quite far from Java conceptually. –  Jon Purdy Jun 24 '11 at 19:29

I would vote in favor of C++, for a number of reasons.

First of all, C++ has quite a bit more that's reasonably similar to Java, so the transition is likely to go a lot more smoothly. This is even more true of the library than the language itself -- the Java library is much larger than either the C or C++ library, but the C++ library has enough more that it won't be nearly as foreign. If you decide to go to C, plan on feeling utterly lost for the first few months (at least) simply because the library provides so little of what you're accustomed to being able to use. You'll probably still feel like you're missing quite enough with the C++ library.

Second, in terms of concepts, C is nearly a subset of Java -- essentially the only thing it has that Java doesn't is pointer arithmetic, which I've never seen as being all that big of a deal. Although Java has generics, you'll quickly find that C++ templates really have quite a bit that's new, different and (at last potentially) quite interesting. With C, you're not really likely to learn a lot that's new or different (other than, perhaps, a rather different (minimalist) viewpoint on programming). C++ has a fair number of new and different concepts to learn that simply aren't present in either C or Java (e.g., template meta-programming).

C does have a couple areas where it's virtually the only choice. If you want to write code for really tiny microcontrollers or operating system kernels, then yes, there's a good chance that it's what you should learn. Though it's only personal opinion, I would say that in most other areas, C probably should have been dropped a long time ago, and continues to be used primarily out of momentum (we've got 7 zillion lines of C, and we're not going to rewrite it...) or simple bigotry (e.g., see Linus Torvalds's rants).

As far as Objective C goes, the situation is fairly simple: if you're going to write for an Apple system (MacOS or iOS), everything else is clearly and definitely relegated to secondary status. Apple does their best to push the idea that all development most be done in Objective C. While it's possible to do otherwise, Apple is pretty clearly doing their best to make your life as difficult as possible if you insist on doing it.

At the same time, total use of Objective C on all other platforms is probably easier to measure in parts per million than percentages. For most practical purposes, "do you want to learn Objective C?" can be rephrased as "do you want to write native apps on Apple machines?" with essentially no loss or change in meaning.

Bottom line: C and objective C both have strong niches; if you're interested in one of those niches, you virtually need to learn the language that fits. Otherwise, I'd have a lot of difficulty recommending either one.

share|improve this answer
    
Thanks for a detailed explanation. –  Sid Jun 25 '11 at 5:53

The part of C++ that is close to the metal is the same as C's, so learning C++ won't give any benefits as far as low-level programming goes.

C++ has many pitfalls, and is a hard language to master because of this. Unless you want to become a professional C++ programmer, the efforts won't be worth it. The high-level programming features of C++ (basically OOP and generic programming) are also present in other languages, where in my opinion they are easier to learn. My personal preference goes to F#.

Learning low-level programming is hard enough by itself, and you don't want to be disturbed by the oddities of C++ while you are learning. If you want to learn C++, you can do it after you have learned C.

share|improve this answer
    
Thanks for your response. –  Sid Jun 25 '11 at 5:54

As someone who does more C++ than Java work, I would think that learning "object oriented C++"[1] shouldn't pose that much of a problem to someone proficient in Java. The main pitfall I would see there is that you can easily end up writing Java in C++ rather than idiomatic C++ and that's where the real challenge lies, because C++ is a lot more than just "C with classes". Being able to write OK OO code in C++ should be fairly easy for someone with a Java background, but mastery of the language will take a lot of time and effort.

If you want to learn C++ to have more than one leg to stand on job-wise then it might be worth the effort. If you're trying to do it purely for advancing your programming knowledge and insights, I would do the following:

  • Learn C. The language isn't that big, it's got fewer gotchas than C++ and it's very "close to the metal". It's not being referred to as a portable assembly language for nothing.
  • Pick up another language that uses idioms that are far removed from the traditional procedural programming (like in C) or OO programming (like in Java). It doesn't matter that much as to what it is - Haskell, Erlang, Lisp, Clojure etc - but the idea is that you'll expose yourself to a different way of thinking when it comes to programming. You'll get much more out of it from your general understanding of programming idioms than by learning another language from the same family tree..

[1] As opposed to the whole enchilada with generic programming and all the other idioms it also supports.

share|improve this answer

From a CS perspective, C++ might be more interesting as there's more going on in that language. For example, the introduction of lambda expressions opens the door for all kinds of interesting bits and functional programming. Template metaprogramming as well, and a lot of the new language features where built in to support this new avenue of development.

C would serve you more in moving to Objective-C. Unless you're on the Apple, where Objective-C++ is possible, you can't combine C++ and Objective-C. Most people seem to hate the mix anyway but I've never had the opportunity to use it. Unlike C++, Objective-C really is very much like C with object-oriented support.

share|improve this answer

I would start with C. C++ is essentially C with object-oriented support. It might (I don't know for sure, but this seems likely) make learning something like Objective-C easier. Also, C is a pretty good middle ground between Java and assembly. If you want to go low enough to learn assembly, knowing C would make it easier (since it is a very low-level programming language).

share|improve this answer
4  
Sorry, C++ is WAY more than C with object-oriented support. –  Crazy Eddie Jun 24 '11 at 17:15
    
I've been told that Objective-C is much more like Smalltalk added to C, whereas the original C with Classes that acquired a whole lot more stuff and became C++ was C with Simula classes. Two very different object-oriented systems. –  David Thornley Jun 24 '11 at 17:42

C++ is a good choice at the moment, Microsoft is building it up again after letting it languish a little in favour of C#; and there's the new C++0x which has just been ratified so you'll get a bit ore good stuff out on the blogosphere as compilers catch up (I believe GCC already has and VC2010 has a fair bit of it implemented). There is another factor in play here - C++ may be more difficult to learn than many other languages, but I've never been to an interview or similar and had people say "you know C++, so you won't be able to pick up language x in no time", quite the opposite in fact :)

Objective-C is a good choice if you want to code for iOS, but otherwise is best left until you've done a fair amount of C (and/or C++). Script languages are good to add to your repertoire, but I think you'll need a 'core' language first before using Python, Ruby, Perl or Visual Basic/WSH. Last option is C#, but I think you'll find that too close to Java to provide an answer to your question.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.