Category Archives: Development

Apple Professionals Group

A wonderful bouquet of flowers.I wrote down some thoughts a couple weeks back and thought I’d throw them up here. It’s mainly a bunch of questions with some ideas. Unlike a small group of Professionals I don’t need the stuff I talk about here. I’m perfectly happy with my work 2014 MacBook Pro and my 2011 MacBook Pro. Both computers are plenty powerful enough for iOS Development. Here are the thoughts.

Why doesn’t Apple create a Professionals Group dedicated to developing a lineup of serious Pro computers and software? Maybe it moves a bit more slowly than the rest of the company? Maybe you get a computer every two to three years, but it’s at the top of the range, always. Maybe the computers are completely upgradable and modular. Something like we’ve never seen Apple create.

Laptops with “bigger” bodies (think late 2014 15in MacBook Pro), with faster processors and lots of RAM. Maybe you can only get one type of laptop? E.G. 15in MacBook Awesome with the newest Core i7, 32GB RAM, and a 1TB drive, plus a discrete graphics card of some kind driving their already awesome Retina Display.

Think of a more rectangular Mac Pro. One you could open and add RAM, processors, and drives to, easily. Maybe there is a way to plug “modules” into the front and back to the device without cracking the case? Maybe the case is the size of a Mac Mini, but is stackable so you can add additional units Toolbeltthat extend processing power. E.G. pop off a small cover on the top that exposes a slot that the next “Mini” looking device sits right on top of. Oh, how about extending the iMac using these “modules”? That would give us a 5k display and give Pros the ability to scale it up from the base model. Maybe the primary “motherboard” is just a beautifully designed Apple Bus that allows that. Would it be difficult? I’d image it would, but isn’t that what Apple does? They find unique solutions to difficult problems.

Oh, how about creating a professional level display that is also a touchscreen and is on a swivel like the new Microsoft Surface Studio? Why not make it a standalone display that connects to one of these new Mac Pro bases and could also be used with a MacBook Awesome? Super high end stuff.

Apple has billions in the bank. Why not go out on a limb to advance computing down some crazy road with a small group of dedicated hardware, software, and design professionals targeting professionals?

Look. I’m not the ultimate target of such specialized hardware. It would be professionals making movies and dealing with big honking problems. As an iOS Developer I’m fine with a laptop, but I’d sure like to see Apple strike out to create something truly wonderful. Something that changes the computing game, again. This time in the favor of professionals.

Wouldn’t it be cool if they’ve been doing this all along and they just haven’t finished? That would be awesome.

I know this isn’t the type of thing Apple does, but look at what’s possible.

Here’s the Acer Predator line of gaming laptops. Extreme? You bet. But all the same, super powerful portable computers.

How about Project Valerie?

Beloved Hedwig.I’m sure a lot of the loudest of critics would pick these apart: “Oh, they’re too heavy”, “They’re ugly”, blah, blah, blah. Sure on all points. But they’re high performance devices from people thinking outside of the box. They’re not constrained by “Lighter and thinner” at all costs. Imagine what Apple might be able to do if they were willing to make something a bit heavier. Maybe they could so something really special. I don’t think we’ll ever find out. I have a feeling Apple is going to keep making the Mac thinner and lighter until they are so close to the iPad the Mac no longer matters.

Then Apple will stop selling the Mac.

Passion Project: Update #2

Back in November I talked a bit about my passion project. I’ve rewritten the Pharmacokinetics Math library for RxCalc in C++ and I’m rewriting the UI completely in Swift. It’s been a real blast. My November update talked about bringing C++ and Swift together with a tiny layer of Objective-C++.

Over my holiday break I didn’t code as much as I wanted to, but I did manage to get some done. Since returning to my day job I’ve felt a bit more excited about working on the RxCalc update at night. I don’t know why, I just have.

I now have the new mixed Swift, Objective-C++, C++ based app in a working state, but I have a lot of polishing to do as well as adding some new features. Of the remaining 1.x features I have to implement is Options. Once that is complete I’ll move on to adding IAP, Theme, and 3D Touch support.

I really love working in Swift. The code base feels so tiny compared to its Objective-C counterpart. Not that Objective-C is bad, just different.

Next up? The Android version. For that I need to spend some quality time with JNI.

I’m not in any shape to ship this release, but it’s getting close by the day.

Passion Project: Mixing C++, Objective-C++, and Swift

I know a lot of folks have had to go through the process of bridging to C++ so you can use it from Objective-C or Swift. In my case I’m using it from Swift, so I thought I’d share what the middle Objective-C++ layer looks like. If you’ve done any Objective-C it will look like straight Objective-C, until you look a little closer. That’s when you’ll notice a C++ namespace, new, and delete statement. This code is a straight passthrough to the underlying C++ code — it’s here so Swift code can communicate with the C++ code.

Here’s the code that bridges to our Creatinine Clearance calculation.

https://gist.github.com/Fahrni/ed5c386bec659985b439306ac67cabd3

You’ll notice a class called PKMConvert that has a class method called genderFromPKMGender. I created a set of mirror enums. One on the iOS side the enums use NS_ENUM syntax, on the C++ side they’re straight C style enums, so this code converts between the two. It’s just a simple mapping.

Another thing you’ll notice is I’m still using “old” C++ syntax to create and destroy objects. I’ve been thinking about updating the syntax to C++11 so I’d use unique_ptr instead. We’ll see if that happens. It’s not a big deal.

Something I’ve been mulling over is releasing the entire PKMath C++ Library as an open source project once I have it working for iOS/Mac, Android, and Windows. I don’t know that it would be overly useful for anyone, but there you go.

Since I haven’t actually written any Swift code in the new RxCalc to use the Objective-C++ code I thought I’d share one of my unit tests for the Creatinine Clearance example above.

https://gist.github.com/Fahrni/423d34cc900679ff35f4bf99c9d0a778

Here’s how the different layers look from 30,000 feet. I like pictures, don’t you?rxcalc2layers

The Omni Group and The App Store

The Omni Group: “The app is now a free download. When you first run the app, you’re asked whether you’d like to start a trial or purchase a license. But before you purchase anything, we also explain that discounted pricing is available to existing Mac App Store customers. If you check for discounts, validating your previous install, we either offer you discounted upgrade pricing (50% off) or—for recent purchasers—a completely free upgrade to the new version.”

This is a significant breakthrough. The App Business is a tough nut to crack, especially with millions of competitors in the store. Couple that with the lack of trials and it’s very difficult to keep a business afloat. The Omni Group happens to be a longtime developer of Mac Apps so they know what’s at stake. They create beautifully designed and engineered software at a fair price for Mac and iOS. They’re one of the best in the business.

Until now only really big companies have been able to provide what could be seen as a trial. Microsoft and Adobe are so large they setup subscriptions for their software, think Microsoft Office 365 and Adobe Creative Cloud. While Omni is definitely one of the big players in the Mac and iOS market they’re still a very small company. With this move it finally appears that Apple is relaxing their stance on trials a bit. For productivity software having the ability to use a trial that creates meaningful output and becomes a read-only viewer after a period of time is huge. This will give folks the time to create some drawings, kick the tires, and decide if they really want to purchase OmniGraffle. Brilliant!

Old C++ Code

I was inspired by a recent post by Brent Simmons to write about some ancient C++ code I wrote back in the min-90’s. At that time I was just learning to develop Windows applications in C and C++ was just starting to get some traction, not unlike Swift in the Mac and iOS community today.

When you created a Windows application you’d have to write a WindowProc (Windows Procedure) that would process all messages for a particular window. A Window Proc would receive a message and other parameters. You’d switch on the message and the WPARAM and LPARAM parameters would contain other information specific to a particular message. It was well documented, but it was quite ugly.

https://gist.github.com/Fahrni/cca128a6862d85d5a3c1eafcc077a531

Believe it or not this is how a lot of your favorite Windows applications were originally written. Giant switch statements that dissected two other values to determine how to respond to different types of messages.

When I started learning C++ I was trying to find a way to create a Window Proc that didn’t have to implement every Windows message in the system, there must be thousands of them. Could you imagine a base C++ class that responded to every Windows API message in the system? I can’t. It would be a real mess to deal with.

It took me quite a while to come up with a way to do it. I happened upon the answer in the C++ FAQ. This would allow me to create a base class that provided one Window Proc that would look in a dispatch table (a map) to see if the Windows Message was handled by the Window in question.

Here’s what it looked like. I hope this gets the point across.

https://gist.github.com/Fahrni/6578d38cd5ac6725133f635d9b6cd690

When you implemented a Window Proc class you would derive from a base class and provide it with a message dispatch table (at the top of the above gist.) The dispatch table would direct the base classes Window Proc to call the correct handler for a specific message.

https://gist.github.com/Fahrni/5a58f52c8c43eb3de2c5872fa7c696a2

Notice that this Window Proc is a straight C function. That’s how the Windows API operates. It’s a C based API, but it provides a mechanism to attach user provided data to a Window Procedure. That’s how this operates. When the Windows WM_CREATE message is sent it includes a this pointer to derived Window Class, which can be looked up later based on the HWND identifier.

In the gist above the code that calls pWindow->DispatchMessage knows how to look at the dispatch table and direct the message to the appropriate pointer to a method.

https://gist.github.com/Fahrni/4ce26f04e831513b830574da00ce6ef2

The code that knows how to send a message to a particular method is (this->*pHandler)(wParam, lParam). This is dereferencing a pointer to a method. All methods have the same signature, which is consistent with how the Windows API works.

Will Code C++ for Food
By the way. This code still builds and runs with up to date versions of Visual Studio on Windows 10. A lot of this code was written in 1995 and has been tweaked over time to keep it up to date with changes to the Windows API.

As I’ve said before, old code never dies.

If you’re feeling really brave you’re welcome to grab my crusty old C++ library and build the simple sample application on your Windows box. Please note, the code is provided as is without warranty, expressed or implied.

WWDC 2016

It’s always interesting to read the WWDC tea leaves based on the imagery used on the web site. This year we got a poem and some Swift code.

WWDC 2016 Poem

The Swift in this picture is interesting because we can see they’re calling learnAbout with OSX, not macOS or MacOS as the rumor goes. I suppose they couldn’t give it away even if they were renaming it, could they?

WWDC 2016 Poem

Code is poetry

As much as I’d love to attend I won’t be able to. Dropping somewhere between $3-5K for a conference is tough to justify. I will say it is amazing and I’d love to be there all five days.

At this point I’m hoping to make it to The Talk Show Live once it’s announced, if I can manage to score a ticket.

Maybe I’ll see you there.

Mobile Cross Platform in C++

Will write C/C++ for foodPSPDFKit Blog: “PSPDFKit started in 2010 as an iOS-only project. Back then there was just one person working on it. 6 years later, we’re 28 people, have frameworks for iOS, Android and the Web, and our core framework even runs on OS X and Windows.”

Great piece on cross platform development using C++ and a tool from Dropbox called Djinni to help make things look native.

I’ve been toying with the idea of making RxCalc run on Android and the first thing I want to do is rewrite our Pharmacokinetics Math Library (PkMath) in C++, which ironically began life in C++ and was ported to Objective-C.

Regarding Style

RibbitAs I’ve gotten older my coding style has evolved. I’m a fairly verbose coder which can drive some people absolutely crazy but it works for me. It makes code more readable.

Case in point. Something I get questioned about all the time is why do I write false if conditions like this.

if (nil == thing) {
    // Create a new thing
}

Instead of doing…

if (!thing) {
    // Create a new thing
}

Well, that’s easy. My eyes can pick it up instantly. One other thing about that syntax. It’s a hangover from over 20 years of writing C and C++ code. The compiler will bark if you try to a value to zero. In that way it served as a way to make sure you didn’t accidentally make a mistake that could take a while to find. Let the compiler help you where it can.

I really like it more for readability. Opinions vary.

It doesn’t matter

Medium: “It surprised me to find that the vast majority of the apps in the top 100 are still building without any Swift.”

This shouldn’t be a surprise. In the end nobody cares what language you use to build your app, especially if it does what you want, performs well, and has a good design. 

Some may say I’m an old guy, so I shouldn’t be taken seriously. I will tell you this. If it ain’t broke, don’t fix it. That’s the proper attitude to have when developing software. I’m not saying you should never rewrite a section of code. On occasion that’s necessary, but if code works and doesn’t need to be touched as part of a new feature, just let it ride. You’ll be fine. 

In the end it just doesn’t matter.