Aug 22, 2011

TDD and Unit-Testing for Python Developers

A few days ago, I gave a 1:30 hours long talk (in Hebrew) in my company about TDD and Unit-Testing for python developers.

The idea was to focus both on what is TDD, including a 45 minutes demo, and to give some concrete tips for unit-testing in python.

Usually when I give a talk about TDD, I use some kind of simple kata as a demo, like the prime factors kata of Uncle Bob. The problem with that, is I usually get responses like "TDD works only for calculators examples". I tried to be a little more original here and demonstrate a more real-life like example, and I tried not to come prepared too much, so I could demonstrate a genuine way of thinking about the design and letting it drive my code.
Looking back, I think this caused the demo to be a little messy - I told the audience to participate and throw ideas in the middle, and this caused things to advanced a little bit too slowly, and we didn't really get to real value by the end of the demo (as opposed to using a simple kata when you get value by the end of 5-10 tests).

For the tips sections, I took most of the material from Michael Foord's great blog and mocking framework: http://www.voidspace.org.uk/, and I think it should be very useful. So thank you for that Michael!

Anyhow, apart from the messy demo - which I think is still educational - I feel like the talk went fine, and decided to share it.

The Talk
Here's an unedited screen and sound capture of the talk, for the Hebrew speakers of you.

If you can't watch it through this shaky flash plugin, you can download it from here

Unfortunately, you can barely hear what the audience is saying so you can't catch up on the audience interaction - I wanted to edit it a bit and add subtitles of these parts but I really can't see myself getting to do so any time soon, so I decided to share it as it is now rather than sharing an edited video never :)
Also, there were some off screen interactions, unfortunately the video camera didn't work well so you wont be able to see them.

If you only want the slides (in English), you can access them here:
https://docs.google.com/present/edit?id=0AaAaoNed4IPFZGZ2cHJocHZfMWQ2NmNmdGdr&hl=en_US

Additional TDD material
Per audience request, some useful links:

Recommended books:
Test Driven Development: By ExampleGrowing Object-Oriented Software, Guided by Tests


Additional TDD demos:

Hope you found it useful...
If you did, you should check out some other posts in this blog, and follow me on twitter.

Aug 2, 2011

Getting started with iOS development

So... In the last couple of weeks, I've been researching iOS development - reading some blogs, going to some lectures or watching them on iTunes U, searching for answers to common questions on stackoverflow, etc.
This doesn't make me an expert on the subject, but I think if like me - you're thinking about starting with iOS development or mobile development in general, this post might save you some time and make sure you're not missing any of the important technologies available today (August 2011), and the information you need to know in order to get started.

Before You Start...

Do I have to own a Mac in order to develop for iOS?


  • In a word: YES.
  • There might be frameworks that will let you develop the applications without a Mac, but when you'll want to deploy on a real device, or to the app-store, you're going to need a Mac for that.
  • Even if you succeeded in creating a Hackintosh on a VM (I personally had a really hard time trying to do so...), it is not recommended - as you are going to have troubles once you'll need to update your software/OS version, etc.
  • I tried to find online solutions for "Mac for rent", and found macincloud.com, but 2 days after sending a request for a trial they announced they closed the site for new users.
Does it cost me money to develop iOS applications?


  • The iOS Developer Program costs 99$/year. It lets you have the development environment for free, and the ability to install your apps on up to 100 personal device, and deploying them to the App Store.
  • You can however, obtain xCode (the development environment) for 5$ in the Mac App Store, or get the 4.1 version comes free if you have OS X Lion. This will let you develop apps freely, and test them on the iPhone/iPad simulators. If you'd like to test them on a real device as well without paying the 99$, you'll have to jailbreak it first (which is a big No No if you're planning on deploying it to the App Store in the future).
I'm considering deploying my app to android or other platforms as well.
What kind of options do I have?



  • Well, it seems as if the most popular choice is simply to re-write your app for the other platforms using the platform's native framework + SDK. This might sound surprising, but understandable once you think about the downsides of the cross-platform solutions available today.
  • Notice that because both Java (Android) and Objective-C (iOS) can integrate with C/C++ code, writing at least some layers of your application in C/C++ will make it easier to port it to other platforms.
  • This is also true about web applications. Nowadays, all smartphones and tablets have the capability of displaying web content such as HTML5/CSS3/Javascript. Therefore, writing your app as a web application or at least having a web container that runs web content as part of your native app, will make it available for other platforms freely, or at a very low cost. There are also some frameworks that will facilitate your efforts writing such apps, that will be discussed later on this post.
  • Even though there are some downsides, there is a variety of available frameworks for developing cross-platform apps, and I'm going to discuss all the notable ones later on this post.
So, what are the downsides of using a cross-platform solution?
  • Native Features: Most of the available cross-platform solutions won't let you access all the native features of the hardware. For instance, if you want to record real-time data from your microphone or camera, you'll have to write native code that does it, even if your basic framework is cross-platform.
  • Performance: Like cross-platform solutions on the PC, a cross-platform solution in mobile devices comes with a performance overhead, some more than others.
  • User Experience: Your UI will fail to address the special look-and-feel and the specific features of a given platform, like the 4 physical buttons that exist in Android vs. the single home button in iPhone, which will surely feel awkward to the user.
Why iOS and not Android?


  • While following smule, a great music-related iOS app developers, I found an interesting post they shared about why they don't develop applications to Android:
    http://tech.fortune.cnn.com/2011/05/27/why-its-harder-to-make-money-on-android-than-on-apples-ios/
  • Another thing they claimed, is that it's impossible to do real-time audio processing in Android due to high latency: "right now if you create an app for android that just routes the audio from the microphone to the speaker, there will be a noticeable delay, even on the devices with fast processors. This is a problem because if you want to make an app like 'I Am T-Pain' then it becomes impossible from a user experience standpoint to do live vocal processing. Put another way, hearing your voice come out of the speaker delayed creates a user experience that is not on par with that which we've been able to create on iOS. - this is a major problem if -- like I do -- you want to include real-time audio processing in your applications.
  • On the other hand, it seems that the majority of the mobile devices in the market is soon going to be Android's: http://www.mofonu.com/2011/07/15/android-devices-130-million-and-growing-%E2%80%93-550000-devices-activated-everyday/
Native iOS Development Technologies

Some useful links to get you started
Objective-C
  • An additional layer to C that introduces objects
  • Syntax is ugly (smalltalk like), but not something you can't get used to
  • Memory management is better than C, but you still need to be very aware, unlike modern languages. However, iOS 5 will support Automatic Reference Counting (ARC), so this should alleviate the pain. (See http://developer.apple.com/technologies/ios5/)
  • Has some very features of modern languages, like automatic getters&setters, nil objects that do not causes a crash if referenced, and dynamic language features - altering existing classes, invoking methods dynamically, etc.
  • The iPhone SDK and all APIs are written in Objective-C (Including the UI layers), and as said before - you are probably going to write at least one layer of your application in it, so you definitely should learn Objective-C if you are planning on developing for iOS.
  • A GREAT summary about Objective-C's basics: http://www.otierney.net/objective-c.html
IDE (xCode)


  • Basically, it's like VisualStudio for iPhone applications. Seems like a decent tool - autocompletion works very nicely, and there are built-in UnitTests support which is great (no green bar though...)
  • Comes with a set of tools, like the iPhone simulator which is a very good way to feel how your app is going to appear on the device without actually deploying it, and other important tools like a profiler, a memory debugger, etc.
  • Will take some time to adjust to, and from first look - it's powerful, but lacks some advanced refactoring features IDEs like Eclipse have.
  • I heard some that claimed that even if you develop in other IDEs, you'll still have to compile them eventually in xCode before submitting to Apple. However, I guess this was true prior to a change in Apple's policy regarding development tools, in September 2010.
  • One prominent alternative for xCode is Appcode by JetBrains (IntelliJ dudes): http://www.jetbrains.com/objc/ - haven't thoroughly checked it out yet, so no review.
OpenGL ES


  • Official website: http://www.khronos.org/opengles/
  • OpenGL ES is a subset of the OpenGL 3D graphics API, designed for embedded devices, including mobile phones. A subset - meaning some of the features of OpenGL such as floating point operations might not be available, and you'll have to replace them with alternatives if you're planning on porting an existing desktop OpenGL application.
  • The upside of developing in OpenGL ES, besides being a strong and popular 3D graphics engine, is that it supports many platforms. Implementations always have a platform-specific part, and the OpenGL API which is the same on all platforms for a specific OpenGL API version (which unfortunately may differ between the Android SDK and the iOS SDK). So while your code won't be 100% cross-platform, it should be easily portable, especially if you create proper abstractions between the platform-specific and non platform-specific part.
  • A great set of OpenGL ES tutorials for iPhone can be found at http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html
Cocos2D


  • Link: http://www.cocos2d-iphone.org/
  • An open source objective-C based framework for easily developing 2D games for iOS and Mac. Based on OpenGL ES.
  • Contains nice features such as scene managements, menus and buttons, tile map support, high score server, and many more.
  • Very popular - has a large community and lots of cool games created with the framework.
  • The tutorial in the official site seems very effective, and there are lots of other books and tutorials out there.
Cross-Platform Solutions

Web Based Cross-Platform Solutions


  • There are a lot of platforms that let you develop native apps in html5/javascript/etc.
  • This is a good solution for developers who already experienced in web, and do not wish to learn objective-c or other similar technologies.
  • On the other hand, although some of these frameworks allow you access to the hardware of the devices, it is limited in comparison to real native apps. Also, there are major performance limitations, and of course there's the native look-and-feel issue I mentioned earlier.
  • The most popular examples of such frameworks are: PhoneGap and Appcelerator Titanium. I must admit my research less focused on them so I can't really say how they are, but I do know they are popular and has a large community, and on the other hand - they have the known limitations mentioned earlier.
  • To sum it up, here's a nice presentation by Onavo about the dilema of Native apps vs. Web Apps:  http://www.slideshare.net/onavo/advanced-ios-engineering-the-junction-talk
Rhodes Rhomobile


  • Link: http://rhomobile.com/
  • A bit similar to the rest of the web-based cross platforms solution, except that it's Ruby based, and should be more powerful regarding hardware capabilities.
  • Personally I'm more of a python guy, but from the little I know, ruby is a really fun dynamic language.
  • According to their claim, apps written with rhodes are faster than Android apps written in Java, because it's written 
  • Hardware capabilities currently include access to GPS, camera (only still pictures), bluetooth, audio playback, barcode recognition, and more. Audio/Video capture is planned in future releases.
  • Integrates nicely to all popular IDEs, with a built in unit-testing framework, etc.
  • All in all, seems like a good option if your app doesn't require intensive graphics or performance, and you like ruby, or at least prefer it over objective-C.
Marmalade


  • Link: http://www.madewithmarmalade.com/
  • Until recently known as 'Airplay SDK'
  • A cross-platform infrastructure in C++ - mainly targeting game development but according to them "Marmalade’s sweet spot is 'rich' apps, by which we mean any combination of: great graphics; audio processing; use of device APIs such as camera, GPS, and microphone; deep C/C++ codebase; or anything else that raises your app above the level of a simple mobile website wrapper"
  • They have a plugin for the existing IDEs: either Visual Studio in Windows, or xCode in Mac - which makes it very comfortable to develop.
  • The support for platform-specific code (called EDK) gives an automatic layer of abstraction that makes it very easy to write a cross-platform app that takes advantage of native features.
  • There is a very impressive portfolio of games developed with this SDK, like games by Electronic Arts, or PES by Konami.
  • All in all, this looks like one of the top choices for developing cross-platform applications.
Unity


  • Seems like a very powerful cross-platform game engine. Has good documentation and a good community of Q&A. http://unity3d.com/
  • Most of the development is done with an editor, and the engine supports scripts in Javascript, C# and Boo. There are also many native plugins in the Pro version, and you can write them yourself in c/c++ / objective-c / java, etc. (but using it will make your game non-cross-platform of course).
  • In general, seems like this is a very strong option for game development, especially if you are developing 3D games for multiple platforms. However, accessing the microphone/camera of the mobile device + other advanced features will require using native plugins.
Flash CS5


Corona SDK


  • Link: http://www.anscamobile.com/corona
  • Based on the Lua scripting language, should be similar to ActionScript. There's a nice blogpost regarding how to port a Flash application to Corona: http://blog.anscamobile.com/2011/01/flash-to-corona-porting-guide/
  • Claims to focus on performance and from the showcase seems like there are very impressive games developed with Corona.
  • Has access to many of the device capabilities, including camera, microphone, GPS, etc.
  • There's a free unlimited trial, but you need to buy a subscription in order to distribute apps.
Afterword

That's about all I have researched and can share with you currently. I hope that with time, after gaining some hands-on experience, I'll have some more useful knowledge to share in this blog. So if you're interested - stay tuned: subscribe to the blog, or follow me on twitter.

I would like to welcome any comments you have about the information written here: if you feel I left some important information out, if you spotted a mistake or two in the data, or if you have a personal opinion about some of the frameworks I mentioned. Please leave your comments as a reply to this post. I promise to take them into account.

Edit: Thanks @philxan for mentioning I forgot about MonoTouch

  • Official Site: http://ios.xamarin.com/
  • Part of the Mono Project (http://www.mono-project.com/Main_Page) - a solution that allows you to write cross-platform C# application.
  • Basically, it's a C# framework that integrates with the desktop Mono SDK and the iPhone SDK and lets you create native applications in C# and the .NET framework. Should be interesting mostly if you're looking to port an existing C# application for iOS, or if you're an experienced C# developer and want to save yourself the efforts of learning and adapting to new technologies.
  • The IDE is MonoDevelop for OS X - looks a solid IDE, but I can't say I tried it personally.
  • Cost begins at 399$ for a personal license...
  • Has a version for Android (and naturally Windows Phone) as well
  • Here's a good site with code samples: http://monotouchexamples.com