From C, years ago, to what? Xcode, Python, RealBasic, other?

Discussion in 'Mac Programming' started by chitin, Mar 23, 2008.

  1. macrumors newbie

    Joined:
    Mar 23, 2008
    Location:
    Bilbao, Spain
    #1
    I started to learn C in the mid 90s (on my own and with a few good books) and by 1999 I had a working prototype (for the 68K processor) of the only application I worked on. This is an application designed to help me with the research I was doing at the time; basically analysing graph properties for sets of intersecting lines and nodes (shortest routes and similar things).

    I then modified the app to run on the PowerPC processor and tweaked bits of it until 2003 (under OS 9).

    When I switched to a G5, and OS X (10.3.9), I bought a couple of books and started playing around a bit with Xcode and Objective C. My intention was to update the software to run native on OS X, but could not run CodeWarrior on the G5. Then, I stalled, I felt the effort of switching was too much.

    However, I still use the software and I have been thinking about it again lately. Ideally, I’d like:
    - To be abe to re-use most of the code I wrote (in C, although with quite a few calls to the old Mac Toolbox).
    - Not spend ages reworking the GUI: I used mainly EasyApp by James E. Trudeau and ResEdit.
    - Be able to add features (functions) relatively easily, for which I’d be quite comfortable using C.

    I’ve read a number of threads in this forum before posting this and can’t find a similar case. My feeling is that to move on I’ll have to bite the bullet and, practically, start from scratch. In which case I’m not sure whether something like Python or RealBasic could be easier than Objective C (haven’t tried either).

    Bear in mind that it is not general programming I’m after, but to work on this specific tool I’ve developed over many years. Not fussed about cross platform issues either (Mac is fine). And although I enjoy programming as an activity, I have less time than years ago to devote to it. Also, I’m still with the G5 and OS 10.3.9 (but would buy a new iMac if need be).

    Any suggestions? Many thanks for your patience and any possible advice.
    Chitin
     
  2. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Best method would be to port it to Carbon and use Interface Builder for the UI.
     
  3. thread starter macrumors newbie

    Joined:
    Mar 23, 2008
    Location:
    Bilbao, Spain
    #3
    Thanks Cromulent, but I have some difficulties.

    I did look into the document "Moving Projects from CodeWarrior to Xcode", that Apple produced at the time, but can't do the preparatory steps because the version I had of CodeWarrior (version 6) does not run in my G5 and the old computer (PowerPC 9500 with Mac OS 9) won't start anymore. And I don't think it's that productive to buy a newer version of CodeWarrior just for the conversion.

    So the situation is that I have all the source code files and the resource file in my G5, but no CodeWarrior software to run or play with.

    How difficult do you think it would be to create a new application with XCode, build the UI and add source code files one by one, changing them as I go along? Or can anyone see an easier route? Am I talking nonsense?
     
  4. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    Carbon is good as its similar to the Macintosh Toolkit. So if you have code in that it will be easier to use Carbon. However Carbon isn't going 64 bit so going to Cocoa will be more future-proof. Cocoa is much more modern than Carbon, and it is a very communication centric development system which works very well. Like Carbon it is based on C so any raw C code will work with it however the UI stuff will have to be re-worked.

    EDIT: When I talk about Cocoa I mean Cocoa with Objective C. As you know C that will be easier/faster than using Python with Cocoa. I would also strongly advise upgrading to Leopard for Xcode 3.0.
     
  5. macrumors 6502

    Joined:
    Jun 16, 2004
    #5
    Unfortunatelly, you won't be able to buy CodeWarrior (10) anymore. You may be in luck if you contact Freescale and explain your situation (not for commercial use, personal development, etc), but I'm not sure if they will be able to help.

    I've never done a conversion from CodeWarrior to XCode, however if you don't care about giving up your code I can probably do it for you. (I'm using XCode 3, not sure if its backwards compatible).
     
  6. macrumors member

    Joined:
    Mar 21, 2008
    #6
    I would look at Java. It's the cleanest and best supported object oriented language. With netbeans you get a UI builder. The APIs are awesome, much of what you had to code by hand ten years ago is most likely all available.

    Get a head first java book (amazon it.) You'll be developing in no time.

    And your program will run on anything.

    -kamo
     
  7. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #7
    Java's UI stuff is notoriously poor.

    Same applies to Cocoa. Java takes most of its ideas from that.

    That is an advantage, but it won't look particularly good on any platform...
     
  8. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #8
    I wouldn't recommend Java really unless you need the cross platform nature of it. If he is going to have to learn (parts of) a new language I would think he would be much better served spending the time learning Objective-C and then Cocoa as it will give him the grounding he needs for Mac development for probably the next 10 - 20 years or so. I can't see Apple dropping Cocoa anytime soon.
     
  9. macrumors 6502

    hankolerd

    Joined:
    Sep 19, 2007
    Location:
    Seattle, WA
  10. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #10
    Hi

    I'm not sure if this is a good strategy but I would suggest keeping your original C code and put some time into stripping out all the ui code to create a library which could be used as the 'back end' for your new app (I can't really see the point of rewriting everything in a new language). Once this is done you've got a few choices for creating the front end.

    If you decide to go down the Objective-C/Cocoa route then you only need to learn enough to be able to implement your new UI. You'll be able to pick up Objective-C quickly, prototype the UI in Interface Builder, and pick your way through only the parts of Cocoa that you need to get the job done.

    If you want to go down the RealBasic route, then you could use RealBasic for the UI and link it to the C library that you've created. I'd say picking up RealBasic will be a lot quicker than Cocoa (you could probably have a working UI in days), but it would be inferior to the Cocoa equivalent (there are more visual controls in Cocoa and they look and behave a lot better than the RealBasic counterparts).

    Hope this helps!

    b e n
     
  11. thread starter macrumors newbie

    Joined:
    Mar 23, 2008
    Location:
    Bilbao, Spain
    #11
    Many thanks to all

    I'm grateful for all the contributions, and particularly to Sord for that generous offer of doing the porting.

    When I fisrt chose C that many years ago, one of the criteria was that it had to be a language with a long term projection and I'm more than happy with how it has turned out (I'm very slow at this, I'm afraid). So, I think Cromulent's referece to the long term bet is good advice and that's the route I think I'll try (Objective C and Cocoa).

    I also like Ben's suggestion, of stripping the code to the basics and build a new UI with Xcode. In fact, since much of the UI was in a set of files that I recycled from James Trudeau, the code I wrote is largely about the basic calculations, with little UI in them (just hooks to the menus and some window drawing behaviour).

    So I'll probably be getting myself a new toy (a macbook with Leopard and Xcode 3) and get back to learning a bit of programming. I'm sure I'll be posting more requests for help when I get stuck with it.

    All the best
     
  12. macrumors 65816

    Joined:
    Apr 19, 2004
    #12
    Had to dig for this:

    http://www.mactech.com/articles/mactech/Vol.15/15.01/Jan99GettingStarted/index.html

    For those suggesting to port to Carbon so that you can use most of the Mac Toolbox calls....Apple had a thing called the "Carbon Dater" that would tell you how much of your app needed to be changed to get Carbon compatible. Who knows if they still do such a thing.

    Also, remember that Objective-C is just C plus some object oriented stuff. Anything that is compatible with C is also compatible with Objective-C.

    Don't confuse Cocoa (apples new API) with the Objective-C language :)
     
  13. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #13
    Many parts of the Carbon UI has been modernized and they've even made lots of improvements for Leopard but I doubt that the next cat will add many features, if any at all. If you learn Carbon now without stepping into Cocoa, you'll eventually be behind at some point again. It's clear that Cocoa is the future :)
     
  14. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #14
    In case you don't have any system at the moment that actually compiles your old code, you could consider finding an old fruity-coloured iMac on eBay, and use it for the first phase of going to modern Carbon. It's a matter of preference. Some people prefer working with a working code base all the time, alternatively start XCode, create a new Carbon project, add all your source files, and fix all the compiler errors that you will get one after the other.

    It is probably a good idea to separate all user interface code into separate functions at the same time.
     
  15. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #15
    FWIW I've done this twice in trying to clean up someone else's C++ code for a Windows app.

    Stripping it down to its pure essence is a great way to simplify and allow you to completely separate the UI from the bits that do the heavy lifting. As a bonus, straight C is portable to any platform supported by GCC, so think of it as future proofing.

    B
     
  16. macrumors regular

    Joined:
    Mar 22, 2008
    #16
    2 cents

    I am just starting out also on Objective-C and it's just the first week but I feel it is a very elegant language once you get the hang of it.

    I do have some basic Java experience, also from years ago and also learned on my own. Other languages (just for your reference) include Pascal and of course the ever popular BASIC.

    My suggestion to you (take with grain of salt as I am just a newbie) is to go with Xcode and Objective-C. You can "reuse" most of your C code, since ObjC is basically C with OOP stuff put on top. You can use C syntax completely if you do not want to do the OOP stuff.

    So what you can do is figure out how to OOP your original code, and create an OOP version of the core logic (without the UI stuff) and then use Xcode's Interface Builder to create the interaction later.

    This would allow you to later extend the code easily, since it's OOPed.

    I would not recommend going to REALbasic, or any other of those languages, not even Java. Forget Java. You already know C, and therefore can pick up Objective-C in about a day or two (really). How much you grok the OOP stuff depends on yourself but from what you wrote I don't think you will have much trouble going that route.

    There are very few Objective-C books out there though (someone correct me if I am wrong). I think only about 3 or 4 of them actually, for OS X and Xcode.
     
  17. thread starter macrumors newbie

    Joined:
    Mar 23, 2008
    Location:
    Bilbao, Spain
    #17
    Might try Carbon...

    Whilst I get the impression that the Objective-C route is the more future-proof, after seein psingh01's message and the MacTech article I am tempted to give Carbon a go.

    Unfortunately, the Carbon Dater tool doesn't seem to be available anymore for a preliminary check (can't find it in the ADC Carbon section), but if it is true that most of the Toolbox routines of the old Mac OS are supported in Carbon, it might be a relatively quick effort.

    On the other hand, if I find too many difficulties I'll move over to Cocoa and start cleaning up the old code...
     
  18. macrumors 6502

    Monkaaay

    Joined:
    Jun 19, 2006
    Location:
    Richmond, VA
    #18
    If you already know C and want to develop for OS X only, working with Objective-C and Cocoa is definitely the way to go. It shouldn't be a terribly difficult transition with a C background.
     
  19. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #19
    Cocoa is a far better framework too. Its one of the best frameworks on any platform.
     
  20. macrumors newbie

    Joined:
    Mar 7, 2008
    #20
    I would agree with Monkaaay here.

    I've updated some old codewarrior apps to XCode universal binaries and most of the old resEdit resource files just don't work anymore. Plus you need at least CodeWarrior 8.3 and preferably 9.1 or higher to do the auto translation to XCode.

    If you only need to write for a Mac then InterfaceBuilder and Cocoa is probably the way to go.

    If you need cross platform, Mac, Window and Linux from the same code, or have a lot of complicated GUI that needs to get done really quickly, then REALBasic is definitely the way to go.

    gary hayenga
     
  21. macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #21
    Ack! No, ditch REALBasic (or any variety of BASIC) and use Qt (or wxWidgets, but Qt is better) if you need to do cross platform GUI development.
     
  22. macrumors newbie

    Joined:
    Mar 7, 2008
    #22
    You clearly have no idea what REALBasic is if you try to equate it with any other variety of BASIC. BASIC is just the syntax it uses.

    It's an excellent tool for fast, cross-platform, object-oriented, GUI development that natively compiles to machine code for Mac, Windows and Linux.

    If those aren't the things that you need then there may be better tools for your specific need. But if those are the things you need then you can just get stuff done with it.

    gary hayenga
     
  23. macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #23
    I know what REALBasic is. Despite the OO guff and an expanded library, it's still Basic. Which is ultimately just a matter of taste (Basic = the Rodney Dangerfield of languages), but more importantly, unlike Qt Open Source edition, RealBASIC isn't free (by a long shot).
     
  24. macrumors 6502

    Monkaaay

    Joined:
    Jun 19, 2006
    Location:
    Richmond, VA
    #24
    Sounds like a more efficient version of Java to me. :thumbup:
     
  25. macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #25
    To paraphrase Stroustrup, Java isn't platform independent, it is a platform, and a proprietary one at that. It's a subtle distinction that's lost on many.
     

Share This Page