Calendar

<<  juillet 2009  >>
lumamejevesadi
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

(juillet 2, 2009 09:30)

 Beautiful Code

Leading Programmers Explain How They Think

By Andy Oram and Greg Wilson


Find it on Amazon

Summary of the editor

This unique and insightful book is a collection of master classes in software design.
In each chapter, today's leading programmers walk through elegant solutions to hard problems, and explain what make those solutions so appealing.

This is not simply another design patterns book, or another software engineering treatise on the right and wrong ways to do things. Instead, it gives you the chance to look over the shoulder of some superb software designers and see the world through their eyes.

Thirty-eight master coders think aloud as they work through a project's architecture, the tradeoffs made in its construction, and those moments when it was important to break rules.

My criticsm and comments

This book is an interesting reading to do, but to me, a bit inegal. Some chapters are very good and interesting and let's say I was less sensitive to other ones. What i will do here, is just giving a word about some chapters I found among the ones of best added values.

Chapter 2 : "Subversion's delta-editor interface as ontology" by Karl Fogel

This chapter will show a concrete example of how a classical problem can be solve : tree comparison. It uses as example one core API of Subversion, written in 2000 and still unchanged until now. The main interesting part is showing how you can do the choice of implementing a restrictive API to force users to use it in a given manner. As a consequence, all the future code becomes very predictible and the current porgram is much more robust.

Chapter 7 : "Beautiful tests" by Alberto Savoia

I'm working in TDD for years now and this chapter just bring some testing approach to you. It starts with a very simple code example : the dichotomic search. This algorithm seem to be very simple but 12 years have been necessary to provide the first implementation proven to be bug-free, even with dealing with very large arrays.

What I like in this chapter ? The explanation of the testing strategy : which test you can write and until which point you go to be almost sure your code is bug-free.

Chapter 8 : "On-the-fly code generation for image processing" by Charles Petzold

Charles Petzold is delivering here a very interesting chapter, showing two meanings of the word "beautiful". It starts with a simple - and elegant - code to apply raster operation on images. It works good but is not so performant. As a consequence, he shows us how can generate IL code that will do the image transformation, and above all will be fast. His strategy ? Just generate minimalistic code, that won't have any loop or predicate, limiting the numboer of access to array element, ...

Chapter 14 : "How elegant code evolves with hardwares : The case of Gaussian elimination" by Jack Dongarra and Piotr Luszczek

They present here the evolution of one of the core method of the system LINPACK, LAPACK and ScaLAPACK. What is very interesting is how they made evolve the code to adapt it to the successive computer architecture.

Chapter 17 : "Another level of indirection" by Diomidis Spinellis

A nice explanation of the implementation of the core of FreeBSD dedicated to the IO operation: how an additionnal level of indirection can elegantly support the different type of file system : FAT-32, ISO-9660, NTFS, ... and can even simply support their specificities like security checks. 

Chapter 23 : "Distributed programming with MapReduce" by Jeff Dean and Sanjay Ghemawat

MapReduce is used internally at Google to execute processing of a huge number of data on a huge number of computers. They describe here how we can take advantage of this framework / API to let our programs being executed on a large scale of clusters, and then re-collecting the data into the main application. One of the introduction sentence is clear enough :

"Suppose that you have 20 billion documents, and you want to generate a count of how often each unique word occurs in the documents. With an average document size of 20 KB, just reading through the 400 terabytes of data on one machine will take roughly four months."

Chapter 31 : "Emacspeak : the complete audio desktop" by T. V. Raman

He explains here how he took the Emacs system to provide him with an audio system. What was the most interesting ? The way he does. Indeed he didn't modified the original code but worked in AOP (Aspect oriented Programmation) using the advice functionality of Lisp to provide Emacs with new aspects : the ability to speak.

Conclusion

This book shows interesting code in various languages. Maybe some chapters will be harder to read because you are so unfamiliar with Haskell or Lisp. But anyway, go for them ! They will show interesting thoughts and may point out some functionality of the used language that will let you think "How I would do that in .NET ?". No doubt that this book will inspire you and give you many new ideas !

Go for it !

Want to find more about the books I have read ? Go to my bookshelf to find the few criticism I have already made !

(juin 12, 2009 08:51)

Recently I have been in the need of extracting  kind of a "call tree" of some functions of my code.

More exactly, it was not such the call tree, but I was needing to be able to list of methods being called by a given entry point, and then seeing the size of each tree.

NDepend can very easily give this information. Let's see how !

Let's start with code

Let's write some code that we'll use to validate our results. We'll start with a very basic set of class that will call each other:

namespace ClassLibrary1
{
   public class SecondClass
   {
      public void DoInSecondClass()
      {
         this.PrivateMethod();
      }
 
      public void DoInSecondClass_NoPrivate() { }
      private void PrivateMethod() { }
   }
 
   public class TopClass
   {
      public void Do()
      {
         this.FirstMethod();
         this.SecondMethod();
      }
 
      private void FirstMethod()
      {
         SecondClass obj = new SecondClass();
         obj.DoInSecondClass_NoPrivate();
      }
 
      private void SecondMethod()
      {
         SecondClass obj = new SecondClass();
         obj.DoInSecondClass();
      }
   }
}

Let's create our NDepend project

Our project is very basic but should be enough to validate our results. So now, we will create our NDepend project to start collecting (and validating) our metrics.

  • Start NDepend
  • Click on "Home / Start" and choose "New Project"
  • Give a project name ("NDepend Test" for instance) and the location where you want to store it
  • In the Code to Analyse tab, click on Add assemblies of a Visual Studio Solution and select the project you have just created.
  • In the Report tab, click on Select All

And here you are, ready to start the analysis ! Just click on Run Analysis and wait for NDepend to prompt the report.

Let's dig into the called method

We now want to find all the methods called by our entry point.

At the end of the analysis, NDepend pops up the report in your favorite browser. However, we'll close it for now and we will search our entry point in the Class Browser. To do that, either use the Show Menu button in the menu, or the hotkey ctrl + alt + C.

Just select the method you want, right-click on it, and select Who I use indirectly and then SELECT METHODS WHERE ...


Click on the image to enlarge

What happens here ? NDepend will generate for us a CQL Query. A CQL Query is written using the CQL language, a SQL-like language that allows us to run queries against our code to extract some information, statistics, .... Here we are using the following query :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy

When we look to the result, it looks pretty good, unless that we do not have the number of line of code. Easy. We can just update the CQL Query like that :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy, NbLinesOfCode

and here the result we get :

Of course the last column is visible only because we have altered the query to add another ORDER BY clause

Any graphical representation ?

It would be very nice to be able to extract a visual call tree with all the methods we have here in the CQL result. And of course, this can be done easily. Just go to the CQL Query Result page and right clic on the line marked 8 methods matched. Then you can choose Export 8 methods matched to Graph


Click on the image to enlarge

Antyhing missing ?

What we have here is pretty cool to find quickly information and in our case the dependencies between methods. Anyway, there is a functionality that could be nice to be added on the graph. We may start viewing a graph not from a CQL Query result, but from a list of assemblies. And thus it could be interesting to be able to :

  • From a graph of assemblies dependencies : doing a zoom meaning double-clicking on an assembly to see the type dependencies of that assembly
  • On a type, being able to do a zoom, meaning double-clicking on the type to see the method dependencies of that type
  • On a mehtod being able to right-clic to add to the graph or the callers, or the callees

Conclusion

 Anyway, even if some functionalities could be added to the tool, NDepend is a very interesting tool, easy to learn and very powerful - especially due to the CQL language.

Give it a try, and comment about our use !

(juin 12, 2009 08:40)

A few months ago, Patrick Smacchia offered me a professional licence of NDepend so I can try it on my current projects.

I was already knowing NDepend as being a reference tool for analysing code, extracting metrics, ... but I never had the opportunity to really trying it. But I was so far from the truth !

Unfortunately, I have had very hard months with many things to do (day to day job, articles, conferences, ...) and I have had to postpone so many times my trials.

But better late than never ! It's now on my top priority list and all the trials I now do with the tool show me the extarodinary possibilities of the tool. I will explain in a next post what was my first use of NDepend.

Ready for a try ? Just download a trial version of the tool and have fun !

(juin 5, 2009 08:58)

As I explained some time ago, I was writing an article about Continuous Integration in the Microsoft.NET world for the (french-speaking) website http://www.developpez.com/.

The article has been phased as follows :

First Part (published on March 4th - available online here) - 43 pagesSecond Part (published on June 5th - available online here) - 62 pages
  • Quick introduction to continuous integration
    • Why do we want Continuous Integration
    • What is Continuous Integration
    • What do we call BVTs
  • Quick presentation of the tools needed for Continuous Integration (in the Microsoft.NET world)
    • MsTest
    • Static Code Analysis
    • MsBuild
    • TfsBuild
  • Unit Test : Writing unit tests with MsTest
    • Structure of a test class
    • Checking the correctness of a test
    • Testing the non public API
  • Unit Test : Executing tests with MsTest
    • Via Visual Studio 
    • Thru Command line
  • Unit Test : Configuring tests
    • Test Runs naming
    • Code Coverage
    • Deploying files
    • TimeOut
  • Unit Test : Managing the tests
    • Via the "Test View"
    • Via the "Test Editor"
  • Unit Test : Additional attributes
    • Behavioral attributes
    • Informational attributes
  • Static Code Analysis : Presentation
    • Activate the analysis
    • Running the analysis
    • Explication of the rule naming
    • Parameterizing the analysis
  • Static Code Analysis : Correcting the errors
    • Correcting one error
    • Correcting several errors
    • Grouping the rules suppression in a global file
  • Static Code Analysis : Limitations
  • Quick introdution to MsBuild
  • First steps with MsBuild - Writing a basic project file
    • Its structure
    • What is a task ? a target ?
    • Creating and executing a project file
  • Going further with MsBuild
    • Ensure the project file is valid
    • Properties and PropertyGroup
      • How to statically & dynamically create them ? To use them ?
      • Order of declaration
      • Updating the value
      • Delaying the creation of a PropertyGroup
    • Items and ItemGroup
      • Same detail as for Properties
    • Executing a project file in command line
      • Choosing the target to execute
      • Overriding properties
      • Playing with verbosity
    • Using .NET 3.5 tasks
    • Playing with Targets
      • Control the execution order
      • Explicit call of a target : 3 techniques and their differences
      • Passing input and output parameters to a target
  • Refactor a project file
    • .targets files
    • Importing files from Source Control
  • Create your own tasks
    • A simple one, with inputs (mandatory or not), with outputs
    • Raising errors
    • Debugging your task
  • Quick introduction to Team Foundation Server
  • TFS & Continuous Integration
    • Create, edit and execute a build
    • Parameter a build
    • Which target can you override ?
  • Managing TFS
    • Destroying, Undoing and listing files
    • Presentation of TFS Power Tools
  • Tips & Tricks

To read this article, just go to http://dotnet.developpez.com/ or directly to my webpage on this site : http://pedautreppe.developpez.com/.

Note that these article are available only in french for now, but do not hesitate to leave comments here if you think the content is interesting and that it could be interesting that I translate it.

(avril 7, 2009 09:21)

Last week, I was in Geneva with Norman Deschauwer to give two conferences in the XpDays.

About our sessions

It was the first time we were giving these sessions with Norman, and I'm quite happy of this experience as we received many questions during the sessions and lots of good comments after the sessions ! You were almost 100 assisting to the conferences: more or less 35 for the first one, and more than 60 for the second one. 

If you have any other comments about

  • the way we did the presentation
  • the content itself
  • missing information or redundant information
  • any other subject

please do not hesitate to leave a comment to this post, and Norman and I will be happy to complete our explanations here and to take these remarks into account for our next conference !

In the meantime, you can download our slides here :

All the slides (including the ones of the other sessions) are available on the xp day website.

About the speakers

I have been able to meet nice other speakers during this event and many of them have already blogged about it. You will find below the list of all speakers and some information about them (either LinkedIn contact or their blog). Whenever possible, I will include a link to their post speaking about the event.

Speaker NameBlog and posts about the session
Portia Tung Her Blog - Her post
Pascal Van Cauwenberghe His Blog - His post
Didier Besset  
Isabelle Therrien  
Frédéric Schäffer His company blog
Dominic Williams His WebSite
Nicolas Charpentier His Blog - His post
Jérôme Layat  
Eric Mignot His Blog
Gabriel Le Van  
Philippe Kernévez His WebSite

About the event

It was the first edition of the Xp Days in Switzerland but the Agile Swiss team did a very good work ! Apart of too little space in front of the rooms to be able to speak confortably during the "inter-sessions", nothing to say about the organization. Just a warm applause to all of the organizers !

Really waiting to see the next edition and hoping we will be able to present again a session there ! They were speaking (joking) to organize the next edition in the Château of Gruyère. Well not so probable, but would be very interesting ! :-)

Just a few photos to conclude the post (not mines) and I hope I will see these guys and girls in the next edition or at the next CITCON !

On stage during our firts session
"Return of Experience: XP with industrial dimensions"
Back on Stage : 1mn introduction to our second session :
"Using together Waterfall and XP tools"
After the effort : a very good Swiss restaurant with some of the conferencers The "Agile Swiss" team (part of it) in debriefing during the day

Powered by BlogEngine.NET 1.2.0.0 | Theme by Pierre-Emmanuel Dautreppe