Is it a good idea to learn java before learning c?

Discussion in 'Mac Programming' started by macbook pro i5, Feb 28, 2012.

  1. macrumors 65816

    macbook pro i5

    Joined:
    May 13, 2011
    Location:
    New Zealand
  2. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #2
    I'd say it depends upon your reason for wishing to learning either language.
     
  3. macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #3
    My problem with Java for beginners is that it forces a fairly strict object oriented design approach, which is good in some ways, and confusing in others. A simple "Hello World" program requires you to create a class, then define a static main method within that class, then to even call the println function you need to understand its class hierarchy (System.out.println).

    My sister, for example, did an "introduction to programming" class in high school, and hated it because the teacher didn't do a particularly good job of explaining the concepts -- and there are a lot of concepts to know -- so it felt too much like magic incantations to her. (Is it "public static void main"? or "static void public main"? or ...)

    C is a little looser in that respect (though they get far more similar once you dive into C++) as you can write simple procedural programs without having to worry too much about wrapping the code in a class.

    So for the very basics, if you're going to learn one before the other, I'd probably start with C. (Actually, for the extreme basics of programming, I'd start with Python.) But if you're already reasonably comfortable with object oriented programming, Java has a lot more functionality "out of the box". Once you learn one, switching to the other is not too difficult.
     
  4. thread starter macrumors 65816

    macbook pro i5

    Joined:
    May 13, 2011
    Location:
    New Zealand
    #4
    I want to learn c++ then objective c so i can make apple apps.
     
  5. macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    I took a Java class last semester and I learned C from a really good book about 18 months ago. If you don't have any experience in programming I would start small so that it won't confuse you, like it did me. I found that the book Learn C on the Mac was a great was to get started in programming. I spent a good 3 months slowly reading that book and redoing the small projects my own way. When I finished I wrote a small console based blackjack game.

    With C under my belt I was easier to move into Object-C. Everyone has a learning curve. You can aim hi but don't be afraid step back in to a simpler language. It will take a while to get good and it depends on you.
     
  6. thread starter macrumors 65816

    macbook pro i5

    Joined:
    May 13, 2011
    Location:
    New Zealand
    #6
    Yeah i have no prior knowledge but i replace computer parts
     
  7. Mac_Max, Feb 29, 2012
    Last edited: Feb 29, 2012

    macrumors 6502

    Joined:
    Mar 8, 2004
    #7
    It's not really going to help you learn core C concepts faster. It might actually prejudice you in some ways so if you do go that path (or really even the reverse) so try to keep an open mind when switching to one language from the other. Essentially the core concepts are different and the stuff that does transfer is syntax like:

    Code:
    
    for (int cnt = 0; cnt < SomeInt; cnt++)
    {
    int myInt = AFunctionCall(cnt);
    }
    
    
    Stuff like that should be rather reasonable to learn in the first place.

    Edit: Ironically I had a much longer post that covered a couple of things now brought up in replies... here's part of it in reference to...

    Coming up with good advice for this kinda depends on what your background is. I get the feeling that you're just starting out and really don't have a lot of familiarity with any one language.

    C, C++, and Objective C are similar in a great number of ways. Learning one can help with learning one of the others but it can also cause major headaches. As I learn Objective C myself, I tend to rely on my C++ knowledge in respect to the overall Object Oriented nature of the language but I really have to try to keep myself in an Objective C state of mind. Trying to use Objective C like C++ is a pretty bad idea (and vice versa for that matter). Each language has its own mindset that you have to get a grasp on. In many ways this is more important than just getting used to a different syntax. In the case of C++ and Objective C, even though they're both Object Oriented, they do it in two very different ways.

    If your end goal is learning Objective C, you're probably better off starting with a good C primer to learn the C memory model, pointers, and C style syntax before moving to Objective C related books (most of which will have a mini-C primer as a refresher). You will end up working with ISO/ASNI C code at some point so thats definitely not a waste of time. Once you're comfortable with C/Objective C, start from a fresh empty cup stand point and learn modern C++ (as in, don't write C++ like C with a little C++ sprinkled in). Then feel free to mix them properly and appropriately with Objective C++.
     
  8. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #8
    I wouldn't bother. I'd probably learn C, then Java.

    But, I'd learn Python, Ruby, or Javascript first. Java and especially C can be incredibly de-motivating when trying to learn how to do the simplest of programs.
     
  9. macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #9
    Agreed. Start with Python. Use the command-line interpreter at first for instant gratification. Then write simple programs. Try your hand at user input and output. Basic control flow like loops. Simple functions. The forced indentations in Python will help you visualize code in structures which will help you discipline your coding in C and C++.

    Then move to basic procedural C. Write a "hello world" app. Write a simple console game where the computer picks a random number, you guess, and it tells you if it's too high or too low. Write the opposite program where YOU think of a number and the computer guesses. Stuff like that.

    Then move to objective C and/or C++.
     
  10. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #10
    I still assert that if the goal is Objective C you should try to learn that first, then once you have the hang of that back off a bit to learn some more C and then jump with both feet into Cocoa or Cocoa Touch.

    This is the approach Kochan takes and is aimed at those without any prior experience.

    Hillegass' latest book gives a whirlwind tour of C before launching into Obj-C and this would be my only recommended alternative.

    IMHO Java and C++ will only add confusion to the mix.

    B
     
  11. mrxak, Feb 29, 2012
    Last edited: Feb 29, 2012

    macrumors 65816

    Joined:
    Apr 16, 2004
    Location:
    Drifting through space in a broken escape pod
    #11
    I feel that in general, it's better to learn older languages before learning newer languages, if your goal is to learn a lot of different languages. If your goal is to learn one language, just learn that language. If you want to learn many languages, start with the earlier stuff first.

    My reasoning is that new languages are created in reaction to other older languages, which inform their philosophies and syntaxes. New languages are created because the creator felt that existing languages were not suitable for certain problems. I believe it would be useful for you to understand what those problems were first, so when a newer language says it can handle it better, you understand what it's all about. Especially when you're just starting out and everything's new, older languages have less concepts to learn just to get your foot in the door.

    Every language has its benefits and downsides; there is no one perfect language for every single problem. The more languages you know, the more flexible you can be as a programmer, just like choosing the right tool for the job. You can still bang in a nail with a wrench if it's just one nail to hang up a picture frame, but you probably want a hammer if you're going to build a house. The point is, it's good to have options so you can weigh the pros and cons when you want to tackle a project.

    So, my advice would be to learn C first. C is a wonderful language that will give you a great foundational knowledge of computer programming, as well as an appreciation for memory management. Then, if your goal is Objective-C, you'll already know the bones, and just add on object-oriented programming (and presumably Cocoa libraries). Then, if you're interested in learning other approaches to object-orientedness, try out C++, or Java. Then you can start digging into some really interesting languages like Haskell, Ruby, or Lua. Before long, you'll be doing crazy stuff with Perl, Scheme, and MIPS assembly language.
     
  12. macrumors newbie

    Joined:
    Feb 29, 2012
    #12
    Learn C

    The short version: Everyone should learn C first.

    I agree completely with mrxak

    As a Computer Engineer, trained bottom up from transistors to assembly to C, I could not stress more how important I would say it is to learn C. I believe that everyone programming should thoroughly understand what they're really doing and what is happening when their code is executed/compiled/etc. I'll admit its not necessarily useful for an average programmer to worry about learning assembly first, but a fundamental knowledge of the lowest levels of computer software are essential to well-designed code. Since C is at this point as close to bare metal as really matters, and is so fundamental to so much of today's world of programming languages and modern computing, every programmer should thoroughly understand it.

    Object-oriented programming is useful but certainly is not the end-all of software design, and it definitely doesn't make sense to me to start there. That being said, I found the jump from C to Java (when first learning OO) easier than to Objective-C even after years of experience with C++ and Java. They are so different that Java is probably not the best starting point for learning Objective-C, but I would definitely recommend it as a next step to learn OO after mastering C.

    Scripting languages are useful but learning them definitely doesn't tell you anything about how a computer works, of course not everyone cares how the computer works, as long as it magically happens. I see them as shortcuts (and I do use them often) but as tools for simple tasks (perl is pretty much only good for find and replace) or simplifying and automating a long toolchain, for which they are perfect.

    Of course that's just my opinion, I suppose it doesn't work for everyone.
     
  13. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #13
    The problem I have encountered, even in my own coding, is that the C/Unix DIY approach is the antithesis of good Obj-C code.

    In C, you are actively encouraged to build stuff from scratch. Painfully crawling over the broken glass and barbed wire.

    Higher level languages, especially OO ones, would never force you figure out your own bubble sort, or parse input strings by hand, and the reality is that you do not need to know how this works to be productive and meet your goals.

    Sure, it can help when you run up against something that doesn't work, but it is far from essential.

    I repeat if the end goal is to learn Objective-C to program on Macs/iOS focus on learning that. Learn C along the way as it will be useful, but it is too easy to develop detrimental habits that way.

    DISCLAIMER: Everyone learns things differently, YMMV, IANAL, etc...

    B
     
  14. thread starter macrumors 65816

    macbook pro i5

    Joined:
    May 13, 2011
    Location:
    New Zealand
    #14
    Thank you you are right i have no prior knowledge to any language so i think ill just get my self a learning c book in fact i saw a website teaching c and it is much easier to learn then java IMHO.
     
  15. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #15
  16. Mac_Max, Feb 29, 2012
    Last edited: Feb 29, 2012

    macrumors 6502

    Joined:
    Mar 8, 2004
    #16
    Yeah, my experience has been the same when it comes to C++ and other languages. A lot of people get stuck in the romantic idea of tweaking their code for "maximum performance" for hours on end. I try to stick to the platform's built-in constructs as much as possible. I've seen some really weird things like ad-hoc developed XML parsing facilities in C# (which must have three different, solid, built in ways to do that already) that are terribly inefficient, leak memory, and had to have taken at least one hundred hours to write. I think it took me about 10 hours to teach myself how basic Linq queries and XDocuments work.

    I learned how to work with ANSI/ISO C on the fly while learning and working with C++ (mostly within the realms of Win API calls) and my experience has left me feeling like it might actually be worthwhile to learn the basics of C first, separately. A lot of times my C knowledge is not particularly good (my worst being C style strings... terrible things they are anyways...) and it sometimes makes debugging sample C code for iOS and Mac learning projects painful ;). Granted that probably is more a function of that being a hobby instead of my primary language so this experience likely can be filed under your disclaimer haha.

    Looking at balamw's book link and its TOC, he's probably quite right, the first 70 pages should teach you what you need to know. You can also try "Learn C the Hard Way" (note, that's "hard" as in correct/not taking short cuts):

    http://c.learncodethehardway.org/
     
  17. macrumors regular

    Joined:
    Jun 25, 2009
    #17
    Learn Objective-C first if you want to make Apple apps. You will likely need a little background in C first, but that should be covered by most introductory objective-C books. I would recommend Cocoa and Objective-C Up and Running if you are new to programming, if you have any background in a C based language I would recommend starting with Programming in Objective C 2.0.
     
  18. macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #18
    A someone whose taught himself to code with Objective-C as my first real language, I have to fully agree with everything @balamw has said. If things get too difficult for you, and you really feel like giving up, Python, might be a reasonable alternative to build your confidence before returning to Objective-C. Java doesn't make much sense to me based on your stated goals. You might want to learn it some day, it's a fairly common language, but it's a bit like flying from the US to Sydney when your final destination is Moscow (it's vaguely in the right direction, but far enough away that it makes no sense).
     
  19. thread starter macrumors 65816

    macbook pro i5

    Joined:
    May 13, 2011
    Location:
    New Zealand
    #19
    Thank you so much every one for your help now i have a learning c book and hope to eventually work at apple some day:)
     
  20. macrumors 65816

    Joined:
    Apr 16, 2004
    Location:
    Drifting through space in a broken escape pod
    #20
    Glad to hear you're taking the plunge into C. Good luck to you and have fun.

    I highly recommend, in addition to learning how to program in C, that you try to learn computer science concepts as well and not just... "programming". I'm not familiar with the book you're using, so I have no idea what's covered, but it'll be useful long-term for you to understand algorithms and data structures and all sorts of things like that. It's not just important to know how to program things, but to know how to design and build a program that works efficiently and isn't a nightmare to maintain and alter.
     

Share This Page