Monday 23 June 2008

Explicit localization in EPiServer

This time I want to write about a feature which for sure is not new but I think many people (including myself a few days ago) are not aware of it. Explicit localization is actually a ASP.NET feature, it's nothing EPiServer specific but it can be very useful in EPiServer world. In fact it's all about one following line:


<%$ Resources: EPiServer, admin.admingroup.deletegrouptooltip %>


What it does? It will search through language files and will find a label associated with the "admin.admingroup.deletegrouptooltip" key for currently selected language. What is so cool about that? Well ... the best thing is that you can use it with labels, as a error message for validation and so on ... let me give you an example:


<asp:Label Text="<%$ Resources: EPiServer, usersettings.username %>" AssociatedControlID="UserName" runat="server" />
<asp:TextBox ID="UserName" ToolTip="<%$ Resources: EPiServer, usersettings.username %>" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="UserName" ErrorMessage="<%$ Resources: EPiServer, login.error.username %>" runat="server"/>


How can you set for example localized tool tip for a button not using that approach? I guess the only option is to do that in code behind file in a following way:


UserName.ToolTip = Translate("/usersettings/username");


It's only one additional line ... but having all settings for the control in one place gives you cleaner code, so in the end less chances that you will overlook something. Moreover if you make a mistake typing the label key, you can correct it and see the results with recompiling the code which can save lots of time.

You can find many examples of this syntax (including the one which I used here) just by checking EPiServer's Public Templates.

Thursday 19 June 2008

Don't go dark!

Recently I found very interesting post of Jeff Atwood regarding developers and bad practice of going dark. It was so thought-provoking that I decided to write a few my opinions how it looks like within Cognifide. By going dark we should understand situation where developer is "locked in his room" for a long period of time implementing some piece of functionality until job is done. Definition of 'long period of time' will vary across different organisations. In our case, in ASP.NET team we try to manage granularity of tasks in way that new modules can be implemented in days. If implementation of some module is going to take 1 week then it's considered as a big task. So going dark for us would mean that some developer is "locked" for longer then 1 week working on some gigantic feature. What's wrong with that?

Actually dropping such code-bomb can potentially create many problems:
  • if there was any bad design decision made then whole new feature can be rejected as it may not fit to main project design. Please note that while developer is in the dark working on his feature, main project keeps changing,
  • it's hard for other team members to understand and maintain new code
  • it's almost impossible to do code review

Fortunately for us, we use SCRUM to manage ongoing work. Daily meetings significantly reduce risk of going dark, so good for us! But is that enough to be happy about the process? Jeff pointed out two things:

"The brilliant developer must be capable of performing on a team,
making his work visible in modest increments and subjecting it to
scrutiny as it matures."


and

"Hiding your code until it's "done" may feel safer, but it isn't.
Sharing your ongoing code with your coworkers is scary, much less the
world -- but it also results in feedback and communication that will
improve your code and draw you closer to the project you're working on."


I would like to highlight this part: "feedback and communication will improve your code and draw you closer to the project".

Why is that important for me? From my perspective it doesn't matter so much if you are working on one huge project for a long time or on a few smaller, at some point you have your habits, your ways of dealing with tasks. After some time you have already solved most of the problems which means that implementing yet another class/module/feature will not give me much in terms of new skills, my code won't get better, in fact I'm quite sure that it will stay exactly the same.

Few ideas how to change it, how to encourage people to talk about code quality and good patterns and this way learn new things:
  1. pair programing when implementing bigger features. Main point is to avoid situation when there is only one person working on the feature and in the end this is the only person which is capable of maintaining it. I'm not saying that people should all the time sit together and do proper XP, work in parallel as much as you can. Important is that working with someone enforces communication and design discussions which in the end prevent from going dark.

  2. code reviews, that seems to be the most obvious way of improving my code, I need feedback from other people! Of course it would be great to see senior developers taking active part in code reviews, that would be the best way to share knowledge. But also it's worth to know what less experience people think, fresh approach is also important! :) As I see it, code reviews makes the most sense in the early stages of each project. But also it would be nice to have a 'code review' session once a month to point out some fresh ideas (people don't necessary need to show bad habits ... good practices should be also presented!). Important is to take notes, find consensus and write it down!

  3. internal demo after each iteration, it's vital to keep everyone up-to-date, it's also important to reuse similar approach designing all modules. That is another chance to communicate with peers, to get others people opinion. And additionally, it makes much more sense for end user when delivered project works and acts as a coherently designed system.


In the end, one last point ... I believe that none of us would like to end up doing one-man projects all the time. It usually means very small progress or no progress at all. We have lots of smart and clever guys around, we have opportunities which people in one-man project don't have so let's make a use of it. Don't be anti-social, communicate and improve your code!