Programming in OS X

Posted:
in macOS edited January 2014
I am not sure if this belongs here but, if not, please don't flog me for it



I'm interested in learning to program for the Macintosh. I have had experience doing minor programming in Linux using C and python.



I was curious what most developers use to program Mac OS X apps:C++, C, objective-c, etc.



Also, what would you fellow developers recommend on learning or brushing up on. I heard maybe C, because most of the Cocoa APIs support C or objective-C. I am not too sure about C++ support.



Any input would be greatly appreciated.



Thanks,

Felipe
«1

Comments

  • Reply 1 of 29
    programmerprogrammer Posts: 3,457member
    Quote:

    Originally posted by feliperal

    I am not sure if this belongs here but, if not, please don't flog me for it



    I'm interested in learning to program for the Macintosh. I have had experience doing minor programming in Linux using C and python.



    I was curious what most developers use to program Mac OS X apps:C++, C, objective-c, etc.



    Also, what would you fellow developers recommend on learning or brushing up on. I heard maybe C, because most of the Cocoa APIs support C or objective-C. I am not too sure about C++ support.



    Any input would be greatly appreciated.





    C++ is well supported as well.



    As with any problem, which tool you should use depends on the nature of the problem. I've got a couple of little Python utility programs, plus a C++ Cocoa app that I'm working on. Since I pretty much live and breath C++, that is my language of choice for most large GUI applications or game development. It isn't necessarily the best choice for a new programmer.
  • Reply 2 of 29
    zapchudzapchud Posts: 844member
    I started learning C++ two months ago. Good to hear it's well supported under OS X.
  • Reply 3 of 29
    Python is such a lovely language, probably my most favorite language. I just enjoyed how easy it was to pickup. Now, since there is a wrapper with C, it makes it even more easier to program complex tasks.



    I'm working write now on implementing Rendevous notifier within linux. i am using GTk2 and C. Basically, It will have a nice GUI where I can add links to services within Linux (i.e. ftp, http, etc.) and advertise them within Safari or Itunes. Currently, I can download the source of this implementation from Apple on there ADC site. Only problem is that it is a command line tool and I can only run one add per terminal. Such a hassle to use up a tty for one service. Why not be able to make it run through a nice command interface.



    I guess my question was referring to the degree of support for C/Objective-C in Cocoa. I heard that there is more funcationally with the above than with C++. Also, are there other implementations for GUI apps? Please forgive me for my ignorance. I'm a complete newbie to Mac OS X.



    Thanks
  • Reply 4 of 29
    chychchych Posts: 860member
    Oof, programming in c/c++ (Carbon API) in Mac OS is like programming in c/c++ for the Win32 API, it is utter crap. Definitely learn Obj-C and cocoa, there is no better API for creating/managing interfaces and general programming; event handling is MUCH nicer, the provided classes are VERY useful and nice to use, etc etc etc. You can also interface cocoa's obj-c with regular c and carbon code somehow, never tried myself, but there's that option too.



    Since obj-c is essentially a wrapper for c, c knowledge should be known. C++ isn't useful for learning obj-c (nothing in c++ is really in obj-c) except perhaps oop theory (if you don't know it already, but you can learn this with cocoa too).
  • Reply 5 of 29
    Since it's all pretty much new to you, go for Obj-C. That is the current focus for Apple (although that could change in the future, depends on developer adoption, if most developers stick with C/C++ and the Carbon libs, then things could change). Good luck and have fun!
  • Reply 6 of 29
    amorphamorph Posts: 7,112member
    Keep in mind that you are in no way required to stick to one language for the entire project. You can use C++ for everything that doesn't require system calls, write the UI in Objective-C, drop down from either language into C if you need to do some procedural crunching, and link everything together and expect it to work. (This is called "Objective-C++" by Apple, since they allow some commingling of C++ and Objective-C code).



    Definitely learn Objective-C just because it's simple and cool and amazingly powerful, and because Cocoa was intended to be used with it. But don't assume that it's the only tool at your disposal. Apple has plenty of documentation on their developer site, including documentation on Objective-C++.
  • Reply 7 of 29
    3.14163.1416 Posts: 120member
    Quote:

    Originally posted by chych

    Definitely learn Obj-C and cocoa, there is no better API for creating/managing interfaces and general programming; event handling is MUCH nicer, the provided classes are VERY useful and nice to use, etc etc etc.



    Agreed. You may also want to look at PyObjC (http://pyobjc.sourceforge.net), which allows you to write Cocoa apps in Python.
  • Reply 8 of 29
    smirclesmircle Posts: 1,035member
    Quote:

    Originally posted by fuzz_ball

    Since it's all pretty much new to you, go for Obj-C.





    I disagree. Obj-C will do you no good if you ever want to code for any other platform. Both your code and your knowledge will be locked into the platform.



    Get a solid knowledge of C++ and the STL (the standard classlib for C++) and learn to separate the platform dependend parts from the platform independend. Make a habit out of doing the platform-independend core functionality in C++/STL and slap either a Cocoa UI (you need to learn some obj-C and the Cocoa classes) on or a Carbon one (you can stick with C++ but need to learn some Carbon framework) on.



    It enforces a much cleaner coding style and does not restrict your options.



    FWIW, I am currently doing my programming with Java and the Eclipse project SWT/JFace classes. Those both look native and are fast (on a recent machine with 500Mhz or more). On my Tibook they are OK, on my Centrino the programs fly.
  • Reply 9 of 29
    3.14163.1416 Posts: 120member
    Quote:

    Originally posted by Smircle

    Obj-C will do you no good if you ever want to code for any other platform. Both your code and your knowledge will be locked into the platform.



    Not true at all. First, ObjC can be used on non-Mac platforms. GNUstep (http://www.gnustep.org) is a port of the Cocoa APIs to many flavors of Unix and Windows. Second, even if you don't use ObjC on other platforms, the knowledge you'll gain is hardly useless. From ObjC and Cocoa I've learned many techniques that have improved the Java code I write at my day job (such as delegation, notifications, and MVC). Programming is about algorithms and design patters, not the syntax of individual languages.



    Quote:

    Make a habit out of doing the platform-independend core functionality in C++/STL



    If ObjC isn't cross-platform enough for you, there are many more options than C++. Higher level languages like Python are widely recognized as enabling faster development, while avoiding common C/C++ pitfalls like buffer overflows. The only habit you should follow is picking the right tool for the job.
  • Reply 10 of 29
    smirclesmircle Posts: 1,035member
    Quote:

    Originally posted by 3.1416

    Not true at all. First, ObjC can be used on non-Mac platforms. GNUstep (http://www.gnustep.org) is a port of the Cocoa APIs to many flavors of Unix and Windows. Second, even if you don't use ObjC on other platforms, the knowledge you'll gain is hardly useless. From ObjC and Cocoa I've learned many techniques that have improved the Java code I write at my day job (such as delegation, notifications, and MVC). Programming is about algorithms and design patters, not the syntax of individual languages.





    Not to bash Gnustep (I like the idea), but kindly take a look at the number of applications they are listing on their page. Apart from the workspace.app and mailviewer, only a handful remain. Now contrast that with the amount of C++ or Java apps. It doesn't matter where you look outside the Mac world, neither the OpenSource guys nor software companies have obj-C/Cocoa/GNUstep on their radar.

    Additionally, you should be fair enough to mention that Gnustep has not too much to do with MacOS X. It is based on Display Postscript, not PDF. It features neither AppleTalk bindings nor .nib file support, nor QuickTime. You cannot mix-and-match C++ and Obj-C like you can on MacOS X. Cocoa has evolved massively over the last 6 years, the same cannot be said of Gnustep. Gnustep is not an alternative implementation of the Cocoa API.



    Secondly, if you want to learn good, objective-oriented code, why not choose one of the three languages that are actually wanted by employers: Java, C++, and C#?
  • Reply 11 of 29
    fluffyfluffy Posts: 361member
    Don't worry about what employers are looking for. A second OO language will take a few hours to learn tops once one is mastered, and besides you seem to be interested in this for personal enjoyment not resumé enhancement. There is really no reason to put yourself through the hassle of programming in C++ or Java on OSX when Obj-C/Cocoa provides such a pleasant environment.



    The only thing that is different on the Mac than on Windows or Linux is the development APIs, but that will always be the case. Of course the effort you put into learning Cocoa will not help you program for Windows any more than learning the C# libraries will help you with the Mac or Linux. The cross-platform alternative is Java of course, but Java apps will always be second best in speed, system integration and polish. I don't think it's worth it.



    For application programming on the Mac, stick with Obj-C/Cocoa. Tools are different, use whatever language and tool fits best; perl, python, lex/yacc, etc.
  • Reply 12 of 29
    3.14163.1416 Posts: 120member
    Quote:

    Originally posted by Smircle

    Secondly, if you want to learn good, objective-oriented code, why not choose one of the three languages that are actually wanted by employers: Java, C++, and C#?



    Those languages are not the epitome of OOP. (C++ in particular, due to its static binding). I've been programming in Java for 7 years and ObjC for only 2, yet I consistently find myself more productive with ObjC. (I actually learned C++

    before Java, but after being exposed to better languages I have no desire to use it).



    If popularity among employers were the main criterion, we'd all be using Windows...
  • Reply 13 of 29
    Don't slag C++ too much -- in many ways modern C++ is much more powerful and expressive than ObjC and Java, especially when you building large high performance software. It pays for this power with language complexity, but you don't get something for nothing. For the majority of the code I write professionally using anything else would be a joke. For toy projects or a GUI front end ObjC and Java are fine, but for the heavy lifting I'll turn to C++.
  • Reply 14 of 29
    kickahakickaha Posts: 8,760member
    Quote:

    Originally posted by Programmer

    Don't slag C++ too much -- in many ways modern C++ is much more powerful and expressive than ObjC and Java, especially when you building large high performance software. It pays for this power with language complexity, but you don't get something for nothing. For the majority of the code I write professionally using anything else would be a joke. For toy projects or a GUI front end ObjC and Java are fine, but for the heavy lifting I'll turn to C++.



    Oh I *have* to ask... what large high performance software are you building that C++ is 'best' for? I've worked on everything from miltary flight and sonar simulators to EPA mesocontinental transmedia simulation code, and C++ has *rarely* been the best tool for the job, but instead the one we've been told to use. Java really isn't for high performance, but Obj-C and C++ share the same 'drop to C' ability for when speed matters, and on that level they're equal within a small epsilon from every situation I've run into. The biggest plus C++ has IMHO is template based pre-programming (using the template system for computation at compile time not run time) which can be highly useful, but other than that, there's darned little in the *language* which I find compelling. (STL started out as a beautiful little library, but has grown into this monstrosity that is admittedly powerful, but no more so than dynamically bound containers in Obj-C or Smalltalk, and with entirely too many levels of complexity built in now.)



    Smircle: As I tell my undergrad students, it's infinitely more important to learn principles than syntax. Anyone can code in C++... but it doesn't mean it's well-designed or even OO code. Obj-C is a clean OO language that lets you learn *OO*... *then* you can go learn the syntax of C++ quickly. (And find out how to work around things you took for granted before... *sigh*) I started with Eiffel of all things, and it took no more than a week to see what OO could be. Moving to C++ after that was painful, but fairly straightforward. Conversely, working with folks in industry who had been using C++ for a couple of years, it became obvious that they hadn't much of a clue as to how to design OO systems... the 'zen' of OO had escaped them because they were working in a language that allowed objects, but isn't really object-*oriented*. It's more object-permissive.



    I'd toss a new programmer at Obj-C before C++ any day. Let them learn the ideas and ideals, then go get in the trenches later. C++ is a necessary evil, IMHO, rather like Windows - it's out there, it's ubiquitous, it's something you should probably know just for sheer survival... but that doesn't mean it's necessarily *best*, or even what a novice should start on.



    If someone is looking to program *for the Mac*, Cocoa/Obj-C is my answer, hands down. They'll learn good design, good principles of programming, and be able to concentrate on lessons of architecture instead of struggling with arcane syntax. *THEN* they can go get their hands mucky with the 'real code' and see how bad it can get on the other side of the fence.



    If they are looking to *learn programming for a profession*, I'd point them at Python or Ruby as a OO testbed, then Java and finally C++.
  • Reply 15 of 29
    The best post so far - especially for the originator of this thread - BY FAR has been Kickaha.



    I'm an extremely novice programmer at this point - I taught myself applescript studio a while ago, it got my feet wet again, and I taught myself Obj-C. I learned C a long long time ago - so it wasn't all foreign, but I bought a book and read 3 chapters and then was off writing and experimenting. The book was the Aaron Hillegass book - and excellent one!



    Now I have to say that many times obj-c makes the hard things easy and the easy things hard. It's funny that way. Kikaha is right though - when you need performance - it doesn't matter whether it's C++ or Obj-C (which is currently updated to be obj-c++) - straight C gives you best performance.



    The notion that Obj-C isn't adequate for large projects is laughable. The CIA and LAPD were 2 of NeXT's largest customers. I suppose they are kind of rinky-dink, thinking about it



    Anyway - like Kikaha said - Obj-C really enforces good coding practice. I've seen a lot of C++ (when I learned C it didn't exist - so I've only looked at it a bit) that has nothing to do with OO programming systematics. It's a lot of OO methods used in a procedural way. In obj-c, I've been guilty of the same, but it becomes so quickly apparent that there is a better way of achieving your goal that you (hopefully) quickly adjust your way of thinking.



    In many ways, I would think of Obj-C as an ideal learning language. Even if Apple falters and the language fades from practical application, I would still recommend it - because learning syntax is easy. Learning HOW to program is like building a house - do it right the first time, because it's a lot harder to fix later on.
  • Reply 16 of 29
    Quote:

    Originally posted by Kickaha

    Oh I *have* to ask... what large high performance software are you building that C++ is 'best' for? I've worked on everything from miltary flight and sonar simulators to EPA mesocontinental transmedia simulation code, and C++ has *rarely* been the best tool for the job, but instead the one we've been told to use. Java really isn't for high performance, but Obj-C and C++ share the same 'drop to C' ability for when speed matters, and on that level they're equal within a small epsilon from every situation I've run into.



    Why would you want to "drop to C" when speed matters? Speed and advanced language features need not be mutually exclusive. All ObjC adds to C is a very dynamic object model, which is fine for building very dynamic object systems but that is not the be-all and end-all of software engineering (OOP is not a universal answer, it is a powerful tool in what should be a toolbox of techniques). ObjC's model can also be too dynamic in that problems which should be detected at compile time aren't reported until runtime.
  • Reply 17 of 29
    Quote:

    Originally posted by nothing

    The notion that Obj-C isn't adequate for large projects is laughable. The CIA and LAPD were 2 of NeXT's largest customers. I suppose they are kind of rinky-dink, thinking about it

    ...

    In many ways, I would think of Obj-C as an ideal learning language. Even if Apple falters and the language fades from practical application, I would still recommend it - because learning syntax is easy. Learning HOW to program is like building a house - do it right the first time, because it's a lot harder to fix later on.




    Don't get me wrong, I'm not saying ObjC isn't a good language -- I'm saying that fans of it dismiss C++ far too easily. ObjC is a nice, simple add-on to C and useful to learn. I don't know I agree that it "enforces" good coding style, but again that is a matter of opinion. I also didn't say it wasn't good for large projects.



    Note that I also didn't say that C++ is the perfect and ultimate language. There are good reasons why it is so widely used, however.







    The people responding to a thread called "Programming in OS X" on AppleInsider are very likely going to be pro-ObjC. This is hardly a good place to get a balanced viewpoint.
  • Reply 18 of 29
    kickahakickaha Posts: 8,760member
    Quote:

    Originally posted by Programmer

    Why would you want to "drop to C" when speed matters? Speed and advanced language features need not be mutually exclusive.



    Riiiiiiiight, but what do you think you're doing when you roll a highly optimized C++ method that eschews RTTI, templates, STL, etc, and all the rest of the bugaboos that are known speed killers in C++? You're left with C. Obj-C does precisely the same thing - don't use the selector method calls, and you've stripped off the Obj part, leaving you -C. Er, C. There's really no difference in my experience.



    C++ definitely has its place - learning OO isn't one of them, IMNSHO.
  • Reply 19 of 29
    kickahakickaha Posts: 8,760member
    Quote:

    Originally posted by Programmer

    OOP is not a universal answer, it is a powerful tool in what should be a toolbox of techniques.



    ABSOLUTELY! The richer the toolbox, the better the programmer... but don't you think that it's best to learn each tool to the best degree possible? *For OO*, C++ has severe limitations and makes it entirely too easy to break out of and cheat with sidesteps. (Of course, one could argue that it *makes* you do so since its OO model isn't exactly clean, but that's another discussion.)



    If someone is looking to learn OO, I point them to Obj-C, Python, Ruby or Smalltalk (Squeak)... depending on their focus. If they want to learn generic programming, C++ has one of the best such facilities around (although Eiffel comes in a close second). (Of course, dynamic messaging rather subsumes expicit generic programming, but having it be explicit helps a student learn what's going on... then they can map it easily to dynamic OO.)



    I don't think we're that far off in our positions here, I was addressing explicitly the question of how to learn programming *on MacOS X*. For that, Cocoa and Obj-C are the clear winners in my mind.
  • Reply 20 of 29
    Quote:

    Originally posted by Smircle

    Not to bash Gnustep (I like the idea), but kindly take a look at the number of applications they are listing on their page. Apart from the workspace.app and mailviewer, only a handful remain. Now contrast that with the amount of C++ or Java apps. It doesn't matter where you look outside the Mac world, neither the OpenSource guys nor software companies have obj-C/Cocoa/GNUstep on their radar.

    Additionally, you should be fair enough to mention that Gnustep has not too much to do with MacOS X. It is based on Display Postscript, not PDF. It features neither AppleTalk bindings nor .nib file support, nor QuickTime. You cannot mix-and-match C++ and Obj-C like you can on MacOS X.




    that c++ and objc mix isn't gnustep fault, but moreso the fault of the gcc compiler project manager(s). apple has given them the code necessary to add the "objective-c++" language, but they haven't added it in yet. i'm pretty sure that apple has the source available on their site somewhere, so a person can build an objc++ compiler if they so desire.



    the GNUstep project is wonderful. it offers (nearly) full cocoa api compatibility. that is, write your app for osx (without proprietary bits, like .nibs; actually, I'm pretty sure you can convert .nibs to an open format, like .gorm), build yourself a GNUmakefile (which isn't as hard as a well done, hand made, regular Makefile), and rebuild. i've yet to encounter anything in cocoa that isn't covered by the GNUstep's implementation. the only nagging problem is their docs are empty mostly empty. but, luckily, apple's aren't, and all wording applies to the GNUstep version.



    Quote:

    Cocoa has evolved massively over the last 6 years, the same cannot be said of Gnustep. Gnustep is not an alternative implementation of the Cocoa API.



    Their main intention as I understand it, is to provide a free version of cocoa, so innovation isn't really a big part of it.



    Quote:

    Secondly, if you want to learn good, objective-oriented code, why not choose one of the three languages that are actually wanted by employers: Java, C++, and C#?



    You just named 3 of the most disgusting languages in use today.
Sign In or Register to comment.