Thoughts on RestKit

by Tom Bennett

I had the opportunity to use RestKit recently, and wanted to quickly post my thoughts.

RestKit is a handy framework to easily convert JSON or XML data obtained from a REST endpoint (the ease of use can be seen in this tutorial. In addition to converting a JSON response into actual objects, the framework offers caching via CoreData. Really great stuff. There's one catch though: RestKit relies on old version of AFNetworking, version 1.3.3 or so. As a result, using RestKit prevents an app from taking advantage of AFNetworking 2.0. I think for many this would flat out be a dealbreaker. While the developers are supposedly working on this, I haven't really heard anything regarding their current progress, so I wouldn't bet on seeing it emerge any time soon.

In summary, RestKit is a great means of transforming a REST response into actual objects you can use in code; but if you plan on using AFNetworking 2.0 (and if you're considering RestKit, you probably should), the dev lag makes this a non-starter.

Source: http://restkit.org/

Balancing Line Length And Font Size In Responsive Web Design

by Tom Bennett

Interesting piece discussing making written content legible on the web, with a particular focus on scaling on mobile devices (the same advice can easily be extended to apps). The article touches on something that is too easily ignored: line length.

If a casual reader gets tired of reading a long horizontal line, then they’re more likely to skim the left edge of the text. If an engaged reader gets tired of reading a long horizontal line, then they’re more likely to accidentally read the same line of text twice (a phenomenon known as “doubling”).

65 characters (2.5 times the Roman alphabet) is often referred to as the perfect measure. Derived from this number is the ideal range that all designers should strive for: 45 to 75 characters (including spaces and punctuation) per line for print. Many web designers (including me) apply that rule directly to the web.

Basic advice: optimize the font size for legibility, then fine tune the line measure. Bonus tip: keep line height at 150% the font size.

Swift has reached 1.0

by Tom Bennett

Swift version 1.0 is now GM.

You can now submit your apps that use Swift to the App Store. Whether your app uses Swift for a small feature or a complete application, now is the time to share your app with the world. It’s your turn to excite everyone with your new creations.

Android Performance Tips

by Tom Bennett

While getting ready to write a new Android app, I decided to see if there might be any neat tips and tricks in the Best Practices section on the Android developer site. Boy was I not disappointed! I've only reviewed 2 sections so far, those on Performance and Memory Management, but I'm eager to tackle the rest. The following are some choice tidbits from each.

Note that these tips are specific to Android, and might not be ideal in other environments (due to differences in the JVM or platform considerations).

Performance Tips

Prefer static over virtual methods

If you don't need to access an object's fields, make your method static. Invocations will be about 15%-20% faster.

Use static final for constants

The optimization itself applies only to primitives and Strings, although it's generally best practice to make constants as such.

Getters / setters

Without a JIT, direct field access is about 3x faster than invoking a trivial getter. With the JIT (where direct field access is as cheap as accessing a local), direct field access is about 7x faster than invoking a trivial getter. Note that if you're using ProGuard, you can have the best of both worlds because ProGuard can inline accessors for you.

For loops

This one really surprised me:

With an ArrayList, a hand-written counted loop is about 3x faster (with or without JIT), but for other collections the enhanced for loop syntax will be exactly equivalent to explicit iterator usage.

In the following code, "the JIT can't yet optimize away the cost of getting the array length once for every iteration through the loop":

public void zero() {
    int sum = 0;
    for (int i = 0; i < mArray.length; ++i) {
        sum += mArray[i].mSplat;
    }
}

Be mindful of private access with private inner classes

To summarize, when a private inner class tries to access the private member variables of the containing class, the compiler generates some synthetic, static methods to wrap member access. This is because, while legal, the VM considers one class assessing another class' private members to be illegal. As mentioned earlier, using a getter / setter can be 3x - 7x slower than direct member access.

Managing Memory

Release memory when your user interface is hidden

To be notified when the user exits your UI, implement the onTrimMemory() callback in your Activity classes. You should use this method to listen for the TRIM_MEMORY_UI_HIDDEN level, which indicates your UI is now hidden from view and you should free resources that only your UI uses.

Notice that your app receives the onTrimMemory() callback with TRIM_MEMORY_UI_HIDDEN only when all the UI components of your app process become hidden from the user. This is distinct from the onStop() callback, which is called when an Activity instance becomes hidden, which occurs even when the user moves to another activity in your app.

Use optimized data containers

Take advantage of optimized containers in the Android framework, such as SparseArray, SparseBooleanArray, and LongSparseArray.

Be aware of memory overhead

Enums often require more than twice as much memory as static constants. You should strictly avoid using enums on Android. Every class in Java (including anonymous inner classes) uses about 500 bytes of code. Every class instance has 12-16 bytes of RAM overhead.

Source: http://developer.android.com/training/best...

Markdown has a standard

by Tom Bennett

Interesting to see that 10 years after John Gruber came up with Markdown, there's only now any sort of standardization. Standard Markdown was just announced today. As someone who uses Markdown for just about everything (notes, presentations, blogs), I'm definitely glad to see this happening.

Edit: It looks like this was done without the blessing of John Gruber. Until things clear out, I'm removing any links to "Standard Markdown." I'm also fixing my earlier mistake of not linking to either John's site, Daring Fireball (which I read religiously), or his page dedicated to Markdown.

In depth piece on data theft

by Tom Bennett

Nik Cubrilovic has a great, in depth piece on celebrity data theft. Considering how much data everyone stores online these days, it's probably a worthwhile read for everyone. Of particular note how these accounts are compromised:

  1. Users who scour Facebook and other social media looking for targets and collecting as much information as possible. Data collection includes utilizing public record services and purchasing credit reports. Obtaining data on a target includes setting up fake profiles, friending or following friends of the target, being persistent with extracting information that might help answer secret questions, approaching male friends of the target, etc.
  2. Users who use the target data to retrieve passwords or authentication keys. There are numerous methods here and most have tutorials available online. The most common are RATs, phishing, password recovery and password reset. RATs are simply remote access tools that the user is either tricked into installing via private messages or in an email (link or an attachment) or that someone close to the target will install on their phone or computer with physical access. Phishing is sending the target an email with a password reminder or reset that tricks the user into entering their password into a site or form the attacker controls. Password reminder is gaining access to the users email account (again using secret questions or another technique) and then having a reminder link sent to access the cloud storage. Password reset is answering the date of birth and security question challenges (often easy to break using publicly available data – birthdays and favorite sports teams, etc. are often not secrets).

It's not simple brute force and phishing, but also a system built upon social engineering. Recall that password reset was how Sarah Palin's email was broken into years ago. It's fairly trivial, especially given how often those "password secrets" can be answered by a quick look at someone's Facebook profile.

I guess take this incident as a reason to consider how much personal data you're putting out there, and if it could be used against you. I know I immediately went to Facebook to double check some privacy settings and outright remove some data.

Mike Ash on interesting Swift features

by Tom Bennett

Mike Ash posted a few weeks ago on Interesting Swift Features. If you haven't been paying too much attention to what's going on with Swift, this is a good overview of what's unique about the language. While not much is truly novel in Swift, many of the language features will be new to someone coming from a pure Objective-C, Java, or C background. Moreover I think it's rather unique to see all of these features in one language.

In his post, Mike touches on:

  • Explicit Optionals
  • Generics
  • Tuples
  • Type Inference
  • Trailing Closures

Trailing closures certainly help improve the legibility of code, and I'm excited to finally work in a language that allows for multiple return types. However, I'm most interested in seeing how optionals play out. At a surface level I think they're a great idea, and I'm very happy to see optional chaining is a thing since you can't simply pass a message to nil.

The next year or two will certainly be an interesting one for iOS developers, that's for sure.

Objective-C

by Tom Bennett

I've been brushing up on my Objective-C lately, and want to share some really valuable resources I've come across.

First, I highly recommend users new to the platform read Objective-C Programming: The Big Nerd Ranch Guide. Despite dabbling with the platform for years now, I still learned quite a lot.

Build Settings

  • Enable Analyze During Build
  • Make sure to treat all Warnings as Errors

Blogs, Podcasts, etc

Coding Style

Again, be sure to read this if you're new to the platform. Are you prefixing your classes to avoid namespace clashing?

Personal Finance

by Tom Bennett

Last year was the first time I seriously took a look into how I was spending money. Considering I was 26 and working professionally for 3 years, it was a pretty sad state of affairs. Something so rudimentary should certainly be taught in high school, particularly since timing can be so crucial when planning for retirement, college, wedding, etc. Anyway, I wanted to take some time to distill what I learned in case someone else finds themselves in the position I was in.

Probably the most important thing to consider is retirement. It's easy to neglect retirement when you're young, but compound interest and the volatility of the stock market really favors long term growth. Saving for retirement might seem like a daunting task, but it doesn't have to be. 

If your employer offers a 401(k) plan with a match, at the very least make sure to meet that. Otherwise you are literally walking away from free money. Once you have that met (or if your employer doesn't offer such a plan), focus on maxing out a Roth IRA. You can open up a Roth through the same company that handles your 401(k), or you can shop around (I'm personally a fan of Vanguard). The key difference between a Roth IRA and a 401(k) is that a Roth grows interest free. In other words, the interest you earn in a 401(k) will be taxed when you withdraw it in retirement, whereas interest from a Roth is not. I should also mention that 401(k) contributions are made pre-tax, while Roth contributions occur after taxes are taken out. 

Once you have money in a retirement plan, you need to make sure to invest it! The easiest approach is to invest in a lifetime fund, which automatically adjusts asset distribution (percentage of stock, bonds, international stock, etc) over time. Lifetime funds are generally named after the year targeted for retirement (for example, I use the Vanguard 2050 since I expect to retire around 2050 at the age of 65). It might sound silly, but in college I let the money from an internship sit in a money market fund, which means it wasn't really making anything at all! You are free to come up with your own asset allocation you can tweak, but a lifetime fund is by far the easiest to setup and maintain.

Of course, retirement is only one of many expensive events in a persons life, and it's important to save for those too. I've always been far removed from the idea of marriage or purchasing a house, but once those events become real, it's already too late to save. Consider that the average wedding costs $28,000, or that a house generally requires 20% deposit. I've found it far better to save monthly for these events so that I'll be ready if and when they happen, rather than end up in a lot of debt. Worst case, I end up with a lot of extra money that I could use to retire early, start a business, tour the world, etc. 

The sort of funds to invest in for these sorts of goals is tricky though, since the timeline can vary wildly. If you're already in a long term relationship and marriage seems like a possibility in a year or two, stocks aren't really a viable option due to volatility. But if you're like me and don't have firm plans on when to buy a house, then you can be a bit risker and work around stock market fluctuations. The key thing is to make sure that you're saving monthly; what specifically you invest in can be determined later.

While the goals I've mentioned up until now have been fairly long term, you should still consider short term goals as well. My favorite savings goal is $5,000 a year for an international vacation. Since the event is such short time, I put all of those funds into a savings account dedicated toward that goal. This way I can easily see the progress I'm making, and those funds are separated from my emergency fund and checking account. 

Now for some closing notes. Make sure you have an emergency fund! This should be about three to six months of expenses that you can rely on in case something unpredictable happens, like losing a job or necessary car repairs. Don't use this for items that you're aware of ahead of time, those you should be saving for! 

Note that I mentioned that your emergency fund should consist of your expenses and not salary; this implies that you should have a budget and should be living within it. If you aren't already using Mint to track your spending habits, I highly suggest you start doing so now. It's a painless way to track spending, and it even allows you to construct a budget based on your historical spending habits. If the idea of saving so much money seems impossible, I really recommend using Mint to inspect your current spending habits and see if there are some easy wins. Perhaps you're spending more than you expected at the bar, or your car is a bigger percentage of your take home pay than you thought.

When it comes to investing, I advise against individual stocks, and highly recommend index funds. While individual stocks seem like the best way to make a lot of money, you really only should invest in them if you're very familiar with the company, its competition, and its future economic prospects. You should be investing long term; otherwise you'll need to spend a lot of time and effort staying abreast of new information and developments. Comparatively, an index fund requires little management from the individual investor since its tied to the stock market. Trying to beat the market is difficult and costly, while a solid index fund with low fees can still reap rewards. 

Recommended Reading:

Books:

Websites:


More posts incoming

by Tom Bennett
This year I broke a long standing tradition and created quite a few new year resolutions. One of these resolutions was to write more frequently, aiming for something once a week. While I'm not quite sure what exactly the end product will be (thoughts on programming languages? creative pieces of fiction?), I do know that I want to act now to make it into a habit. As such, I'm going to start with just random musings that I will then post here. No guarantees on content, just whatever happens to be on my mind that particular week. Here goes!

Net neutrality

by Tom Bennett
Upon finding out that AT&T was encouraging employees to complain about net neutrality, I felt compelled to leave my own comment on the FCC's net neutrality site. I was shocked to find more than half the comments (of the sample I read) going against net neutrality, and all of them written by people who clearly did not understand the issue. This riled me up a bit, and so I wrote my own entry and actually commented on some opponents' entries. I am very thankful for Comcast providing me ammo when doing the latter. Anyway, the following is the comment I posted to their site. I assume anyone reading this knows the internet is not a big truck, so feel free to comment.

It seems rather unfortunate, but a cursory glance at many comments would suggest many people against net neutrality don't actually understand it, nor how a network actually works. Without the FCC's intervention regarding Comcast's throttling of bittorrent traffic, many customers (likely forced to use Comcast since the local monopoly cable companies are allotted) would be not be able to use that particular technology. And while we can acknowledge that bittorrent is commonly used for pirating, it also has many legal uses, many which have not been fully evaluated. Net neutrality is important in maintaining no protocol or packet is blocked because the network owner disagrees with the content or the source.

However, I am uncertain if regulation would even be necessary if there were open access to network facilities (although I question if they must go hand in hand). As stated in this report, http://www.reuters.com/article/technologyNews/idUSTRE59E16J20091015, open access forced lower prices for higher speeds, areas the US could certainly use a boost (the fact that this nation is so far down the food chain despite inventing the internet and controlling ICANN is a disgrace, but I digress). Open access would also foster competition, thus making irrelevant anyone choosing to throttle traffic.

Regarding those speaking out against a certain "search engine" (please, we know you're attacking Google), you should note that Google Voice is not a telephony service. Google Voice acts as a forwarding (free, when used within the US) service between two pre-existing numbers. Users who have a number with Google Voice only attach that number to pre-existing phone numbers, and are serviced under those respective providers.

The one area I question net neutrality is with regards to wireless networks, due to the nature of wireless networks requiring broadcast communication, etc. Even in this regard though, I am willing to side with net neutrality, as any network provider whose network suffers (AT&T and the iPhone, perhaps?) should be forced to improve their network (innovating when necessary) rather than prohibiting their customers from legitimate uses.

Thoughts on Assassin's Creed

by Tom Bennett
I just finished playing Assassin's Creed (or, at least I think I did, more on that later) on XBox 360. At the moment, the thing that sticks out the most is the drastic change in core gameplay leading up to the end of the game.

While the game welcomes users to use stealth and strategy while playing, in general it's not always required. To some extent, I would actually say this was detrimental to the game, as I would occasionally make a mistake in the execution of an assassination, and then just swing my sword around to finish the missions. Not nearly as cool as jumping from the shadows, but I digress. The point which I am trying to expand upon is that, although Assassin's Creed expects some stealth, there are many opportunities to be a bumbling brunt and just battle hordes of guards. However, the emphasis is obviously placed on using stealth and crowds to sneak about on missions, and actually running away in order to avoid combat when caught.

Yet, for some reason, the last two assassinations actually force the user to just hack away at enemies - no alternative options are provided in which the user can use stealth. It is as if the user was playing a completely different game entirely. And while the crowd fighting can be entertaining, it is still buggy and not the reason I'm playing the game. And while I'm on the topic, I really hope to see sequels allow the user to manipulate enemies a bit more during fights. With such an emphasis on crowds, I very much expect to be able to push guards into each other.

Another aspect of the game I found disappointing was the use of beggars. Instead of providing a potentially useful ally (beggars assist you if you are kind to them) or attempting to teach some sort of useful social message, Ubisoft just presented an annoyance to users. I suppose that the developers actually did the opposite of the latter suggestion, as beggars did nothing good for me and I always had to shove them about. The worst part is that the user isn't presented with an option - the beggars want money, but Altair carries no currency. What's the point?

And now the biggest question with Assassin's Creed - what the hell happened at the "end"? I really must put in end in quotes there, as the only way I knew I had arrived at that point was when I researched my latest achievement. While I am usually a fan of stories where the audience must draw their own conclusion, the game offered nothing even approaching closure. At least in Matrix Reloaded I had a screen saying "To be continued." The ending offered was more on par with something I would see before a season finale - not quite so good when I'm expected to shell out another $50 in two years and dedicate another twelve hours.

I don't mean to be overly critical here, though. I think Assassin's Creed had many amazing technical feats: the large cities, massive crowds, and so many climbable surfaces are just a few. The game was also pure fun too, even with the frequent annoyances such as misguided throwing knives and a character who refuses to arm himself in combat. Yet, I feel the game could have been so much more if the dev team met it's promise of a city which responded to your choices. As for the game's story, I'm still not sure how I feel about the almost cliched approach it took. The betrayal of the master was obvious quite quickly, and so the conspiracy felt almost half-baked (although if there is causation there I cannot be sure). Here's hoping the sequel can patch up these issues.

ISPs are backwards in the US

by Tom Bennett
Loved this article I recently came across: Time Warner to charge $150-Per-Month Unlimited Internet. Whereas most industrialized countries have cheap 20 MB - 100 MB downstream internet connections, most Americans are lucky they even have the privilege to pay large sums for 6 MB down (personally, I usually see my 7 MB at 2 MB, but that's a different story).

The beauty of the whole thing is that American ISPs are trying to claim that their infrastructure is too poor to handle large data transmissions, and instead of improving their service to some reasonable standard, they leverage monopolies to punish the consumer. I guess the big question here though is it just a ploy to prevent users from using Video On Demand services such as Hulu and iTunes instead of their cable service? Considering how much cable costs these days, and all the profit the cable providers would lose if they watched their customers pull back, the conspiracy doesn't seem too far fetched. And if this is the case, I wonder what may happen to net neutrality in the next couple of years?

Regardless, these recent moves seem fairly futile, and I just hope something is done so the country that invented the internet can at least provide its citizens with some competitive speeds.

GDC Sessions

by Tom Bennett
While I wrote about my reflections upon GDC as a whole this year, I didn't really comment on any particular sessions. Truth be told, no session really stuck out this year like Creating a Character in DRAKE'S FORTUNE; instead, a collection of speakers sparked my interest and motivation to create games. So, which were they?

Clint Hocking's Fault Tolerance: From Intentionality to Improvisation showed a new flow to have in games, one in which designers stop punishing the player. This flow results from the user creating a plan of action, and then acting upon it over short periods of time, from one to the other. Most games break this flow by forcing intentional gameplay - the player dies and then goes back to some checkpoint. Improvisation suggests the user reflects upon what happen, how it changed the gameworld, etc (creating a new plan), and then acting upon it. While Clint suggested Bioshock accomplished this, I disagree in that the transitions could be smoother.

From CS to L4D: Creating Replayable Coop Experiences was interesting, well, for creating replayable coop experiences. This was likely a full sessions since it's a Valve design session, and rightfully so. The core idea behind the talk was simply force cooperation by punishing those who refuse to work as a team (using mechanics, not some force field, etc), while also creating randomness to break down the group on occasion. Fairly obvious, but I suppose the limited number of good co-op games establish how non-trivial this is (that, or companies are too lazy to change the status quo...).

I recall being disappointed with The Tech Behind the Tools of Insomniac Games, but in retrospective, hearing them discuss how their build system is pretty interesting for someone who has never worked in such large environments.

The GDC Microtalks had the highest idea/time value (not surprising since 10 talks in 1 hour). Jane McGonical's talk was, as always, inspiring and gave me some game design concepts. The topic(s) was/were CZADOF: Confucious Zombie Apocalypse Dance Off Fraction. To sum up, people have fun when doing good, which happens a lot when there's a zombie apocalypse, and enjoy themselves when embarrassing themselves with others. Clint Hocking attacked game review inflation, John Sharp reminded everyone that video games are nothing truly new given the history of games and play, and Eric Zimmerman presented an impromptu game questioning fun. One of my takeaways on Zimmerman's talk: impromptu games + a requirement to cooperate = willingness to open up with strangers.

The Beauty of Destruction was an interesting talk on some pitfalls and lesser known facts about C++ destructors. I found it enjoyable, but would have had a more rewarding experience if I was currently using C++ (obviously). Still, nothing like someone forcing you to question how your memory is managed!

Experimental Gameplay Sessions made me realize I sincerely need to stop criticizing current game mechanics and start prototyping my own. Big motivator, as I now have a goal to present something of my own next year.

State-Based Scipting in Uncharted 2, had a few gems. I was surprised to hear a decorator pattern was used instead of inheritance, although given the cost on the stack, function lookups, and the purpose of the pattern, I suppose it makes sense. Also nice to hear about the message passage system for "threading" events across multiple objects, where dependencies might occur. Really wish I could mod their games, if just to see how Lisp fits in.

And that was my quick explanation of what sessions I attended and thought were notable at this year's GDC. Unfortunately, I missed quite of few very interesting talks due to conflicts with other sessions (such as On the War Path: Tactical AI in Dawn of War 2) and had to order the recorded sessions on DVD.