I recently made the jump into Android development to see what it was about. To give a little bit of background, I have been a user of Apple products my whole life. I’ve used an iPhone since the day the original one was released. Does this make me biased? Probably. That said, Java was one of the first languages I learned in high school. By comparison, I’ve only worked with Objective-C for two years and Swift for one.
This is an article listing first impressions of Android development as an iOS guy, not a definitive critique on everything wrong with Java and Android. If you are an iOS developer, you will probably notice these things right away when you make the switch.
Strings are Stored in XML Files
As annoying as it may be to instantiate a resource string from an XML, it is actually a wonderful convention that forces the developer to write better code. Many programming books will tell you to never hardcode your strings and instead refactor them out to global variables. This takes it a step further and moves it into swappable resource files, making things like localization incredibly easy. As an iOS developer, you should be using NSLocalizedString for every user-facing string, but it’s all too easy to hardcode the string and pretend you will never want your app translated into another language.
Square’s Picasso Framework
I’m jealous that image-asset loading could be this easy in Android. Loading thumbnails into a table view is incredibly straightforward, and I almost feel inspired to write a similar framework for iOS. It certainly beats having to explicitly decode the received bytes into an image, then asynchronously resize and set the new image into the appropriate ImageView, something I’ve done many times on various iOS projects. Picasso also has a built in caching system so you can write it and never worry if you’re doing something horribly inefficient. Interested in using Picasso in your next project? Take a look.
Lack of Blocks as Method Parameters
Yes, every good programmer will tell you that you should strive to use the conventions of the language you’re using rather than the conventions of another language you are more comfortable with, but this is one trait of Java (or more specifically, pass by reference design) that I found rather irksome. Simply put, passing in a block of aysynchronous UI code as a parameter of a network request is sexy, and Java doesn’t want any part of that. Anonymous classes will almost get you there, but it’s still not nearly as efficient or elegant. Strangely enough, Objective-C blocks and Swift closures seem completely beyond the imagination of many pure-Java developers I know, almost like attempting to envision a new color they’ve never seen. If only they knew.
Lack of “Storyboards”
There was once a time I staunchly opposed storyboards for iOS development. “XIBs are ultimately more functional and powerful,” I would tell myself. Then I actually tried using one in a project.
For developers that have never had the pleasure of working with them, imagine you had one big GUI editor for all those resource layout files you built, all in one screen. User-flow is clearly defined by arrows that point from one activity to the next.
I don’t know if there are any plans to introduce similar Android functionality. I certainly know Android Studio and the like won’t have anything similar to Xcode until such functionality exists. What I used to ignore soon became a necessity in my iOS development, and it’s sad to not have something like it in Android.
Ternary Operators Only Work With Assignment
If you’ve never worked with a ternary operator, here’s your chance to learn. It’s one of the most elegant syntax structures ever devised:
amount = (a > 0.0) ? a : 0.0
In this example,
a is checked if its value is greater than zero. If so,
amount is set to the value of
a, otherwise the value of
amount is set to
Ternary operators work great for setting default values to variables if the intended assignment is somehow invalid. They also happen to be really useful for one-line if/else control-flow statements.
(isValidThing()) ? doTheThing() : doSomeOtherThing()
Well, except you can’t do this in Java. Only the first example written above.
It’s unfortunate, but it’s Java’s syntax. Ternary operators must assign something.
My knowledge of Android is still rather limited. One does not even begin to get really comfortable with a framework or language until around the sixth month mark. Ultimately Android and Java are just another an ecosystem that is perfectly valid, and shouldn’t be condemned. To become an Android developer I must think like an Android developer. Nothing more, nothing less.
Although really, ternary operators. Come on.