DCSIMG
January 2011 - Posts - Uri Lavi

January 2011 - Posts

Sixth Software Craftsmanship Meeting

Our six meeting will deal with a Software Engineering technique called: "Refactoring".

This is one of my favorite techniques, which is usually misunderstood and overlooked (e.g. Refactoring != Rewriting).

So, here are the details:

Subject: "Refactoring Workshop

We will refactor several real life examples in pairs (or triples). 
Also, we will be demonstrated with the techniques to create a better code.

Please bring your laptops (with the environments set-up) to the meeting.

 

Time frames:

18:00 - 18:25 - Gathering / Mingling
18:25 - 18:30 - Short Intro / Explaining the meeting's set-up 
18:30 - 19:30 - Refactoring I (60min)
19:35 – 19:45 - Break + Giveaways
19:45 – 20:45 - Refactoring II (60min)
20:45 – 21:00 - Wrap-up + Giveaway 

 

Giveaways:

We have great giveaways to give during the meeting. DON'T miss them :)

 

Food:

Although we are plaining to have basic food, please also bring something with you for the group. 
(Thus we will be able to support the event with the user generated food).

 You can register here.

Posted by Uri Lavi | with no comments

One small step for a man, one giant leap for mankind

Lately I had a lot of thoughts about how to introduce a change within an organization.

For a while now I am giving some talks about leading a software development team, focusing each time on a different facet, such as: Quality, Architecture, Recruitment Process and etc...
(I have combined some of those thoughts into a short lecture, which I entitled Fostering Software Craftsmanship (Building Successful Teams) and it is given as a part of the IL Tech Talks).

But here is a phenomena, I encounter each time.

Most of the audience understand the importance of the concepts, but really struggle with introducing them to their organization.

Warning

  • Writing Unit Tests will lengthen my development time!
  • How much time should I "reserve" for doing Refactoring?
  • How do I explain to my manager that Refactoring is important?
  • Code Reviews are difficult, because people have different tastes!
  • Code Reviews are taking too long! We will not be given the time to do it, ever!
  • Continuous Integration will take a few weeks to accomplish. I won't be given any time to do it in the near feature!
  • Those concepts are great, but the time to do them should be allocated by the management.
  • ...

I am sure we all heard those sayings. Heck, we even have given those once! (No... Not really :) )
Though I have a lot to say and comment about each and every one of the above statements - there are some broader aspects I must cover first.

We all hate changes, don't we? Doing Unit Tests, investing our time in Refactoring (or Builds) - those are just an extra activities that we have never done (or done correctly).
One should really invest his own time in order to polish those activities and doing so is just recognizing that we need to change. As humans, we find it extremely difficult to accept changes.
Jack Welch understood it perfectly, but nevertheless he succeeded to introduce a lot of changes to GE. Jack Welch found the change to be exciting, daring and imaginative.
GE success can be rooted to its ability to change and to change fast.

However, applying change in the simplest way doesn't work.
We cannot accept the change all at once. Evolution takes its time; Therefore, in order to accept the change we also should adapt one step after another.
(It's really like Refactoring Steps: One small change at a time, compile and test).

Sometimes it takes years to introduce all those concepts to your teams:
Start by a simple task, like code conventions or source control layout, then teach unit tests and invest in teaching code smells, continue by applying rigor Code Reviews and etc... and etc...

Doing everything in one big bang just doesn't work. I have seen several teams that got introduced to Scrum or TDD in a matter of weeks. Those are big changes to somebody who didn't evolve to the "right" point. Needless to say that the failures that those teams experienced were so discouraging that till now some of those Software Engineers hate TDD and claim that Unit Tests (even not TDD) are plain waste of their time.

You shouldn't be surprised that applying all the great concepts to your organization will take years.
One step after another; One small step for a Software Engineer, one giant leap for an Organization.

Close-up of Astronaut's Foot on Lunar Surface

Posted by Uri Lavi | 1 comment(s)

Code Smells

If you like practicing in identifying code smells, then you can find below a short class called TimerManager.

public class TimerManager
{
    public delegate void TimerCallback(object data);
    private static readonly object _sync = new object();
    private readonly Dictionary<int, Timer> timers = new Dictionary<int, Timer>();
    private readonly Dictionary<int, TimerCallback> callbacks = new Dictionary<int, TimerCallback>();

     public void SetTimeout(TimerCallback timerCallback, int snooze)
     {
            var timer = new Timer(snooze);
            lock (_sync)
            {
               timers.Add(timer.GetHashCode(), timer);
               callbacks.Add(timer.GetHashCode(),
               x =>
               {
                  lock (_sync)
                  {
                     var t = timers[x.GetHashCode()];
                     t.Stop();
                     t.Close();
                     timers.Remove(x.GetHashCode());
                     callbacks.Remove(x.GetHashCode());
                  }
                  // invoke function provided by caller
                  timerCallback(null);
                });
            }
            timer.Elapsed += timer_Elapsed;
            timer.AutoReset = false;
            timer.Start();
      }
}

Here are some Code Smells, that can be identified:

  • TimerManager (a weak smell) - Everything that is called a manager alerts me a great deal.
    Usually managers are God objects, have low cohesion and high coupling and violating too much OO principles...
    It doesn't necessary mean that the same happens here, but it should be noted and then verified in the code.
  • TimerCallback should be generic or restricted by a Data Type.
    It's better to specialize the TimerCallback with more concrete type parameter. Having said that, it might be that the author wanted to use the built in TimerCallback in .NET.
    In such a case the declaration is redundant.
  • static _sync object.
    The class has only instance members, besides that _sync object; Will it make sense to do the following?
TimerManager timerManager1 = new TimerManager();
timerManager1.SetTimeout(...);
... 
TimerManager timerManager2 = new TimerManager();
// here timerManager2 will block on the same object as the timerManager1
timerManager2.SetTimeout(...);
  • Both Dictionaries are just plain procedural programming definitions; It is the same like having 2 arrays aligned by their indexes as both the dictionaries will be accessed by the same index (an int).
    Behold, as one mistake (accessing the wrong index) can lead this code to an undefined behavior.
  • GetHashCode shouldn't be used to identify uniquely an object.
    Let me repeat again... GetHashCode mustn't be used to identify uniquely an object...
    GetHashCode's implementation is needed for collections (and Equals, see below).
    Sometimes the same result of the hash code will put two different objects in the same hush bucket - which means those are not unique identifiers!!!
  • Once implementing GetHashCode, the Equals method should be implemented as well.
  • Consider the follwoing code:
t.Stop();
t.Close();
  • One should be familiar with the tools at the hand.
    Close() does what Stop() do and more... Calling Stop() and then Close() just makes the method a little bit longer without any effect.
    When in doubt, consider to take a few moments just to review the provided API.
  • Redundant Remark.
    The remark repeats the code, doesn't bring anything informative enough and affects the length of the method.
    It can be safely removed.
// invoke function provided by caller
timerCallback(null);
  • Thanks to Aviv the following is of course another smell: passing null to the callback function (i.e. declaring the parameter in the callback and eventually passing null).
timerCallback(null);

TechEd 2010 Thoughts

TechEd Eilat 2010 is long over... And with all the hassle of day to day work and other obligations only now I have found a few minutes to write my thoughts.

As everybody who has previously attended such a venue would tell you, Microsoft really knows how to set-up and orchestrate such a huge event. It is really impressive to see...

Instead of summarizing the events from each and every day I have decided to draw a different perspective and to provide some analysis (which of course reflects my and my thoughts alone) on Microsoft's behavior and its future roadmap...

Here are some facts that I have learned:

Windows OS

Windows OS:

Windows 7 is considered to be a very good operating system.
Microsoft revealed that in 2010 over 240M licenses were sold, almost 88% of the business are moving to Windows 7 and their projection for 2011 is ~409M in licenses.

The adoption of Windows 7 is important because most of the users/businesses previously voted by not upgrading to Vista operating system. Being able to move the users to Windows 7 is important in order to minimize the risk that the users will stay with an old platform and thus (potentially) will be more open to move to other browsers and operating systems. Therefore Microsoft can rest in piece for now, as its clients starting to upgrade to their best OS (till now) which of course opens different perspectives and deepens the control of the IE (Internet Explorer) browser.

And while talking about the browser...

Silverlight IE9

HTML 5/Silverlight:

After having the web filled with rumors that Microsoft is killing Silverlight and the official blog post by Bob Muglia, Jason Zander specified in his opening talk that Silverlight should aim for the following scenarios: a. Business Applications b. Devices (Windows Phone 7) c. Streaming Media. He also emphasized that as Micrsofot were always good in supporting standards, Internet Explorer 9 fully supports HTML 5.

Looking into the future it's actually not surprising. Our web browsers can be safely considered as the next operating systems. Our work routine is around a browser, not only by browsing web sites, but also by utilizing them as applications for news, newspapers, eBooks reading, e-commerce, banking, development and etc... Therefore it is very important to Microsoft to be as much compatible to the standards, especially when Silverlight didn't provide the expected adoption rates.

Jason mentioned that the IE team has rebuild the JavaScript Engine and improved speed, GC and its interop with the DOM. Everyone who is familiar with the speed comparisons between the browsers will say that it was a necessary step in order to allow the IE to compete with others. Just a thought here, how about releasing the JavaScript Engine as an open source :) ?

Azure:

TechEd2010.Thoughts.WindowsAzure.PNG

Finally a cloud; Microsoft invests a lot of effort in Azure. It starts in investing a lot in explaining why PaaS (Platform as a Service) is a better choice for developers than IaaS (Infrastructure as a Service), continues with providing very good tools for developers (about that in a moment) and finishes with demos and facts about the ease and speed of the development on Azure.

One of the really good demonstrations was a demo of how to develop one application and deploy it on Web (ASP.NET MVC), Windows Mobile Phone 7, Kinect and Azure. Microsoft has been known for years for their top-notch development tools which easily integrate one with another. By allowing developers to deploy the application into the cloud (Azure) in a minimum effort, Microsoft's assures better chances of adoption.

All in all, I had a great time.
Thanks to Microsoft for inviting!

Posted by Uri Lavi | with no comments
תגים:, ,