Beginner in Programming

Discussion in 'Mac Programming' started by Josh Kahane, Jul 14, 2008.

  1. Josh Kahane macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #1
    Hi

    I previously asked on another forum on where to start if i wanted to program for the iPhone/iPod Touch. They said start with OSX. Im only 15 want to start early learn stuff over my summer holidays, where should i start? I dont know a thing by the way yet. Im am at the very beginning. Any help much appreciated, thanks.
     
  2. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #2
    Well when I was 13 I started off teaching myself Visual Basic 5 for windows making old school progs for aol 3.0 lol.

    But I'm kinda in the same spot as you. I'm a computer programming student. I just bought my first mac about a year ago. I'm learning this summer how to program for the mac. I won't be learning this in school so I have to do it on my own.

    Anywho, I have a strong C++ background, which can be an advantage and a curse. If you want to learn some basic programming principles, a good language to start is BASIC. It won't get you programming for the iPhone, but I thought I'd throw it out there.

    If you wanna jump right in, you wanna learn Cocoa and Objective-C. Apple brought out Objective-C 2.0 with OS 10.5 which includes a garbage collector and dot syntax, but I have been unable to find a good book out yet covering it.

    I want to program for the iPhone also, so my plan of attack is to learn Objective C and Cocoa and then once I know those I can pour through the Apple docs and figure out the differences and nuances in Cocoa Touch. After researching it, these books are your best bet as of now:

    Cocoa Programming for Max OS X THIRD EDITION by Aaron Hillegass
    Programming in Objective-C by Stephen Kochan

    Programming in Obj-C 2.0 is coming out in Nov. Make sure you get the third edition of the cocoa book; it will cover the garbage collector and the new stuff in XCODE 3.

    There is also an iPhone Developers cookbook by Erica Sadun comming in Oct. This will show you how to use the SDK to program for the iphone.

    Hope that helps. I'm sure I mentioned some stuff that doesn't make sense yet, but get those books and you will. Just take your time.
     
  3. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #3
    The place to start is with C, C++ or Objective C programing. At first you will create programs that run at the command line. These will accept typed input and create printed output. You may as well start with "plain old ANSI C" as that is the foundation for everything else. You are going to need a book length introduction. So you next question for the forum is "What is a good intro level book for C programming?" Don't worry about Cocca programming on Macs. At this point you just need to know programming in plain on C on the command line.

    OK, you are starting from dead zero. The first thing you want to do is to get the "Hello World" program to run.

    Code:
    int main()
    {
      printf("Hello World\n");
    }
    Put the above inside a file called hello.c and then compile it with "gcc -o hello hello.c" and run it by typing "./hello".

    After that you change the program to do something more useful, like find the first 100 prime numbers or whatever. Then write something to accept some typed words and alphabetize them. Much later you can worry about xcode and building a graphic interface then later you can do the same on an iPhone. But the Mac is a much nicer place to learn than the iPhone and everything you learn will carry over.
     
  4. ManWithhat macrumors regular

    Joined:
    Jun 24, 2008
    #4
    There's no return value in your main code you gave him.
     
  5. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #5
    Oh snap! That's a compiler warning if I've ever seen one!


    Yeah that biggest thing about programming is the logic. If you can understand the logic, the language isn't a big deal. The one thing I've noticed thus far going from C++ to Obj-C is how much more object-oriented it is. Make sure you have a good understanding of pointers and you'll understand objects better.
     
  6. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #6
    Programming in Objective-C is a good book, but it can be unclear on a lot of things. I think if I didn't already know C++, I would have had more trouble with this book. I don't know any C books, but I can recommend a good C++ book if you're interested...
     
  7. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    Actually, it is just plain illegal in C99.
     
  8. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #8
    Will it compile in XCode? I know it would in Visual C++, it would just give me a warning, if I'm remembering correctly.
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    Hmm, ignore me. I must have had a brain fart.

    Compiles fine *grumbles under breath*.
     
  10. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #10
    lol I refuse to ignore you, sir!

    No, I was honestly asking, not implying you were wrong in any way. To be honest, I have programmed almost nothing in XCode. I've merely been reading Obj-C and Cocoa books. I don't need the basic command line programs that books teach (I've done all of that in C++), so I'm just starting to get into the Interface Builder material. So I really was asking if it would compile or not.
     
  11. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #11
    Basically (and this what I got confused about) in C99 you are not allowed implicit return types. That is why the following is not allowed:

    Code:
    main()
    {
         // blah
    }
    this is fine though as it explicitly states the return value although personally I would add void to the arguments list.

    Code:
    int main()
    {
        // blah
    }
     
  12. skateme macrumors newbie

    skateme

    Joined:
    Jul 14, 2008
    #12
    An easy (and powerful) language to learn is AppleScript. The syntax is read like plain English and you can create some pretty good apps with it. Pretty sure it won't work on iPhone but it's a pretty good start for Mac dev.
     
  13. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #13

    There's also Perl and Python, which are pre-installed on a mac (have never really used them so can't comment on them). For my money though, Ruby (which I do use) is a good starting point as the syntax is beautifully intuitive, it's 100% object-oriented, making it a great launch-pad for objective-C and there's a little beauty called appscript Ruby that enables you to use it as an alternative to AppleScript if you're so inclined.

    Definitely agree that you'd do well to kick off with a scripting language though as you'll be able to practise your hand at programming logic and structuring classes without being overwhelmed with memory management and other things straight off.

    I'd hesitate at saying go for objective-c straight off. I started learning Cocoa programming with Objective-C about a week ago having been programming PHP for about 2 years and Ruby for about 6 months and while I think I'm doing alright, I suspect if I'd picked it up 2 years ago I'd have thrown it out of the window by about chapter 6. :)
     
  14. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #14
    ahhh ok gotcha. What is C99? Is it just a different standard of C?
     
  15. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #15
    Code:
    int main()
    {
        // blah
    }
    [/QUOTE]

    Sorry to digress, but how can this main function return an integer if the function inside isn't actually doing anything to return a value? Or is it just implicitly returning 0 for successful completion?
     
  16. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #16
    I can't comment on Ruby, but C++ really isn't a bad starting point for Objective C, either. Objective-C gets into Objects right away. My biggest gripe with the book I've recommended is that it introduces pointers at the end, and basically tells you to skip them. The author believes it will hurt your understanding. I believe they will help you with objects. A book like "Starting Out With C++" by Tony Gaddis doesn't get into object oriented programming until about half way into the book, so you get a good understanding of loops, functions (methods in Obj-C), arrays, pointers, etc. Then he shows you classes. I feel like this really has made Obj-C easy for me to learn. I had to adjust/shift my idea of objects a bit, because Obj-C uses them slightly differently, but when the author was doing things with pointers in the Obj-C book and explaining nothing about them, I knew exactly what was going on.

    Bottom line: Learn how to do command line programming first. When you have a good foundation there, you're ready to step into a graphical interface.
     
  17. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #17
    You need to "return 0" at the end of this for it to be proper; it isn't implicitly doing anything. This is why you'll get a warning doing it. You return 0 back to the OS at the competition of the program to indicate that the program has executed successfully.
     
  18. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #18
    The latest version. There was the original K&R "standard" then C89 which was standardised is 1989 and then C99 which was standardised in 1999. Just different revisions. Most compilers do not support the full C99 standard though.
     
  19. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #19
    I don't know BASIC, never used. But I have read many times that BASIC is a terrible language and that people who learning programming with that language are basically beyond all redemption as programmers.
    I don't know what the rational is behind it, but maybe it's better to be safe than sorry and thus stay away from BASIC. No insults intended here.

    A better place to start would be scripting languages such as php or perl, then move on to command line based programming with c or obj-c, before moving on the full fledge GUI based programmes.
     
  20. Farani macrumors 6502

    Joined:
    Oct 21, 2007
    #20
    lol no insult taken. What exactly do you mean beyond all redemption? BASIC is an old language. It is just as the title says, basic. Definitely not object-oriented. But it will get you working with loops, functions, etc, doing command line things. I took it in high school before C++. It was True Basic. A lot of people took it as an easy elective. I would recommend C++ based off my experience... I'm not saying other people's suggestions are worse or better. They might be much better. I'm just saying from the experience I have and how it has worked for me.
     
  21. Josh Kahane thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #21
    This is great guys, thanks, ill look into guides on AppleScript and Objective C/Cocoa. Although whats the link between Objective C and Cocoa? Also which would be easier to learn (as i dont know a thing yet), Apple Script or C? One more thing, whats the best way to learn, doing exercises, or reading the manual and sort of working through? Thanks.
     
  22. Josh Kahane thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #22
    Sorry one more thing. Whats the difference between Objective C and C++?
     
  23. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #23
    Objective-C is a language. Cocoa is an Application Programming Interface (API). Cocoa gives you access to the OS X internals through a defined set of actions. Cocoa is an Objective-C API, so that is the preferred language for accessing it. There are bridges to other languages like Python, but the most direct means of access is by programming in Objective-C.

    AppleScript might be easier to start with than C, but C will take you further towards the goal of being a proficient programmer.

    I believe that there is no better way to learn than to do. Exercises are the way to go. Reading and knowing how to read/understand documentation is very important, but if you read a cook book from start to finish, you would not be a master chef. You have to apply what you are reading immediately, in my opinion, for it to stick.

    C++ is a programming language with a long heritage. It is about 25 years old. It is not a proper superset of C, but uses a lot of C syntax while adding Object-Oriented programming as a supported programming paradigm. Object-Oriented programming is a means to group like functionality and data into packets called Objects. C++ is used for things like OpenGL graphics programming, Win32 programming, and a number of other tasks. I will leave the subjective discussion of its merits relative to Objective-C alone.

    Objective-C is also a programming language with a long heritage, but it has only recently begun to gain momentum. It was the lingua franca of the NeXTStep platform, and when NeXT was acquired by Apple it became the lingua franca of the OS X platform. It is a proper superset of C, adding syntax to support Objects. One major difference between Objective-C and C++ is the type binding. This is not going to mean a lot to you now, but this is important to Cocoa once you get there. Another major difference is the way methods are called on Objects. In C++ method invocations must be resolved at compile-time, even if they can be overridden at runtime. Invocations in Objective-C are performed using a message-passing protocol inherited from SmallTalk. This means that a message pass can fail at run time, but also allows for more run-time flexibility.

    All of this is, likely, gibberish to you. Really what you need to know is that C++ and Objective-C are both C-style languages that add syntax to support Object-Oriented programming. If you want to program native applications in the future on OS X, Objective-C is the best candidate. If you want to program against an API that is C++ based, that is a better choice. You can write against an API called Carbon on OS X with C++, but it was built as a bridge for developers moving from Windows and Classic Mac OS to OS X. It is quickly losing favor as Apple is not updating it to include features as OS X matures.

    Hopefully this is helpful, if somewhat overwrought.

    -Lee
     
  24. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #24
    "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration." Dijkstra.

    I am not a CS-guy, but from what I gather Dijkstra is an important computer scientist, and many people apparently share his view or parrot it (like me). I only mention this because the person asking the question is new to the world of programming and might not be aware of this view on Basic. Every language has it opponents and champions, but the opinions about Basic in this regard seem to be tilted quite strongly against the language.
     
  25. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #25
    Oh good, so it doesn't really work. That's reassuring. :)
     

Share This Page