Jul 1 2010

Naming Conventions – Why Your Code Sucks

I’ve seen a lot of poorly written and ugly looking code in my time. That’s not even considering the undocumented and uncommented code. We all know we should comment our code but how many of us do it consistently? I admit, when I’m in a coding frenzy, stopping to write comments just gets in the way of my thought process and can be distracting. I will however write a bunch of comments before I write the code, of the operations I think I need, in order to give me an outline of where I need to get to. For example:

// Get URL string for video file
// Load video file from URL request
// Load video file into video player
// Set up video player
// Play video

I may not know all the APIs to load and play the video just yet, but at least I’ve given myself an outline and as I fill in the code below each comment, I can see exactly what I’m doing and where I need to go.

Why Your Code Sucks

The point of this article is not to talk about comments, but how to avoid writing them in the first place within your functions and still be clear for everyone else, for the most part. This is your code:

newPlPt = crt2pl( nmc.x, nmc.y );

Not even a comment could concisely convey the meaning of that hideous statement. Instead, why not:

newPolarPoint = cartesianToPolar( newMediaContext.x, newMediaContext.y );

Well written code is self documenting. Let me restate that: if you can write code so that someone can jump to any point of that code and understand what’s going on at that point, read it like a sentence, and not have to decipher minute details like what each variable means, then you don’t have to comment most of your code.

There’s no reason you need to shorten the names in your code. Most programmers have never had file size limitations to deal with, so there’s no reason for it. Stop pretending you live in the 1960s and embrace nearly infinite file storage. To save keystrokes perhaps? Please, use a real IDE with code completion and stop doing stupid things like:

public function updateP( p:Player, d:MovieClip, b:MovieClip, t:Textfield);

Function Names

Also, because your functions are essentially actions, they need to reflect that in the name, so put a verb in the beginning of your function such as: getData(), setStatus(), enableWiFi(), hideControls(), handleGraphicException(), launchBall(), etc.

Class Variables

Get rid of the underscores in front of your class variables. For example: _dg; _myNumber;. All class variables should be private anyway, so why do you need that ridiculous convention? It’s a hold over from C where there was no “private” keyword, so you’re using it and you have no idea why.

Also, what’s with the “my” naming convention? You sound stupid when you have those: myInstanceName, myMovieClip, myGraphicsContext. Of course it’s yours, whose would it be, if not yours? If you’re programming with a colleague, do you refer to his variable references as yourInstanceName? Or hisVideoFileURL? Of course not. Don’t be that stupid; you’re reading too many stupid online tutorials by uncreative people who only code because they have nothing else better to do while living in their parent’s basement.

In the very least, be consistent with your naming conventions.

Hungarian vs. Polish notation

Depending on which language you’re coding in,  you may need to use a notation to help you with type casting. Let me rephrase that: if you’re using a loosely typed language, use Hungarian notation. You should probably use this with strongly typed languages anyway because with abstract types, you never know what you could get into and it’s just generally less confusing.

Hungarian Notation: vendorNameTextField or vendorName_txt

Polish Notation: txtVendorName or textFieldVendorName

Why not Polish notation? Not only is it ugly, but why would I sort on variable type instead of the variable name like I can do in Hungarian notation? The notation names come from how the speakers of those languages modify their verbs and nouns. To say: “My ball” in Hungarian is:  ”labdám” where “labda” is the root word and the ‘m’ singifies a first person possessive. Hence the ending of the word shows the crucial information. It’s the opposite in Polish notation where the beginning of the word is modified. In the interest of full disclosure, I love the Polish, but I am Hungarian, but I promise that’s not why I prefer one over the other.

Final Thoughts

In the end, be consistent, be clear and spell out your variable and function names.


Jun 27 2010

Corona Game Template in Lua

This is a template I threw together for the Corona SDK from Ansca Mobile. Since Lua is not a language most people are familiar with, I figured I’d throw together some sample code for Corona and share what I learned so far with the rest of the Corona SDK community by including the template here.

The template includes example code for:

  • Display groups
  • Orientation and accelerometer
  • Touch with buttons
  • File reading
  • Example level file for scripting game play

The template separates functionality into modules for an object oriented approach. I’m still learning the techniques for Lua, so if you notice a better way to do it, please don’t hesitate to let me know in the comments below. Some things in the template are not the best way to accomplish some things, but should give people a good idea on best practices of software design. This will also with work Corona’s Game Edition.

If you find the template useful, take a look at some of our current applications to support us. It’d mean a lot.

Download the Template Code

Also, check out the links on the side. Thanks!


Apr 14 2010

BarNinja – An iPhone App Postmortem

The BarNinja iPhone app is a mixed drink application with over 730 drink recipes with additional features including a random drink selector, bartending tips, powerful search, and a shots per bottle calculator for party planning.

The Beginning

As far as we could tell when we started the BarNinja iPhone app, there weren’t any other apps like it on the Apple App Store. That was back in April of 2009. While I was in San Francisco back in March, I got a Facebook message from Jason asking if I was interested in doing an iPhone app. I had done a bunch of Mac development and even independently sold a previous application. I had also attended Apple’s developer conference (WWDC) on two separate occasions so I was quite comfortable with developing for Apple products. When I got back from California, we sat down at a local bar in Blacksburg and wrote down our ideas for the app he wanted to make. That was prior to iPhone OS 3.0 being released and we were counting on some key features in that release for our app. In the end, we ultimately failed when the features didn’t work out exactly as we expected. Luckily, only a little code had been written and that was enough to get me up to speed with the current iPhone development platform.

Instead of quitting, we got BarNinja, another local Blacksburg startup involved in another app idea. We wanted to leverage the shake feature (iPhones can detect when you shake them) that was relatively new and make a mixed drink app based around that.

Soon after we started, a few other apps starting hitting the app store with exactly those features. But the competition didn’t deter us, but instead pushed the bar higher for us. We now knew we couldn’t just make another mixed drink app with a shaker feature, we had to make the best mixed drink app with a shaker feature. We were also creating a 730+ recipe database (including ingredients and other drink information) that would hopefully give us an added advantage. Luckily, at the last WWDC (2005) that I attended, they announced a technology called CoreData which allows developers to place small databases easily within their applications. They also included it in the iPhone OS and I ran with it.

Problems and Solutions

The problem with having 730+ recipes is that it becomes nearly impossible to find a drink in a list. The list view we had, took minutes to scroll through and even tired out your finger having to swipe so much! We added an index on the side to quickly scroll through the list alphabetically. We also added a search to find a drink by name and even added a filter to sort out if the drink was a “mixed drink” or a “shooter.” But that still wasn’t good enough.

I could find drinks like “Vodka Martini,” but what if I wanted a drink with vodka as an ingredient? So we added in a search that would find ingredients too. That worked out well, but often times vodka isn’t named vodka, it’s also names just “Absolut,” which everyone knows is vodka, but the iPhone doesn’t, so we had to teach it what kind of alcohol those products were.

More progress, and we were rolling right along until we tested it out on the actual device; it was painfully slow. The user would hit a key on the virtual iPhone keyboard and the key would get stuck in the “up” position until the search was done and only then could you hit the next key. Searching 730+ recipes is easy, but searching on average 6 ingredients for 730+ (~730 x 6 = a lot) takes 4 or 5 seconds on an iPod Touch 2nd generation. So we had to get a little creative.

My solution was to split off the search into a separate thread (a simultaneous process within the application) and perform the search in the background. This introduced a few other problems that I had to fix but the responsiveness improved dramatically. Then, using Apple’s performance tools, increased the search algorithm by about seven times. Thanks to all those boring Computer Science classes I took at Virginia Tech I was able to speed it up and also make it appear to speed up.

Updating the table view, after finding each recipe that matches the criteria, is slow (thanks to the performance tools for reminding me of this). So I returned the first 5 results instantly because those are the only ones you can see initially on the screen and then the rest were updated in a decaying frequency as they were found until the search was done.

Iteration

Early Search

Early Search

Icons, glass name and index

Icons, glass name and index

Early drink details view

Early drink details view

The Final Product

Initial Screen

Initial Screen

New search screen

New search screen

New drink details view

New drink details view

Results

They say if you’re happy with your 1.0 version of your application, you didn’t release it early enough. While we definitely have plenty of work yet to do on this application, we didn’t release it soon enough. It did not take a year of programming to get this done. The programming was the easy part, it was all the other stuff that got in the way, distracted me and things I had to wait on that took the longest. Back in the day, when doing my Computer Science homework, the motto was “Start early, and start often.” That rings true for every long term task.

We didn’t run any real usability tests. This upsets me a bit, but we never really got to show it to too many people. Now LTZ has a few more developers working on more apps, so we have a larger pool of testers, but in the end, we still need to test it out on real human beings and put all those Human Computer Interaction (HCI) skills I spent a lot of time learning, to use.

I did try to apply those skills with the layout of the app. When the app launches, the first screen is the random drink screen, which you can tailor to your tastes in the options. We wanted to give the person using our app something to do right away. We didn’t want to over whelm them with a list of 730+ ingredients; it doesn’t impress anyone. In our limited testing everyone figured it out and got a kick out of the shake feature. With other apps, we noticed, they presented a huge list of options that just left you wondering what you should do next. It’s that classic “uuuuh” moment. With ours, right after the launch of the app you can start enjoying the functionality.

The next screen is the raw list of drinks, plain and simple. Our search is straight forward and easy to figure out and the index on the right helps users navigate down the list quickly. We also stuck to using as many user interface elements from the standard set of Apple iPhone as possible. Many other apps try to be creative and diverge from the standard set of UI elements and consequently from the Human Interface Guidelines that Apple has set forth. The result is a poorly designed, clunky looking application that takes time to figure out how to use. Since we’re using a standard search bar, people using our app know right away what that means and can start right away in using the search feature.

We also chose a dark theme for our colors, not because it looks cool, but because most of our users, we assume, will be using it in a bar, or bar like conditions such as a party, etc. But we also didn’t want to give it a depressing theme since it was suppose to be fun and helpful, so there are a few bright colors in there. The design will most likely change and be updated, but that’s the rationale for the initial release. We’ll see what our users think and how they use the app.

We know our app isn’t perfect, but we’re confident we know where to go from here to improve it and fix some of the problems we know exist in it. Through additional usability testing, we’ll slowly improve upon BarNinja to make it the best drink application on the app store. We know we’re not there yet with the initial release, but we look forward to adding great functionality that people will love.


Apr 11 2010

What I’ve Been Up To

I’ve been crazy busy ever since we returned from Colombia. We fell back into life in the US at full sprint and have only had a few periods since where we could rest. As a result, I don’t think I’ve been clear on what exactly I’ve been up to with my family and friends. So here’s the short version of most of the major things I’ve been up to since getting back:

iPhone Development

We started a company last year to allow independent iPhone app developers to make the transition from “wanna-be” to published developer. The model works similar to a record label, where LTZ provides the leverage, so that developers can concentrate on coding rather than the logistics of getting apps out. We wanted to start small, get a few early successes and then use that momentum to gather a pool of developers. We’re also planning a Code Kitchen, which is a class to teach iPhone and Mac programming to anyone interested for free.

Most of our early time was spent on logistics, even though we had our first app idea right from the start. It was a lot of waiting; we waited for resources (copy, data, images, feedback), we waited for Apple, we waited for the lawyers and we waited for contracts. So in a year’s time, we finally had an application ready to release. But thankfully, most of that work won’t have to be completed again since the contracts, setup and other logistics are taken care of. I’ll post a longer article on the whole process (what it took, what we learned, etc), but as I type this, our app, BarNinja is “In Review,” waiting to go up on the Apple App Store. It still might get rejected (one never knows with these processes), but we’re hopeful that it will appease the Apple review gods. We’re also more hopeful that the app will actually sell well and we can get some money into the business so we can buy “test” devices, like the brand new iPad for all our people.

Scuba Diving in Blacksburg

As many already know, scuba diving is a relatively new thing for me. However, I instantly fell in love with the sport and have tried to progress as quickly as I can. It’s been a lot cheaper than flying.

I got my Open Water (OW) certification in November of ’08 (with dives in Cozumel, Mexico in December), my Advanced Open Water (AOW) in July of ’09 (with dives in the Florida Keys and on the US Coast Guard Cutter my grandfather served on in World War II), my Rescue Diver certification (that required another certification of Emergency First Responder) and now I’m working on my Divemaster certification, which is a professional level diving certification. As you can image, this has been a long journey, with a ton of training, reading, and diving. The diving part was especially difficult due to the location. Blacksburg is not known for it’s amazing scuba diving, but diving in the local river, which has a maximum depth of 41 feet, has made it a bit easier.

We should be able to finish up the divemaster certification in May of this year. That’ll allow me to help teach some classes with Scott, who runs Avalon Adventures here in Blacksburg and the New River Valley (NRV). He’s my current instructor and I’ve helped him out with his website. The plan is to serve Blacksburg, Christiansburg, Radford, and the surrounding NRV to provide classes, dive trips, dive refreshers and other adventures. Hopefully, we’ll also make some money in the process.

Music

I’ve picked up my guitars again. Sadly, I don’t think I’ve picked them up in at least six months, but I’m at it again. Luckily it only took me a few minutes to remember what those six months made me forget. I am also helping my old Computer Science instructor with his business at Rocket Music. It helps me get back into music, even though its on a strictly computer programming level. Just talking about guitars, buying guitars, customizing guitars and everything guitars reminds me to go pick up one of my guitars and practice, if for only 15 minutes.

Our Foster Dog

Our foster dog Petunia has really adjusted well with us. When we first got her, she had some problems with other dogs, being generally nervous, crying when we left her home alone, etc. We weren’t surprised, since her previous owners abandoned her and she spent a long time in the shelter. Now all she does it try to cuttle up with us and never leaves us, even if that means following us from room to room.

Ana is getting attached to Petunia and I don’t think we’re going to get her adopted. Being a Pitbull mix, people are afraid of her. However, everyone that’s met her has loved her, which is another reason we don’t think we’ll let her be adopted. She never barks, is great with our cat, loves to play, never complains, and is so adorable. She’s gathered such nicknames as Petu, Petufilese and just Perrita. Dogs are a lot of work, but I think in this case, for her, she’s worth it.

Apartment

My girlfriend of about a year, moved in officially a few months ago. She still has her old apartment, but the rent there is taken care of by a sort of sub-lease. Previously, we were always together anyway, cooking food, studying together, grocery shopping together. The only difference was, she wasn’t paying rent or the massive electricity bill we seemed to rack up with her presence. I have an extra bedroom in my condo, which I gave to her for all her stuff. We moved in her tredmill into that room (producing some of the first small scratches in my new hard wood floors), her desk and a bunch of other things so that she has her own space. It’s worked out extremely well and while we’ve had our fights about stupid apartment and living stuff, you don’t truly know a person until you lived with them. That goes for friends and girlfriends.

Spanish

As a result of living with a native Spanish speaker, I’ve picked up a lot. I never learned Spanish. It was always the language of poor people where I lived. Instead I studied German, the language that’s most understood in Europe. While living in Hungary, I learned Hungarian so picking up Spanish was probably the easiest thing for me. With Spanish, for example, just add an ‘O’ or an ‘A’ after any English word of more than 2 syllables and translate word for word and you have a pretty good, understandable sentence.

Before I met Ana (pronounced Ah-na, not Anne-uh by the way), I probably knew less than 20 words, and that’s after having spent two weeks in Mexico scuba diving. Before that, I probably knew around 5. Now I wish I would have learned it sooner, but I’m glad I learned German since Ana and I are planning a trip back to Europe. Ana has never been, so I’ll take us around Hungary, we’ll visit Italy (which is a language both of us have studied, but she understands a lot better) and she can take us around Spain since they almost speak the same language as she does.

We have a savings account set up that we’ve been putting money in since last summer. It’s not a lot, but it’ll at least pay for the plane tickets out there. Then we plan on staying with friends where we can, and since we both have friends all over Europe, it shouldn’t be an issue.


Apr 10 2010

iPhone Pricing

As with any product or service, the question of pricing is always one of the many challenges of selling a product or service. Many price their products or services low in an attempt to under cut their competition or initially sell a lot and get their name out there. Others charge way more than a person is willing to pay for such a product.

With iPhone development, more often than not, you’re selling a product as opposed to a service, which may be a compliment to your physical or web based service. If your iPhone app is a complimentary product to a service that you already offer and charge for, your iPhone app should probably be free (depending on complexity). Look at it as a value-added feature to put you above your competition and make using your service more convenient and enjoyable. By creating more ways to access your service, you provide more opportunity for your customers to use it more often and really benefit from what you’re trying to offer them.

So what’s the sweet spot for a price for your iPhone app? It obviously depends, but there are some guidelines we came up with.

Be Unique with Your iPhone App

The more unique your application is, the more you can sell it for. By being unique, you have less competition and thus a higher demand.

Complexity of Your iPhone App

If your application can be easily reproduced by a 16 year old kid on a weekend, you either shouldn’t charge for your application, or if you do, don’t charge more than a dollar because that 16 year old kid won’t.

Proprietary

If your application uses proprietary information, software, APIs or other technologies that aren’t easily implemented or obtained, you can charge more for your application. This relates to complexity, but be aware that people will often create equivalent systems if it’s popular enough so proprietary systems and information require a lot of maintenance to keep them relevant.

Usefulness of Your Application

How often will someone use your app? Is it just a novelty or something someone will only use for a certain chore that they rarely do? If so, the demand for the app diminishes and so should your price.

No application should be more than $10 with few exceptions. Remember that you’re developing for a mobile platform and the software is limited and your price should be limited too.

If it’s a game, how is the quality and length of game play? The quality, the game play and the fun factor all play a part in your price. Obviously, people much prefer spending money on entertainment than on a new fancy laundry list application. Games are usually unique (to the App Store at least), are complex and provide a greater satisfaction to buyers, which allows them to enjoy a higher price tag.

Perspective

Having a higher price on the App Store shows more confidence in your application. Giving your app away usually means you don’t think people would be even willing to spend the price of a soda on your application. These applications are fine, but for some of us, we need to make a living.

Making your app a dollar usually means, I want to make some money, but I don’t think people will pay any more for it. But charging a dollar can also be good if your app has a wide appeal. What you lack in big numbers, you make up with bulk sales. So, if it’s a game, you could potentially have a larger market as opposed to a utility application that the user spends 30 seconds on. So you really need to look hard at your application and keep several factors in mind before you price your app. You can always change it later, so one approach is to start low and see how sales go.