What to expect from a dev team?

There are many dimensions to software development: scope, duration, cost and quality. Software development is an art, not a standard process. It is not mass production where you can quantify and predict everything. Attempting to get fixed values on all these dimensions is a big mistake. Here is why.

Customers often come to me with a fixed scope, duration and cost in their mind. Think of it as asking a research team to build a 400 HP electric engine that can run for 500 KM in no more than 90 days without exceeding the budget. It can look pretty on paper, but at some point, some of these variables will actually need to vary. This is what will happen to quality when everything else is fixed. Sacrificing quality is the classical recipe for writing terrible code, which in turn results in extended durations, cost increases and reduced functionality due to this technical debt.

Customers do not like this idea, but there is a solution. In agile development, we can fix the duration, cost and quality while allowing the scope to remain variable. The customer may not get everything they ever wanted in any one Sprint, but they get a high-quality product increment that contains the highest priority features completed, while minimizing technical debt. Let me give you a simplified example.

A hypothetical customer wants an online store. He wants a checkout process with a payment system. He also wants users to rate and comment on products. Users should be able to sell products to each other and have a private messaging system to facilitate communication. The PM system will allow managing contacts and import them from third-parties. The customer has a fixed budget and needs to get it done by a certain date. The deadline doesn’t have any margin for error. This project will most certainly fail. But, if you allow the scope to vary, developers might still deliver a quality project within the allocated time and budget. It might exclude contact management and importing, if it had a “nice-to-have” priority.

Notice how we can play with the scope and still deliver a great product that will start generating money for the customer. If we had constrained the scope, another variable would have suffered, leading to project failure.

The next time you talk to a development team, keep this in mind. Having the idea of the century is not synonymous with a successful project. You must admit that everything cannot be written on paper before you start the software development. Once started, you have to learn to make sacrifices, and do them in the right place.

php|tek 09

(photo by Marco Tabini)

I had the pleasure to attend php|tek this year in Chicago. This conference was organized by php|architect.

I attended some very interesting presentations such as “Dissecting an MVC Application”, “Alternate Databases”, “Of Haystacks and Needles” and “Seven Steps to Better OOP Code”. I enjoyed the Pecha Kucha presentations. These were very short presentations on topics not always related to PHP. I liked the one by Scott MacVicar and Andrei Zmievski on spelling.

I also met many interesting people with whom I intend to stay in touch. Wade Arnold, author of Zend_AMF, should be expecting feature requests and patches from DevBots. There were many interesting discussions around best practices between the presentations.

I was also able to catch up with my international friends that I don’t get to see very often. We celebrated Chris Shiflett’s birthday by going to a Peruvian restaurant and enjoying a great variety of beer at the Map Room, in the company of Andrei Zmievski, Sean Coates and Scott MacVicar. I enjoyed the event so much that I stayed an extra day to visit Downtown Chicago with Stefan Priebsh, Sebastian Bergmann, Arne Blankerts and David Zuelke. I posted some pictures to Flickr.

The only negative comment that I would like to share is the fact that WiFi was very unreliable during the event. I ended up paying to use the hotel’s WiFi every day to stay in touch with the office.

My next stop is ZendCon in San Jose, California.

Application Domain and External SWF Loading

Why do we care about application domains? I worked on a project that required me to load and unload SWF files into a bigger application (loading mini-games into a virtual world). Every time I loaded a mini-game, it would never unload when I exited it. That will keep accumulating until the app slows down to a crawl and crash because we’re out of memory.

The application domain and definition loading is one of the things that is not documented in a way the common mortal can understand. By popular demand, I will attempt to explain it the way I understand it. I will provide some examples along the way. Before I continue, here is a link to the official documentation on ApplicationDomain.

I will explain class definitions and domains, and then tell you what you can do to properly unload your movies and assets.

Class Definitions

Everything that you load has to be stored somewhere. It’s easy to understand the visual elements because you can just stick them on the stage. But what about class definitions?

For all of you who aren’t sure what class definitions are, remember all the classes that you import on top of the document when writing AS3. You can then instantiate your mx.controls.Button or flash.events.Event in the document. You can then add instances of visual components to the display list (stage).

Now think about your SWF for a minute. When you create a symbol in the library and export it for ActionScript, you’re basically creating a definition in the SWF. That definition will be loaded into some domain and you can instantiate it on the stage.

If you look at the schema, you’ll see all the class definitions in the current domain. When you close the application, all instances will be destroyed, class definitions removed and memory freed. If you decide to load an external SWF, you can choose where to load the definitions: in the same box as Class1 or in its own box.

ApplicationDomain.currentDomain


If you choose to load them in the same box as Class1, what will happen when you decide to unload your SWF? Any instances on that stage are destroyed, any definitions in its box are removed and memory is freed. Oh wait, there were no definitions in its box, so there’s nothing to remove from it. The file is unloaded in any case, but the definitions live on as a parasite in the box of our application. That’s right, a parasite. You can’t target a specific definition to unload. If you want to unload ClassC, you’ll need to unload the whole app (basically just close it). That’s not what you want to do. You want your app to run all day.

What is the solution? Remember there are 2 choices when loading your SWF. What if you want your loaded SWF to keep it’s garbage to itself? Sure.

New ApplicationDomain

So instead of loading you SWF into the application’s domain, load it into its own domain. How?

var appDomain:ApplicationDomain = new ApplicationDomain();
var context:LoaderContext = new LoaderContext(false, appDomain);
var loader:Loader = new Loader();
loader.load(new URLRequest("myButtons.swf"), context);

We created a new domain and loaded all definitions into it. So now our application has 2 domains: the default one and a new one. You can create as many new domains as you have SWFs to load.

What will happen now if you unload your SWF? All classes are no longer in the same box, and the Loader that loaded our SWF has a reference to our new domain.  That means that when you unload your SWF, the domain (box with definitions A, B and C) will be removed and memory freed. Yay!

Conclusion

So what does that all mean? Should we create a new domain for EVERY file that we load? Sure you can. But you shouldn’t. There are some nice functions such as getDefinitionByName() that I want to be able to use without searching for the domain in which my definition is contained. If I have a mini-game that requires 20 SWF files, searching for that little symbol in all these domains can be painful. I would rather create 1 new domain (say domainA) and load all 20 SWFs into it. Then I can access my symbol definition from domainA, and unload this domain when no longer needed. For a second mini-game, I’ll create domainB. The idea is not to stick everything into the application’s domain.

Please tell me if this post helped you with your memory usage. Also, feel free to add to my explanation if I missed something.

AS3 Mystery: null, false, 0, “”, NaN

This week I’ve been running unit tests and couldn’t understand why some of them were failing for no obvious reason. To understand why some expressions evaluated to true when they were supposed to be false. I know that I should be careful with null vs false values, but never could I have imagined that the Number 0 can be equal to an empty String!

I know that php’s empty() function is quite permissive, but I though AS3 was much more strict (with strict typing and all). And so I ran a different kind of test, where I checked these values in depth. Here is a table describing my results.

  null false 0 “” NaN
isNaN()          true
== “”   true true true  
=== “”       true  
== null true        
=== null true        
== 0   true true true  
=== 0     true    
== false   true true true  
=== false   true      
is Number     true   true
is String       true  
is Boolean   true      
is Object   true true true true

 You will notice that NaN is actually a Number and an Object, that 0 == “” == false and that false is actually an Object. There are quite a few surprises in there that will make me appreciate strict comparison.

April Fools’ Prank on my CTO

Today the development team decided to make the CTO freak out. Here is what we did to the application currently in development:

  • Play the Skype ringing tone in a loop
  • Prevent important data from loading
  • Hide the CLI after 1/2 second (long enough to see it appear)
  • On the 3rd run, display a fake Confickr C popup that seems like it’s uploading financial data, with a nice progress bar and all
The effect exceeded our expectations. Everybody had a good laugh at the end.

Flex 3D and Wiimote

I haven’t blogged in a while. Too much work to catch after the conference.

I’m having a lot of fun with 3D in Flex lately. I found this really great open source library papervision3d. It’s incredibly easy to use. I got the hello world to run in my existing Flex app in under 5 minutes. It’s not using the native Flash 3D so it can be run in Flash Player 9.

After reading their blog, I also found out about the SourceBinding framework (currently in alpha stage). However, the following video is a must-see for all gadget lovers.

A few places still left for the PHP Quebec Conference!

 

The PHP Quebec team is waiting for you from March 4 to 6 at the Hilton Hotel downtown Montreal for the 2009 PHP Quebec Conference.

The Seventh Annual Conference PHP Quebec will start in 2 weeks. This event - the largest of its kind in North America - will last three days and will include some 55 conferences and workshops, a job fair, a cocktail and many informal ways for “networking”. There are so many activities that we had to reserve four different rooms to allow all participants to attend. Topics discussed include security, databases, project management, best practices, and we will have special presentations on frameworks and CMS to name just a few.

One of the featured speakers of the Conference in 2009 is Zeev Suraski, co-founder of Zend Technologies. In his presentation entitled “Why PHP Wins”, he will explain how PHP became the programming language of choice for web developement. Recall that Zeev Suraski had contributed to develop PHP 3 with Andi Gutmans in 1997 and PHP 4 in 1999. Sign up today for this unqiue chance to meet him in person.

Several workshops - the PHPLabs - will be “interactive”. Speakers and attendees will discuss about solutions based on real life experience. That is why it’s suggested that you bring your laptop.

Please note that only a handful of places remain, so don’t wait. Register online before February 28 and to secure your presence at the conference.

For more information visit the conference website:
http://conf.phpquebec.org/

Hope to see you there!

CodeIgniter at PHP Québec

Here is the code produced during the CodeIgniter presentation at PHP Québec yesterday.

foot.zip

lastIndexOf with RegEx?

I was quite surprised that Flex did not have a way to get the index of the LAST matching substring. I want get the index of a word’s first character based on the cursor’s position (I’m working with the text property of a UITextField).

To achieve that I’m getting all text in front of that word: text.substring(0, cursorPosition). Then, I simply want to search for the last non-word character (\W), if there is any. That way, I can have the index of the first character of the word.

So to get the last non-word character, I can’t use lastIndexOf() because it doesn’t support RegEx, I can’t use match() because it returns an array of substrings instead of indices and I can’t use search() because it returns the first index, not the last.

There is a way around the missing “searchLast()” and “searchAll()” functions.

I get a substring before the cursorPosition: text.substring(0, cursorPosition)
I loop through all characters backwards and check if it’s a non-word char.
Once I find it, I record the index at which it was found. 

There might be other ways to get the beginning of a word based on cursor position, so don’t hesitate to share them. I really hope that the next SDK version will come with searchLast() and searchAll() functions.

Super xiao

Remember “Animation vs Animator”? Well this is better!

WordPress Themes