Tag Archives: Android

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.

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.

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

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.

Native Development on Windows

Yesterday I asked on Twitter…

I got one serious answer and some fun poked at the question, which is fine, but I think it points to a real problem on the Windows Desktop. 

Has Microsoft given up on native applications at a time when native on Apple Platforms and Android have never been more popular?

On Apple Platforms we have clear, well defined, native development tools for creating serious desktop applications. Think of apps like Photoshop, or more modern takes on graphics like Sketch, Acorn, Pixelmator, or OmniGraffle. Most of these applications are written in Objective-C against Cocoa (Apple’s Framework for writing applications.) Sure, Photoshop is the old guy in the mix and is built on a custom framework written in C++ that communicates down to Cocoa (and possibly some Carbon API’s?) also worth noting, with the exception of Photoshop, not a single app mentioned above is cross platform (I’m not including Mac to iOS as cross platform, many of the API’s are the same and the act of going from one to the other is much easier than going to a completely different platform.)

All that brings me back to the question of developing native applications in the vein of Visio or Photoshop on the Windows Desktop. I’ve seen plenty of talk about creating Universal Apps, but those seem geared toward a lighter weight style of application, singular purpose apps focused on lightweight tasks, like Twitter or Facebooks clients, not hard core productivity applications that need to perform well and provide their best experience on the Desktop.

We still have Visual Studio, C++, and the Windows API, as a development platform but it feels somewhat abandoned. I know the folks working on the C++ compiler would probably argue against that statement because Microsoft is definitely investing in C++, but what about OS level API’s? That is the level that sort of feels abandoned. We have WinRT today, which seems like it might be part of the story for native desktop development, but do you mix and match that with the Windows API to build a great native application, do you use WinRT alone, or do you just continue to plug away with the Windows API?

It seems that apps built for the modern Metro look should use WinRT? Based on that it seems the old tried and try combination of C++ and the Windows API would still be the best choice for hard core desktop development.

But what about C# and XAML? Maybe those are a good choice for serious desktop development? I’m unclear on that subject. I’ve heard that the Visual Studio IDE was rewritten in C# for Visual Studion 2012, but I don’t know if that’s true or not. If someone reads this post and can point to MS Office, Visual studio, or Photoshop class applications written in C#/.NET I’d love to hear about them. Worth noting is the wonderful toolset by the folks at Xamarin, it makes C#/.NET app development truly cross platform.

Being a long time C++/Windows API guy I still gravitate toward that toolset. Hey, I have a lightweight class library I wrote in 1993-94 that still works today; it builds with Visual Studio 2015 and runs fine on Windows 10, but it could certainly use some refactoring given the state of modern C++. Think C++14.

I’ve been working on a cross platform project recently using Qt, which has me think about portable C++ for Mac, iOS, Windows, and Android. Given C++14 as a starting point for most OS level services; file I/O, threading and synchronization, etc, what would it take to build a modern C++ library that handled native user interface creation and interaction and didn’t feel too constraining on the platform? Remember, most cross platform tools come at a price. They’re always a little behind, they tend to be least common denominator, and can feel non-native. Qt, for instance, doesn’t use native controls on Windows (NOTE: this may not be true today. This was true around 2008, the last time I looked), I find that terribly annoying. I’m sure any Mac, iOS, or Android developer worth their salt would also find it annoying. 

A nice new C++ framework for building native OS level user interfaces using modern C++ as a base would be great to see. I really wonder how long it would take to build such a thing?

Larger Phones

Jerry Fahrni: “The size. I’m not a fan of large smartphones. The Moto X has a 4.7-inch screen while the S5 has a 5.1-inch screen. This is more personal preference than anything else. It’s all about how well it fits in the left front pocket of my jeans.”

My brother recently had to replace his Moto X. He chose a Samsung S5 because, apparently, the Moto X is no longer available. It’s a really nice device, but like him I’m not a fan of larger devices. It really comes down to fitting in my pocket and how it feels in one hand.

I’m happy with the 4-inch screen on my iPhone 5C, and I could see going as large as 4.7-inch, Jay’s Moto X felt great in hand, but over 5-inches? Now we are approaching tablet size.

If you pay attention to Apple rumors, which I don’t, you’d hear talk of Apple releasing a 4.7-inch and 5.5-inch device. This definitely doesn’t sound like something Apple would do, but Apple has been doing very un-Apple like stuff recently.

My hope? I hope they don’t go to a 5.5-inch device. That is extremely large. If you want something that big, buy an iPad Mini, it’s only 7.9-inches.

Facebook Apparate

Harry Potter, boy wizardWired: “Facebook Home doesn’t even have to be a hit. At least not right away. The important thing is that it’s out there, and it didn’t require a lot of up-front capital or R&D investment in hardware. It’s a better strategy than anything else the company has done in mobile. People who already really like Facebook will also like this. For people who live in Facebook, it may even drive them to buy one handset over another. Sometimes mediocre is all it takes.”

Whether or not you find Facebook Home mediocre doesn’t really matter. They’re going to sell a metric crap ton of these things. It’s beautifully designed and will give most people what they want; instant, always on, access to Facebook. Brilliant.

Amazon and Android sittin’ in a tree…

TechCrunch: “It’s called simply the “Amazon Kindle”. But it’s not like any Kindle you’ve seen before. It displays content in full color. It has a 7-inch capacitive touch screen. And it runs Android.”

I’m pretty sure Amazon is pulling a fast one on Google. If they do what I suspect they’re doing they could take over the top spot in the Android OS space, ahead of Google. Yes, I think they could do it. They have their own Android store, they have the selling power of the Amazon and Kindle name. If they focus on creating a great user interface and experience on top of the Android OS why can’t they be the leader? Android is dying for someone to create an iOS, or even WebOS, experience.

Why not Amazon?

Choosing a good backup phone

Tested: ” If you want to save a little cash, and maintain your freedom, you can always pick up a used Android phone on eBay or Craigslist. Since you would be getting this phone second hand, warranties are of little use. You need to make sure the handset is as described. That guy on Craigslist probably doesn’t take returns.”

Having a nice GSM based Android phone as a backup isn’t such a bad idea, especially if you’ll be traveling to Europe.

Is Apple Big Brother?

Alex Levinson: “I don’t think that’s a legal battle Apple wants to face considering the sale of over 100 million iDevices worldwide. That raises the question – how is this data used? It’s used all the time by software running on the phone. Built-In applications such as Maps and Camera use this geolocational data to operate. Apple provides an API for access to location awareness called Core Location.”

No, Apple isn’t “Big Brother”, that’s the government’s job. Go read the article, it’s very good, and gives you the truth about how the data is used, including this nice little nugget.

“Apple is not harvesting this data from your device. This is data on the device that you as the customer purchased and unless they can show concrete evidence supporting this claim – network traffic analysis of connections to Apple servers – I rebut this claim in full.”

Oh, and yes, Android devices do something similar.

If you have an iPhone and would like to create a map of the places you’ve been, there’s an app for that.

Dave Winer on his Nexus S

Dave Winer: “And the Nexus has a light, cheap plastic feel to it. For a $600 piece of hardware that has to compete with the iPhone, it should have some heft, some gravitas. It has none. Seriously. It feels a bit like a McDonald’s happy meal toy, compared to the iPhone 4 which has a unique feel to it, not like anything else, and seriously interesting. You just like to hold it. It sounds so flakey, but it’s true.”

Dave chose an unlocked Nexus S for his trip to Europe. These are his initial, out-of-the-box impressions. He’s been an iPhone/Droid user for quite while. The Nexus S will grow on him, I’m sure.