As a software developer, I spend my life writing line upon line of code with the idea that someone, somewhere will eventually use whatever software I’m building. Assuming that yes, someone does in fact use the software I build, I can only hope that these imaginary people actually enjoy using it!
Recently, I received this video from a close family friend of mine.
Watching this little boy play Shape Matcher, listening to his laughter and seeing his smile – I think I can say that in this particular case, at least someone has enjoyed using my software :)Read More
My third iOS app, Shape Matcher, launched almost exactly a week ago. I’ve been watching my Localytics analytics with much anticipation hoping to see the number of downloads rise. And I am proud to say that for once, my app is actually being downloaded AND used more and more!!
Since (upward-trending) graphs make me very happy, I thought I might share some graphs with anyone who might be interested.
New and returning users
Both the number of new and return users is rising. I had a big day on Sunday, possibly related to the fact that I wrote a blog post about the tools I used to build Shape Matcher but more possibly also because people spend more time with their children on Sundays, although that’s just a wild guess really.
The number of sessions seems to be rising fairly steadily.
It looks like the iPad 2 is the most common device amongst my target audience (mostly people with children).
I’ve had far more users and sessions from the USA than anywhere else. It really make me feel warm and fuzzy to know that people in 62 different countries have played my little game though :)
My latest iOS app, Shape Matcher, was recently released into the wild. It’s an iOS (available on iPad and iPhone) shape matching game for young kids’ – about all the gaming logic I can handle as a night-time Obj-c novice. Anyway, I figured it might be useful to others if I documented what software, frameworks and tutorials I used to develop it.
Inkscape is an awesome open source vector graphics editor. One of the things about writing a game is that you’ll probably need to draw some cute backgrounds or characters. Unless you’re a designer who already owns a copy of and knows how to use something like Illustrator or Photoshop, you’re going to want this software.
Drawing itself is a skill I don’t really have, and that really sucks. These days, apps have to look as good as they work. I might be good at writing software but I’m really not very good at drawing stuff – or at least that is what I was convinced of until Jas and I finally sat down and tried to learn how to draw digitally. We followed a fantastic tutorial called 2D Game Art For Programmers – Part 1 and by the end of it, we weren’t too bad at drawing some nice scenes and basic characters. All it took was for us to sit down and actually put our minds to it and it turns out that we’re not that bad at drawing after all!
If you plan on including lots of images in your iOS game, you might find it easier to use sprite sheets instead of lots of individual images. This is especially true if you plan on supporting different devices with different resolutions (because you need to supply resized images for each differently sized device). Zwoptex is a tool that allows you to create sprite sheets from your original images. You can then use Cocos2D’s built-in support to load the sprite sheets in your game. You can download Zwoptex for free, and if you don’t purchase it, it will take a couple of seconds longer to export the sprite sheets but it will still work properly otherwise. Much recommended!!
There seems to almost be a little bit of a cult following around Sublime Text. I’ve heard lots of well-known developers say that they use it as their primary code editor. It does seem to be nice and fluent. There are a few things about the UI that make it stand out. I use it when needing to copy plist values from the temporary files that Zwoptex outputs to my app ones. It certainly does the trick.
Most games have some sort of sound effects or soundtrack. Luckily cocos2d, the gaming framework I use, allows you to include sounds in your game really easily. But you still need to make your sounds or edit open source ones you find online. GarageBand provides a nice interface to do just this. You can then export them as .mp3 files and include them in your Xcode project. Simple!
cocos2d for iPhone is a framework for building 2D games. It adds support for important gaming functionality like transitions between scenes, sprites and sprite sheets, effects and actions, menus and sound… just to name a few. Shape Matcher is the second iOS game using cocos2d that I’ve worked on. Earlier this year, Jas and I wrote and released Easter Egg Hunt, also using cocos2d. So far we are both very happy with the framework as it provides a lot of functionality that I wouldn’t want to try and write from scratch. The only criticism I have right now is that the latest stable version, cocos2d-iphone-2.0, does not have support for the new iPhone 5 Retina Display screen resolution. Version cocos2d-iphone-2.1 beta3 does, but it’s still in beta. Either way, you can get around it in code if you need to.
Localytics offers integrated app analytics for your apps. They have an iOS library that you download and link to in your app. You can then track certain events in your app, such as when a user clicks a particular button or when they’ve spent a particular amount of time on any one scene. This information can be truly invaluable and the Localytics library makes it super easy to use. Their website, where you can view graphs about your app’s usage, is easy to navigate and nicely responsive. They aren’t free but they offer a free trial that doesn’t end, as far as I know. You have to pay to access some of the more interesting reports.
Although it can take months to write even a semi-decent iOS game, most people aren’t prepared to part with even $0.99 USD for it. I’m not quite sure I’m prepared to spend hours upon hours writing games that don’t make me a cent in return, but I would like people to actually play my games! In terms of games, this is where In-App Purchases come in very handy. You can put your game on the App Store for free, but sell extra scenes or options from within the game itself.
Luckily, Apple has made it pretty easy to integrate In-App Purchases in your application and theres a ton of help on the internet on how to use it. I used one of Ray Wenderlich’s awesome tutorials, Introduction to In-App Purchases, to learn how to include some in-app purchases in my game.
Tips and tricks
It’s a good idea to create both ‘test’ and ‘live’ versions of your app on Localytics so you can test your integration with them and not pollute your ‘live’ analytics. Just before you archive and submit your app to be reviewed, change the Localytics app ID in your code to the ‘live’ one. Don’t forget to do this!!
Although I totally missed it in the Apple documentation, apparently if you have any In-App Purchases in your app, you must provide a ‘Restore Purchases’ button in case the user installs your app on a new phone and has already made purchases. This button seems somewhat overkill since clicking on the buy button again will allow the user access to the purchase without charging them again but I guess it’s nicer for the user to click on a ‘restore’ button than a ‘purchase’ button. Apple app review staff will reject your app if you don’t provide this button. Ask me how I know this…
When creating the individual images that you’ll use in your game, export them in the largest size you’ll need them from Inkscape. Import them into Zwoptex to create a sprite sheet and save this workspace. You can then set up the publish settings to export one sprite sheet for each device resolution you want to support (except for the iPhone 5 that actually has a different ratio). When you press the ‘publish’ button, Zwoptex will create a spreadsheet per setting. This saves a lot of time when you’re writing a universal iOS game and keep making subtle changes to your drawings.
Below is a handy table of iOS device sizes that you’ll want to use in your publish settings for each iOS device:
So what are you waiting for? Go download these tools and get started on your first iOS game! If you have any questions, please feel free to ask :)Read More
One year ago today I started keeping track of my running. I had just joined a new gym and Jason and I had made a pact to really give the gym a go this time. Little did I know what this would lead to…
During this last year I participated in a 5km run with my dad and brother in Santiago, Chile and a 16km run with my workmates and friends here in Amsterdam. I bought myself fancy new Nike Lunarglide running shoes and a bluetooth heart rate monitor. I managed to get to the gym 82 times and started running outdoors.
But best of all, I ran a total of 500km in one year.
I for one would never have thought I could run that far in a lifetime, let alone one year. Yet, here I am, 500km later and only 2 weeks away from running my first half marathon. I must admit, I’m pretty nervous about running 21km. I’ve never actually run any further than about 18km in one go so 21km is going to be a stretch. But then again a year ago I didn’t even think I’d be able to complete the 5km run with my dad and brother without collapsing.
So there we go. A pat on the back for me. I’m proud of my efforts and am looking forward to another year of good, hard exercise. Who knows, maybe this time next year I’ll be able to blog about having run a whole marathon… :)Read More
Since moving to Amsterdam about 10 months ago, we’ve had just about as many visitors. For a multitude of reasons, Amsterdam is incredibly popular with tourists. Every weekend the population of this small city swells ridiculously. In 2010 alone, 5.3 million tourists visited Amsterdam. That’s a lot of people in a very small area!
Anyway, for all our future guests and anyone else visiting Amsterdam, here is my list of attractions. They’re not in any particular order and I know I’m missing a bunch, but it’s a start!
There are a lot of museums in Amsterdam, most of which seem to be art related.
Rijksmuseum – Image sourced from Wikipedia – Amsterdam Rijksmuseum
- Van Gogh Museum
- Rembrant Museum
- Cat Cabinet
- Anne Frank House
- Verzetsmuseum (Dutch Resistance Museum)
- Jewish Historical Museum
- Museum Ons’ Lieve Heer op Solder
- Amsterdam Tulip Museum
- Amsterdam Historical Museum
There are several old churches dotted around Amsterdam. It may seem a bit strange but Oude Kerk is right in the middle of the red light district!
Westerkerk – Image sourced from Flickr – Steve Cadman – Amsterdam Westerkerk
You can spend days just wondering the streets of Amsterdam. The buildings are so beautiful and well maintained. The tree-lined canals and little bridges just can’t get any more picturesque on a sunny afternoon. But then again, there are heaps of other things to do as well, such as…
Heineken Experience – Image sourced from Info Barrel – Heineken Experience
- Heineken Experience
- Canal cruises
- Dinner canal cruise
- Liquor Distillery
- Cheese Tasting
- Whiskey Bar
- Torture Museum
- Walk along the canals & streets in between
- Eating a herring from a street vendor
- Walk around the Jordaan
For such a small city, Amsterdam has several particularly well known areas. Some are pretty obvious (like the red light district) whilst others are much more hidden away (like the Begijnhof). Whatever your style, there’s something for everyone.
Red Light District (De Wallen) – Image sourced from Wikipedia – De Wallen
Like every proper European city, Amsterdam has its fair share of markets. Some only operate on the weekend and most have a particular theme.
Flower Market (Bloemenmarkt) – Image sourced from Wikipedia – Bloemenmarkt
- Bloemenmarket – Flower Market
- Noordermarkt – Organic Farmers’ Market
- Waterlooplein – Flea Market
- Albert Cuyp Market – Street Market
Shopping in Amsterdam is not like it is in the USA or Australia where you have everything you could possibly need in one large shopping mall. Malls like that don’t really exist in Europe where shopping is more ‘boutiquey’. There are shops dotted around the city and a few streets, like Kalverstraat, are lined with them.
Shopping (Kalverstraat) – Image sourced from Flickr – Kevin Oliver – Kalverstraat Shopping, Amsterdam
Dutch cuisine is not particularly varied but there are definitely some dishes you must try while visiting Amsterdam or Holland in general.
Fondue – Image sourced from Life In Amsterdam
- Bacon pancakes
- The Pantry
- Hofje van Wijs Tea and Coffee
- The Five Flies
Holland is a tiny country. It really is. Nowhere in Holland is more than an hour or two away from Amsterdam so there are lots of options for day trips. Public transport (both train and bus) is very convenient, comfortable and affordable.
Zaanse Schans – Image sourced from Eropuit.nl
Over the last year or two, I’ve been reading articles that describe this strange world where software developers are Gods. They are paid so much money that it’s ridiculous. They get flown across the US and invited to parties with naked girls in spa pools and all the booze in the world.
Image sourced from http://www.quora.com/Brogramming/How-does-a-programmer-become-a-brogrammer
Ok. I feel like I’m missing something here. I’m a software developer. I’ve been doing this for the past 10 years or so. I’ve worked in NZ, Australia, London and now Amsterdam, just to mix things up. I’ve even worked primarily in the e-commerce space. So why on earth am I not living this crazy extravagant lifestyle?! Is it because I don’t live in the US? Waaaaahh!!
Then I read this article and the penny dropped.
Who are the “fat guys who know C++”, or as someone else put it, “the guys with neckbeards, who keep Google’s servers running”?
What?? What do you mean who are they? Isn’t this a perfect description of a software developer? If it isn’t, then what is??
Until this point, I’ve been living in a world where I thought the developers that apparently belong to this ‘secret Guild of nomadic craftsmen’ were the real developers, the ones that people refer to when they mention software developers. Apparently I’m wrong and I’m now a part of something that not everyone is even aware exists! To most people, developers are actually cool hipsters that have a great fashion sense and certainly aren’t spock-like.
When did this shift in definitions happen?Read More
For Christmas, my awesome partner Jason got me a Tamron SP AF 90mm f/2.8 Di Macro 1:1 lens for my Nikon D90. I really enjoy taking close up photos of insects and flowers and although the kit lens I already had does a pretty good job at it, a macro lens can do much better. I haven’t really learnt how to use it very well yet but here is my first attempt – a few photos I took at the Changi Airport ‘Butterfly Garden’ in Singapore.
Apart from re-sizing these photos, I haven’t edited them at all.
Things in the “software development” world have changed a fair bit over the last 10 years. In the past, developers used to have to think carefully about the SQL they wrote, making sure that they used well optimized stored procedures on well designed databases with the right indexes on the right columns because let’s face it, the database was often a bottleneck.
Nowadays, with tools like ORMs being used more and more liberally, I get the feeling that some of us are getting a bit lazy and forgetting that the database is still a potential bottleneck. I bet that a lot of developers reading this won’t have had to hand-roll any SQL for a while and instead rely on what the ORM of choice generates for them. Mature frameworks like NHibernate and Entity Framework do a great job at providing us with CRUD statements but if we have a complex domain, a lot of rows, a heavy load or unique requirements then perhaps they aren’t good enough.
Although I’m by no means a DBA or SQL / SQL Server expert, I think it’s important for developers to take some responsibility over data retrieval when writing applications. To get the most out of your application and hardware, you should be aware of which queries are run most often and which are taking the longest to complete. In a perfect world, your DBAs could be providing you with this information on a weekly basis but there are some tools that you as a developer can use to preempt performance problems as well. In this post I’m going to list out some of the tools that I use to help me performance tune and monitor SQL Server, the DBMS that I am most familiar with.
Use stored procedures over executing SQL statementsIn previous versions of SQL Server (version 6.5 and earlier), one of the main advantages of using stored procedures over executing SQL statements was that SQL Server would partially precompile a single execution plan for stored procedures upon their creation and cache it for reuse. However, the last couple of versions of SQL Server no longer precompile execution plans for stored procedures upon creation but instead upon their first execution, like is done for any other SQL statement. Also, execution plans for all T-SQL statements (stored procedures and SQL statements) are now stored in the procedure cache, not just stored procedure execution plans. These changes reduce the overall performance benefit that used to be gained by using stored procedures.
There are still some other performance gains to be made by using stored procedures though. For example, when you call a stored procedure from code, you only have to send the EXECUTE stored_procedure_name arguments down the wire instead of the whole statement. You can also perform a lot more logic within one stored procedure thereby saving you many round trips between the client and the server.
There are also other non-performance-related benefits to using stored procedures over SQL statements such as maintainability, abstraction, security.
Execution PlansBefore releasing a new or updated stored procedure, it’s a good idea to have a look at the planned and actual execution plans for it. If you’re making a change, you should look at the execution plan before and after your change to make sure you haven’t made anything worse! The main things to look for here are:
- Table or clustered index scans. If the table over which the scan is being performed is small, this isn’t generally a problem. If it is a large table then it may mean that your table is missing indexes, or you need additional indexes, or that the optimizer has ignored your index for some reason. If you really need to (and you know what you’re doing!), you could use query hints to force SQL Server to use a particular index.
- Repetitive scans. Try to avoid any repetitive table or index scans by rewriting your queries. There is usually more than one way of writing any batch of SQL statements.
- Highest cost queries. Concentrate on optimizing the queries with the highest relative cost.
Traces – SQL Profiler vs Server SideTraces record what’s going on in your database and are invaluable when it comes to analyzing what’s going on under the covers, especially when there is a performance issue.
SQL Profiler is a great GUI for running traces and analyzing how your code is actually communicating with your database(s). Even if the queries themselves are well optimized and running smoothly, if you’re repeatedly calling them hundreds of times in a row then you may encounter some performance issues. However, as a developer, you should only ever SQL Profiler to run traces on development and test databases. Running a trace on a production database from the SQL Profiler GUI can seriously overload it. You should also make sure you’re capturing the information you need and not too much more otherwise it becomes impossible to find what you’re looking for in all the trace output. I generally set mine up like this:
According to a very talented SQL Server DBA ex-colleague and friend of mine, @trademe_dave you can also run traces on the server side which apparently have much less impact than running them through the SQL Profiler GUI, but it really all depends on how many events you trace (3 or 4 should do the trick) and how long you leave it running for. Safest option is to leave this sort of thing up to the DBAs :)
Dynamic Management ViewsIf you can’t get your hands on a trace, you can try using Dynamic Management Views to show you some execution statistics (including CPU time, physical and logical reads, etc) on all queries. From what I understand, it isn’t perfect – for example, it only shows you aggregated data on queries that have actually finished executing, but that’s still much better than nothing! Here is a great article on how to use sys.dm_exec_query_stats to show you the top (most often run, longest execution time) queries.
Analyze Statistical InformationIf you execute the statement SET STATISTICS IO ON before running a query or executing a stored proc (in SQL Server Management Studio), SQL Server will output some information regarding the amount of disk activity generated by the SQL statements being executed. To turn it off again, you simply execute SET STATISTICS IO OFF. These statements affect the existing connection so if you don’t execute a SET STATISTICS IO OFF command, any other queries you run using the same connection will also produce this performance tuning data.
The syntax looks a little like this:
1 2 3 4 5
SET STATISTICS IO ON SELECT * FROM dbo.Articles SET STATISTICS IO OFF
The information it outputs regarding the disk activity can be found in the ‘messages’ table, right next to the ‘results’ tab in mgmt studio:
What you’re looking for in particular are the number of scan counts and logical reads. For a simple query or stored proc that selects data out of only one table, you’ll generally find a scan count of 1. However, if you’re joining tables then you’ll see that some of the tables involved might have much larger scan counts. I don’t know off the top of my head what a good value for ‘scan counts’ is but your DBA should be able to help with that. More importantly, while you fine-tune your query / stored proc you should keep an eye out on this value to see if it goes up or down with the changes you make – the higher the number, the worse the performance.
With respect to the logical reads, they are a measure of the number of pages that SQL Server had to read the data cache from in order to produce the results specified by your query. Again, a higher number is worse than a lower number so while you are tuning your query / stored proc, you should make sure that you don’t end up with a higher number of logical reads than you initially had!
I’ve also read that it’s a good idea to issue the following two commands before executing your query / stored proc with SET STATISTICS IO ON / OFF around it so that you clear out SQL Server’s data and procedure caches:
DBCC DROPCLEANBUFFERS DBCC FREEPROCCACHE
This article has a lot more detail on SET STATISTICS IO ON / OFF (and SET STATISTICS TIME ON / OFF which I personally haven’t used). And here is an MSDN article on SET STATISTICS IO, just for good measure.
That’s all for now folks!I’m sure there are many other tools that developers can and frequently do use to performance tune their SQL queries and stored procedures. Those listed above are just the ones I use often – if you know of any others please feel free to leave a comment below!
But please, developers, don’t forget that under all your awesome code there is still a database struggling to keep up with the load you’re throwing at it. Be smart about how you access your data and don’t stop analyzing, benchmarking and optimizing your SQL statements.Read More
In a previous role, I was tasked with writing a newsletter email sender. How hard can this be, I thought to myself, and set off to complete my mission.
We were probably going to be sending tens of thousands of emails at a time so although I figured I’d need to use some threading, I thought I’d start by using the asynchronous version of the SmtpClient.Send method, SmtpClient.SendAsync instead of the blocking SmtpClient.Send. I figured that way I’d be able to send batches of emails asynchronously and that way we’d be able to get through all the emails super fast.
I wrote some basic prototype code using SmtpClient.SendAsync and ran a test to send a couple hundred emails in it. Although my test ran without errors, I pretty quickly discovered that I wasn’t receiving all the emails that I was apparently sending by calling SmtpClient.SendAsync! At first I wondered if I’d somehow overflowed my inbox or something but that didn’t seem to be the problem. Then I started doing a bit more research and discovered something which explained the behaviour I was seeing…
From the ‘remarks’ section of the MSDN documentation on SmtpClient.SendAsync:
After calling SendAsync, you must wait for the e-mail transmission to complete before attempting to send another e-mail message using Send or SendAsync.
To receive notification when the e-mail has been sent or the operation has been canceled, add an event handler to the SendCompleted event.
OH! So in order to successfully send multiple emails asynchronously, I must add an event handler to the SmtpClient.SendCompleted event and wait until the first SmtpClient.SendAsync has completed before triggering the next one. Hmm… this does not seem all that asynchronous to me! I realize that there must be good reasons why it was implemented this way but in theory, using SmtpClient.SendAsync to send multiple emails really isn’t all that much more asynchronous than lining up a bunch of synchronous calls to SmtpClient.Send.
I guess it all comes down to your interpretation of what ‘asynchronous’ means – in this case, SmtpClient.SendAsync is indeed asynchronous in that it allows the program to carry on executing without blocking. This is great in most cases, unless what you want to do next is send another email.
So to sum up, it seems the only way to send multiple emails at the same time using .NET’s SmtpClient is to use threading after all. Spawn up a few worker threads with a separate instance of the SmtpClient in each and just send the emails using SmtpClient.Send.Read More
In ASP.NET web applications, the Response.Redirect(string url) method is often used to control the flow of an application (both user browsing and logic) by redirecting the client to a different URL. For example, on a page that requires an authentication user, it is quite standard to first check if the user is logged in and if they aren’t, call Response.Redirect(“login.aspx”). This is all great, except that many developers probably don’t know what’s actually going on under the covers.
Under the covers
Internally, Response.Redirect (and Server.Transfer for that matter) calls Response.End to end the page’s execution (rather abruptly) and then shifts the execution to the Application_EndRequest event in the application’s Global.asax. We rely on this behaviour to bail out of wherever we were when we decided to call Response.Redirect. What most people probably don’t realize is that Response.End raises a ThreadAbortException exception. Exceptions are expensive, and if you’re calling Response.Redirect often, you might find this particular behaviour detrimental to the performance of your site.
So, how do I avoid these exceptions?
Well, Response.Redirect actually has an overload that takes two parameters – Response.Redirect(string url, bool endResponse). If you use this overload instead and pass false to the endResponse parameter, the internal call to Response.End will be suppressed and as such, no ThreadAbortException exceptions will be raised.
Great! But wait, there’s more…
There is a side effect! Using this overload and passing false so that Response.End doesn’t get called means that any code after the call to Response.Redirect will now be executed where it wouldn’t have previously. This makes perfect sense – if Response.End isn’t called then the execution isn’t shifted to the Application_EndRequest event and if the execution isn’t shifted, then it will carry on executing wherever it currently is. That’s right – although you no longer get ThreadAbortException exceptions being thrown, Response.Redirect no longer controls the flow of your logic.
This is fine if you are calling Response.Redirect at the end of a method at the bottom of your call stack because there was probably no more code to be executed anyway. On the other hand, if you are calling this from inside a method that isn’t at the bottom of your call stack, you have to be careful with the remaining stack calls. Even if you call return straight after you call Response.Redirect, where are you ‘returning’ to? Another method that executes more code? Eeek!
None of this is news – it’s all explained in this Microsoft Support article. However, I really don’t feel that it emphasizes enough the negative effects that switching over to the Response.Redirect overload may have on your application. You simply can’t go through your application and replace every Response.Redirect with it’s overload without thinking carefully about what this might do to the logic of your application. The ‘flow’ may still look like it’s working as it should because the user will still be redirected to another page, but under the covers you might find that you’re now executing code that you weren’t before and that may have some pretty nasty unwanted effects.Read More