Be Careful with Renderers

17 06 2009

After we added one fancy renderer to ADG to highlight our search results in case user performed a search I noticed that vertical scrolling slowed down way too much.

After some investigation we found the culprit: in case when no search was performed the renderer filled the cells with white solid fill using beginFill() and endFill(). We substituted this to just graphics.clear() and everything was fixed. So it appears that beginFill() – endFill() is quite expensive though primitive operation. Not funny :)





Mate: Drinking and RIA Development

21 05 2009

It happened almost at the same time when I introduced myself to Mate-as-beverage and Mate-as-Flex-Framework :)

Both things are good stimulators. When you drink Mate it is a kind of a ritual, not just like you buy a bottle of Cola and just drink it. To prepare a good Mate you need to put a piece of your soul and some good thoughts into it, not to say about technology: the water must be of a particular temperature, you should know how much Mate to put in, how to pour water into it, etc. etc. When you done it well you are relaxing, your friends are relaxing and everything is just fine, everyone enjoys a good drink. If you done it improperly people will drink it, they will tell you it’s tasty but they will think “what the fucking crap is it?” ))

The same thing with Mate framework. Proper developer armed with Mate will make the design simpler and cleaner. When applied in wrong way it can make the application heavy and hard to understand. After few monthes of sometimes hard work I have something to summarize and say on this framework, maybe this will be helpful for some readers:

  • the first thing to say: coding with a framework is more productive then coding without one. This is true in general and true for Mate. If you don’t agree with this – go and code for some bananas.
  • Mate provides a variety of weapons that are nicely arranged as MXML tags. After you’ve become friends with few of them you can intuitively understand all others since framework is coherent and consistent. The latest thing I think is due to the fact that Mate is writen by a very small team and the core is actually written by a single man: Nahuel Foronda.
  • As it would be real damage for your body if you drink liters of Mate each day and if you don’t drink anything else the same damage will occur to your application if you use Mate here and there without a mind. I went through it and I know what I say. Do not use Mate if you can do simple things inside your single class. Do not overcomplicate the design. I mean if you can dispatch and catch some minor helper event inside the same object you should bypass Mate event maps.
  • Now about drawbacks. I encountered only one real drawback but in my case very important one: if you need to generate some models/views dynamically whitin the life-period of one swf and if you need to remove such views from the display list and substitute them by fresh ones you can go into trouble. The troubles will happen if you use injectors. Though the Dependency Injection is real power allowing you brain to not control each and other step in your algorithms sequences it creates a lot of bindings which  you can not delete in case you are removing your view from a display list.  So no matter how thoroughly you clean up your models/views that you don’t want to use anymore, no matter how many variable = null assignments you will do almost everything handled by those bindings will remain in memory and not GCed.
    Though still Mate can be used in this case: just without dependency injections. You still have EventHandlers, MethodInvoker and DataCopier workhorses that can save you a lot of time.
  • My next thought may sound a bit heretic but I decided to keep the rule: minimize number of injectors in your event maps. Almost everything you reference in Mate xml constructs you reference by class names, not by some ids of concrete instances. So this rule pretty implies that you need to minimize the number of classes you are referencing in your event maps.

In general: Mate should and can be used for real applications development. I am sure that each developer using this framework will serve his own unique flavor of the Mate with its own taste. And this is very right thing: we are all different so why shouldn’t we do different code :p

When I decided to use Mate in my application I didn’t know ANYTHING about it, just have read some websites with different people impressions. But I decided I will employ it anyway. Now I have a framework in my pocket but the pocket is large and there is still a lot of place :)





Focus Management for UI Components

3 03 2009

A very simple post, just in case if someone will have the same problem.

I’ve got a screen, actually a form with a sequence of UI components, some are standard flex components like TextArea and some are custom. One custom component was ignored while user used “Tab” key to navigate from one field of the form to another.

I wanted to fix it very fast and started with hacks like adding an event listener to the previous component’s focusOut event and calling setFocus() method of that custom component. But that was not working like it should so I went to the Adobe Help and found out a very simple and proper fix: what ever your component is, if it inherits from UIComponent you can just add an implements IFocusManagerComponent instruction and current FocusManager which deals with the focus management on the form will handle your custom component in a standard nice way:

focus-management

This all works very simple when you understand that focus management in Flex seems to be design using the Composite pattern. Thanks Max for noticing this.

You can read here about the IFocus Manager component.

Cheers





Consistency vs Choice

16 02 2009

I would like to share in this post one of my conclusions based on the projects experience.

It is very common situation when something can be done in more then one way. For example, you can have List screens where some lists of items are shown. And you can have a small feature there: search by the item name. There are at least 2 distinct ways how you can design the interaction:

  1. User types in a part of name and then clicks some button or icon. Search is applied then.
  2. User types in characters and as he types the list is continuously being filtered

The question that will definetely appear at some moment is which alternative to follow.
Some people can just not notice this fork and will implement some default solution. This way is not good since there is 50% probability that your users will ask you one day “Hey Jack, why didn’t you choose the other way?” and you’ll need to redo.

If you are more smart you will smell the fork and will ask your customer beforehand: Hey John, how would you like this to work?

That will work but still this is not the best solution.

The best one is to have in your application 2 similar List Screens and implement one way on the first screen and the second one on the second. Then leave it as it is. Let the John-the-Customer touch it, play with it and he will come to you one day and select the solution fitting his needs the most.

You may think there is something wrong with such approach, a need to do double-work, but it is easy to smooth out everything when you have different versions. It actually degrades the probability of those 50% when John ask you reimplement the stuff in absolutely different way.

To sum up the bullshit above: consistency always wins the battle through the powers of choice :)





Problem with Flex deeplinking in case you have multiple SWFs on one page

4 02 2009

This is my first time I encountered a situation where guys from Adobe implemented a feature in a little bit fucked up way.

I already wrote about deeplinking in Flex after I read basic tutorials on its implementation. Then my guys have implemented this solution in the application we are now developing and everything seems worked well in local environments.

But then we deployed the stuff in the remote environments where our SWFs are included into quite complex HTML pages of one CRM system. As you already guessed deeplinking didn’t work there.

We started to search why and found a pretty nice Fx JIRA issue which tells us (jesus christ !!) that the deepliking craps in case you have more then one SWFs in your HTML page and your SWF is not the first one.

We are now in the process of finding some solution. I hope we will dind out something in the net, if not we’ll have to fuck with the History.js ourselves.

If you are reading this and you are not a guy who doesn’t care please go to that  issue and vote for it. Adobe chooses issues to fix first depending on the number of votes from community.

Will add someting new when we resolve the problem.

UPD:

Max have solved the problem in following way:
there is a getPlayer() function in the History.js file which is responsible to return needed SWF object. We have modified this function so it returns not the first SWF on the page but the SWF with the specified object ID. It is not very nice fix since needed object ID is hardcoded in the function code but for our needs it suits right. Here is the modified code (pay attention to the ie/ff stuff):

function getPlayer(id) {
//history crash with multiple swfs fix
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

var result = null;
if (isIE)
{
result = document.getElementById("your_unique_id_for_ie");
}else
{
result = document.getElementById("your_unique_id_for_ff");
}
if (result != null)
{
return result
}
// /fix
return document.getElementById("your_unique_id_for_ie");
if (id && document.getElementById(id)) {
var r = document.getElementById(id);
if (typeof r.SetVariable != "undefined") {
return r;
}
else {
var o = r.getElementsByTagName("object");
var e = r.getElementsByTagName("embed");
if (o.length > 0 && typeof o[0].SetVariable != "undefined") {
return o[0];
}
else if (e.length > 0 && typeof e[0].SetVariable != "undefined") {
return e[0];
}
}
}
else {
var o = document.getElementsByTagName("object");
var e = document.getElementsByTagName("embed");
if (e.length > 0 && typeof e[0].SetVariable != "undefined") {
return e[0];
}
else if (o.length > 0 && typeof o[0].SetVariable != "undefined") {
return o[0];
}
else if (o.length > 1 && typeof o[1].SetVariable != "undefined") {
return o[1];
}
}
return undefined;
}

Now about the ID:
You should specify the ID in the HTML where you embed your SWF object: your_unique_id_for_ie where ID for the object tag is specified and your_unique_id_for_ff where ID for the embed tag is specified.





Expandable universe

3 02 2009

Today after some debates with my developers over certain architectural questions I clearly noticed that there is a pretty analogy  between a software developing team and universe as it is perceived in cosmology.

The mainstream cosmology theory treats our universe as an expandable entity which is regulated by different forces: gravity, strong and weak nuclear forces, etc. The same theory can be easily put onto the project and the project team.

If there is no project manager or a team leader the project (where the Code is actually a Matter) will start expand, expand with some acceleration. This happens because developers are carrying agents of the repulsion force. The amount of repulsion force in an average developer is order greater than of gravity forces.

A good project manager or team leader is the atmost gravity center that makes all energy and matter rotating around himself along certain orbits. This makes the project glue together, it still expands but wothout acceleration and very slowly.

Physics gives me a lot of very good abstractions that can be applied in IT and in projects. When you see this – it starts looking very nice :)





RefUcktoring

27 12 2008

I should have been in the mountains today and tomorrow and should have been having fun on my snowboard but this night when time came to get up and pack my things I felt that my throat is a bit ill and decided (it was not easy) to stay at home.

What one have to do when staying at home on weekend. I prefer learning, blogging and drawing :) This time I chosen to write about refactoring, more precisely about my approach to refactoring.
If you’ve been boiling for some time in IT soup you should know a lot of cases when you or your team needed to refactor some complex system. You are lucky if you have the man who built up the current version of the system to do the job but in a half of cases it will be just a dream. In such cases whoever will take the task should be able to:

  1. Analyze
  2. Plan
  3. Implement
  4. Test/Debug
  5. Fix/Finalize

If the person is not capable to perform any or few of the listed parts of the task – then your project is in trouble.

So, in my project the last week was very hot one since it was last week when we could increment functionality, the next few weeks period will be stabilization phase. And the customer wanted us to improve performace of one thing which required a major refactoring. Not to say that we didn’t knew earlier that the bloody thing should be refactored. We knew that but there were a lot of other tasks + speaking honestly noone wanted to do that job since the guy who initially implemented the complex module (he did this well taking into consideration requirements at that time) was no more in the crew.

But like it always happens the customer insisted and there were no choices but to roll up the sleaves and quickly do the job. I estimated it roughly to 5 man/days.

My programming experience is not that much but I had few times before to lead some difficult refactoring as a manager. And each time I applied the same tehnique which always proves to be good:

  1. Analyze
  2. Plan
  3. Implement
  4. Test/Debug
  5. Fix/Finalize

For points 1 and 2 you need anything where you can draw some simple diagrams. I use a kind of mind-mapping diagram where I try to desribe at the first level basic tasks definitions, then as the branches everything I know about the problem (but only needed things) and points where I need to research, then on the next levels concrete tasks that I need to implement to get the thing done. This is a very good materialization of the analizys process. All tasks that I need to implement I mark in a red font to have them sharply visible. It looks like this:
Metrics Data Loading Refactoring

I always keep there only needed info, names of the classes, code snippets, etc.
When I feel the analysis is completed I start the point 3: implementation going from top to the bottom of the diagram. When a particular red leaf is done I mark it with green background. I do some small tests after each step and when all is green I start testing and fixing small things that always definitely shows around.

I completed the task in 12 hours almost without any breaks, even missed my lunch. It was interesting and it works :)
What I actually implemented is incremental loading of data and its caching. Now I know how any abstract caching is done technically. Think this will be useful in future. Big thanks to Max Hryniv who’s code teaches me a lot.
Also I’m not sure that this technique is suitable for everyone. I saw a lot of times when guys skip steps 1 and 2 and start right from the step 3. But almost always it results in UNDERestimation and troubles.





2 brains are better than just one

12 11 2008

I haven’t been here for a while. Just was too deep in my work and only today allowed myself to take a look what’s going on in the blogs of my friends and make some comments.

Because today was a really good day. In my current project I have a release on Monday and still in my favorite (but most complicated) module there are few really dirty bugs that makes this module to look not that nice as it might be. I came today to the office somewhere at 3 PM with a strong intention to fix one of the problems and a belief that I can really to this. My current understating of Flex allows me to analyze almost any piece of code written by any developer and make there needed changes in case of trouble. I’m lucky that all guys in my team are quite autonomous and can take almost any task by a simple input (sometimes I use a sticky yellow note, write there a short description and stich to the guy’s table) and start working on it without disturbing my concentration on some more difficult thing. So thank you guys for this, I love you all.

There’s a one good mate in my team, Max, who is my primary force for that module development. I worked out few necessary management thigs and then we sat together with Max at my laptop and 4 hours were analyzing, debugging and fixing a trouble. We won. I realized this day few very important things:

  • there are tasks in software development that are unarguably better to do with a friend, not alone. I would not be able to fix this bug without Max, definitely. And he was not able to fix it without me in few previous tries.
  • sometimes quite simple (at the end when you find it) problem can cost you really a few days of work to fix.
  • even BEST, ingenious developers mistake
  • fixing bugs can be just a good quest, a good game and a lot of fun if you perceive this activity positively
  • diagrams and visualization of complex activity chains helps invaluably when you try to understand a complex mechanism created by other person. We created a set of sequence diagrams for different functional flows of that module and then benefited a really from having this before our eyes. Max really cool in doing this, he showed me that Enterprise Architect can import Flex packages and convert it into workable items in diagrams. Once again I appreciated how good tool EA is.
  • sometimes you need to sacrifice personal life and some fun to get the things done at your work. Today I planned to meet one girl, an old friend of mine, who I have not seen for a while. But at 6 PM I was still in the middle of the task so I just called her and told “Sorry baby, we can’t meet today, I have a work I must to do.” I felt that this was not a thing she wanted to hear but she’s a good friend and tomorrow will be ok.

So: if you see that some person in your team can’t do some thing despite of working hard on this – go and help. If you trying to do something and it doesn’t gets working – go and ask for a help.





16 10 2008

I was about to write some piece of bullshit into my blog. Was watching a movie and there one funny guy told a thing “blogging is all about to keep a continuous narration”. Hell knows if that was right though or completely crappy but I am definitely almost absolutely sure that it’s not a good idea to write something down when it is a midnight and your brain is kinda tired and wants to say you “bye bye” :)
So… I decided to check if there are some smart things in blogs of the people I know (not that much, really, I mean not that much people I know having blogs and posting something there) and found out that Pavel has written a thing. Whoever can agree or disagree with the theory a dude referenced there by Pavel evolves but it shouldn’t take such a deep philosophical-kind digging to see that software-craftsperson is better then just a good developer or good DBA, or good PM.

Pavel’s post made me think about why do some people need to back there thought upon the identical thoughts of other people who are for some reasons are known by the greater auditory. Proper thought comes from experience and don’t need any “approval” of others.

Also there was a picture describing a “standard team”. I’ve never seen a standard team.. really never, such as it is described on that picture. I think such standard teams are all dead long time ago and if someone tries to revive one it will fade to gray :) Real teams now are agile and consists to some extent of software craftsmens. At least it proves itself that if you have only pure “jave developers” or pure “htmlers” in your team then your chances to get into troubles are higher then if you have people with multidisciplinar knowledge. Also having such people doesn’t guarantee you will succeed instead of failing and delivering sucks.

One more thing that one can see on that painting is that in team of software craftsmen you can’t be just a specialist, you need to add a VALUE to the team, otherwise it will be boring for you with them and they will be bored with you.

So, let’s learn and specialize, then learn and generalize, and then once again learn and become jacks-of-all-trades. And the fact that Pavel named his post “Softare Craftsmen” tells me that he is not a man of theory, he is man of practice, and working with him I really think he is. Thanks for the reference :)

I see that a lot of people are viewing sometimes my blog (can’t see exactly who you are ;) ) and only some leave me a comment (girls, don’t be shy, I’m still single and can have a dates ;) ). That’s normal, most of people are shy or unable of producing a simple few sentences that are linked together and meaningful )) Just whoever watching this and trying to get some piece of a thought – read that article of Pavel and then read the article of the guy referenced there. It’s how it works, the blogging I mean, the network.

Almost forgot… I should name somehow the post… it can’t be without name I suppose. Or can? I will try to submit it without a name. Let’s try :)





Transformation

11 10 2008

I’ve started coding. Holly fuck )))
It’s a nice feeling to see how a little thing is working when you did it by your hands.
Of course I like to see things done by others, but this is completely different taste.

I’m not yet capable of doing BIG things, but I understand other’s people code and can add my little pieces. That’s not bad for start.
It develops ability to reuse and analyze already existent thing + hold in your head a deeper context then you are holding usually while just “managing”.

Today I’ve added a small piece of functionality that looks up by name a node of a tree on the client side (flex), highlights it and automatically scrolls the tree to that node so the user can see it.
Let’s see what I will do tomorrow :)