Friday, August 24, 2012

NCPrime Mac - Reflections

Long story short: Don't worry - I have not forgotten about the Mac versions of my applications!

Long story long: Years ago, I suddenly became a Mac person when my parents bought me a black MacBook for Christmas in 2006. I loved that computer from the day I got it until I reluctantly sold it for parts in June. But, in the nearly six years I had that computer, I learned nothing about programming, for Mac or otherwise.

I upgraded to a mid-2010 MacBook Pro with maxed specs just a few weeks after I began my first year of college, giving my black MacBook to my younger brother. Despite liking this new laptop even more, I still made no efforts to pursue programming.

In retrospect, I have no idea why. I had styled myself "NullCoding" since the end of 2008, based on some very, very limited experience with VBA (back when Excel supported native VBA, from what I understand). Needless to say, I was disinterested in programming for no good reason.

I only started Mac programming around the end of July 2012. I had been learning C/C++ seriously for about a month before I even started looking at how to do it on a Mac, so once I learned that the Objective-C language used on Mac OS X for native application development is syntactically identical to pure C, I jumped on it. I soon discovered that Obj-C takes many cues from Java and that the XCode IDE is indeed similar in appearance to NetBeans. I drew a hierarchy in my head - Java influenced C#, which is based on C, on which C++ is based, as well as Objective-C. It all started to come together.

It took me less than two days to write a working version of GJSieve 1.7.0 for Mac, most of which was time spent trying to compile the GMP library for multiple platforms from the command line (I figured it out). MuPuPriNT for Mac followed soon after.

I actually started off a little before my GJSieve porting endeavors by giving myself a crash-course in compiling C++ code on Mac. I simply copied over the NCSpiral source from my Windows machine and compiled it using Apple Developer Tools (after I installed them, anyway). It took less than 5 minutes to learn how to use C++ on the Mac - it just works! Whaddaya know?

Since then, however, I have found myself competing against myself!  At the very least, potential application development projects are competing for space in my head and my schedule. I don't have the ability to develop the same application for two different platforms simultaneously. My brain does not work like that. If I finish a major release of, say, GJSieve for Windows, only then can I go to the Mac and implement those same changes.

See, I can't just copy and paste code. In fact, I recognize that to be what my future father-in-law calls "the worst possible thing any programmer can do." So I wrote GJSieve and MuPuPriNT for Mac completely from scratch.

I love Objective-C. Something about it is just quintessentially Apple - straightforward, encapsulated, shiny, fresh, and above all, easy to use. And yet it pleasantly does not give me the impression that "any idiot can write a Cocoa app."

I am so eager to learn, in fact, that I often stare at page after page of official documentation and unofficial tutorials and references trying to find new things to implement. When I found out that OS X Mountain Lion would have full social networking integration, I laughed about it for a bit and then promptly got myself a copy. One flash drive and one hour later, my MacBook Pro was running a sleek and totally up-to-date version of Apple's latest entry into their dubiously feline-themed virtual product line.

I even drove to another state just to buy a shiny new iMac for my father so he too could take advantage of all the exciting new features Apple has given us!

..just kidding, I bought him an iMac because his was going on 7 years old and running Tiger. I also owed him several years' worth of Father's Day gifts...better late than never. Also, come on, the man who consistently forgets how to make folders on his desktop is going to use the Twitter and Facebook integration and iCloud and whatnot? Please. He just needs something that'll last until at least 2018.

I was disappointed with the new (to me) version of XCode, however. Since I was previously running Snow Leopard 10.6.8, I could only use XCode 3.2.6, with which I'd become quite familiar. XCode 4.x had been out for awhile (since the release of Lion last year) but I'd not used it before and consequently had to essentially re-learn everything about how to navigate the IDE.

I figured it out, though, and re-wrote (or at least re-compiled) MuPuPriNT for Mac, deployed to a target OS of 10.8.0. I smugly enjoyed the sense of satisfaction that came from staying ahead of the curve - Mountain Lion had not even been out for three weeks, and my little applications were already compatible!

Not only that, but I soon learned about the NSSharingService class and its method ShareOnTwitter. How easy could it get? I mean really. To share on Windows, I have to do all this, and even then it just takes you to the website! It doesn't post it for you like the Mac does!



At any rate, I am not suspending Mac development, nor will I forgo Windows development because one is easier or harder. I do, however, take into account the fact that the Mac application is actually markedly faster at calculating a massive number. I think this is because of the innately better memory management of Objective-C, which is great considering most applications built in this language are meant for mobile devices. But I don't know. All I know is that it doesn't even appear that the Mac applications need to be multi-threaded! ...yet.

A friend of mine recommended a great cross-platform GUI solution - wxWidgets. This friend is not exactly well-versed in programming in the sense of writing code, but he certainly knows facets of technology and keeps well abreast of the latest and greatest trends (and apparently industry standards as well).

I'd love an easy, cross-platform development solution for my GUI! Just one thing - I'd still have to write two separate groups of code on two different computers in two different IDEs. Given that MuPuPriNT is currently nearly 300 source files and some 7,000 total lines of code (and it's nowhere near done), I think I'll pass and stick to what I know (somewhat) - pure VC++/Win32 API for Windows, and pure Objective C/Cocoa for Mac.

Yes, my Mac apps are native 64-bit. So is any Mac made past 2008. No, my Windows apps are not. They are 32-bit. Not because it's the "Win32" API, but because of the inline assembly code I use. Inline _asm intrinsics do not exist in the 64-bit VC++ environment. I would have to re-do the entire project with specific instructions to use MASM's ML64.exe externally as a custom build step...blah! Not knowing a single word of Assembly, I think I'll pass!

I think that's enough for now. In the near future, I'll be continuing work on MuPuPriNT 1.1 for Windows. Once that is done (give me a week or so with classes starting and all that), I can begin to focus on my Mac apps, specifically IsItPrime and GJSieve, both of which are due for massive overhauls as their standalone versions are currently older and less reliable (and less shiny) than their counterpart implementations in MuPuPriNT for Mac.

MuPuPriNT for Mac, by the way, is technically still on version 0.4a. The Windows version on which I'm currently working is at 1.1b. It will be a lot of work to implement all of the changes - at least the major, important ones - in the Mac app to retain at least some indication that they are, indeed, the same applications on different platforms.

Big ideas...and classes start in just three days. For the record, I don't study computer science...!

No comments:

Post a Comment