PDA

View Full Version : From C, years ago, to what? Xcode, Python, RealBasic, other?




chitin
Mar 23, 2008, 07:59 AM
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



Cromulent
Mar 23, 2008, 08:05 AM
Best method would be to port it to Carbon and use Interface Builder for the UI.

chitin
Mar 23, 2008, 11:03 AM
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?

Eraserhead
Mar 23, 2008, 11:07 AM
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.

sord
Mar 23, 2008, 11:10 AM
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).

kamo
Mar 23, 2008, 01:13 PM
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

Eraserhead
Mar 23, 2008, 01:29 PM
With netbeans you get a UI builder.

Java's UI stuff is notoriously poor.

The APIs are awesome, much of what you had to code by hand ten years ago is most likely all available.

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

And your program will run on anything.

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

Cromulent
Mar 23, 2008, 01:34 PM
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

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.

hankolerd
Mar 23, 2008, 01:44 PM
cocoa is what apple likes to see people use:apple:

lazydog
Mar 23, 2008, 02:26 PM
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

chitin
Mar 24, 2008, 10:59 AM
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

psingh01
Mar 24, 2008, 03:02 PM
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 :)

kainjow
Mar 24, 2008, 03:07 PM
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 :)

gnasher729
Mar 24, 2008, 04:15 PM
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.

balamw
Mar 24, 2008, 10:40 PM
I also like Ben's suggestion, of stripping the code to the basics and build a new UI with Xcode.

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

zippyfly
Mar 26, 2008, 11:23 AM
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.

chitin
Mar 30, 2008, 05:05 PM
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...

Monkaaay
Mar 31, 2008, 08:37 AM
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.

Eraserhead
Mar 31, 2008, 08:39 AM
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.

Cocoa is a far better framework too. Its one of the best frameworks on any platform.

gary hayenga
Apr 1, 2008, 01:53 PM
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.

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

yeroen
Apr 1, 2008, 02:04 PM
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

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.

gary hayenga
Apr 2, 2008, 10:35 AM
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.

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

yeroen
Apr 2, 2008, 10:51 AM
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).

Monkaaay
Apr 2, 2008, 10:54 AM
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

Sounds like a more efficient version of Java to me. :thumbup:

yeroen
Apr 2, 2008, 11:14 AM
Sounds like a more efficient version of Java to me. :thumbup:

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.

Alloye
Apr 2, 2008, 12:19 PM
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).

Actually, the problem with REALbasic isn't the language or even the cost. It's REAL's absolute refusal to release critical bug fixes outside their every 90-day release schedule.

In addition, REALbasic's multi-platform strength is also a weakness. The built-in controls and framework are compromised in favor of the lowest common denominator. While this eases development of simple, database-style applications, creating something that feels truly native on any given platform usually requires a great deal of platform-specific work.

Eraserhead
Apr 2, 2008, 12:57 PM
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.

Not entirely Java is now released under the GPL.


As you already know how to code with C, you'll have no problem moving onto Objective C/Cocoa or Carbon or QT which are all C or C++ based.

gary hayenga
Apr 2, 2008, 04:09 PM
Sounds like a more efficient version of Java to me. :thumbup:

If you mean the "write once/run anywhere" plan, then yes I would have to say much more so. Since REALBasic is natively compiled it doesn't have the Java Virtual Machine overhead.

Theoretically it doesn't have the advantage that if some writes a JVM for a new OS, like say the iPhone, then *theoretically* your Java app would just run. But it doesn't really work that way anyway. And even when you can get your Java app to work it more staggers than runs anyway.

I think REALBasic's RAD interface design is second to none, though I'm wiling to be wrong.

If your priorities are cross-platform, speed of development or shallow learning curve, or some combination thereof, then REALBasic is a very good tool.

If those aren't your priorities then other things could well be better.

gary hayenga

chitin
Apr 3, 2008, 02:32 PM
I'm really pleased with the amount of debate generated and grateful for all opinions. They have been most helpful.

Since the last mail, things have moved on a bit. The people at Freescale have been really nice and helpful, with an incredible service, and I now have CodeWarrior installed on my G5 which means I can at least open up my project and play with it in an environment that is very familiar to me (many thanks to Sord for the tip). Also, I just got myself a new MacBook with Leopard and Xcode 3.

What this means is that I'm going to try a bit of everything. I'll start with CW and see if I can compile an OS X version of my software, then I'll probably atttempt migration to Carbon and, starting from now, I'll gradually learn ObjC with Cocoa using my program as the learning project. Ultimately, I believe I'll migrate fully to the Objective C - Cocoa combination (using simple C when appropriate), but with time and playing around with CW and Carbon as I go along.

This is not to ignore all the suggestions about RB or other routes, which I understand could be reasonabe options, but having invested so much in C as I did I think it'll be good to build on it.

Thanks to all again
Chitin

iSee
Apr 3, 2008, 03:09 PM
That's a good plan. Carbon *is* Toolbox for OS X.

Tip: A good search keyword regarding converting Classic apps to OS X Carbon apps is Carbonize (just in case you hadn't realized this already).

chitin
Apr 3, 2008, 05:08 PM
That's a good plan. Carbon *is* Toolbox for OS X.

Tip: A good search keyword regarding converting Classic apps to OS X Carbon apps is Carbonize (just in case you hadn't realized this already).

Thanks for the tip. I didn't know.

Cromulent
Apr 3, 2008, 06:19 PM
That's a good plan. Carbon *is* Toolbox for OS X.

Not really. Quite a few of the Core frameworks are technically Carbon APIs and they are still very relevant to current Mac OS X development. Carbon as a set of APIs is not entirely dead, some parts are still relevant they have just been renamed.