I’ve written about NDepend on my blog in August and since then the new version (5) has been released. This is a major update, with many changes and improvements. In this text I focus on parts that are most interesting for me.
When we work with the code, we introduce changes, which affect whole code base. We can increase or decrease number of lines of code, complexity of the methods, cohesion of methods and many more. All of those informations can be calculated and shown by NDepend. Those statistics show only the condition of the project in the current point of time. It would be very helpful to know how those metrics change in time. What was the complexity two weeks age? How many types did we have one month ago? If we could compare current values with the historical ones we could say if our changes are good for the project, if the quality of the code is increasing. In essence the ‘Trends’ feature give us such possibilities.
(The image is from NDepend side, because I didn’t have enough data to present a nice chart)
NDepend has now the ability to store it’s own analyzed data and base on it computes charts. On those charts we can see changes of various code metrics in time. The longer we work with NDepend (by default the trends log are calculated once a day) the more accurate our charts are.
By default the tool comes with a set of predefined trend queries. As usual, with NDepend, you can write your own queries (using CQLinq) and use them.
The trends became my favorite, new, feature of NDepend. I can say, that I’m a bit addicted with them. At least once a day I like to spend a few minutes on analyzing them. This gives me a good overview of a whole project.
It is always nice to have one, central, place where you can look and see the most important things. NDepend5 introduces such a place in the form of a ‘Dashboard’ view.
The dashboard contains predefined section with basic statistics and code rules. In addition we can change the view by adding various trends charts to it. It is worth mentioning that every chart view can be fully customized.
The dashboard is a nice starting point for using NDepend. For the new users it can also lower the learning curve, giving the advices which features are the most important and should be checked.
New look and feel
The user interface has been completely redesigned in the spirit of ‘flat’ design principles. It uses pastel colors on white backgrounds, clear and easy to read fonts. The GUI is now coherent with Visual Studio 2012/2013 style. When you work with NDepend5 you feel that it’s part of Visual Studio and not a separate add-in.
Still there is a small place to improvement in ‘Metrics’ and ‘Matrix’ views, which, in my opinion, stand out from the rest of the design (maybe it’s because of the colors and the textures?).
I’ve evaluated Nitrous.IO service for a few weeks now. In a nutshell it allows you to create virtual, development, environment, to which you can connect remotely (using the terminal, but also the web page, chrome app or even Mac app). By default Nitrous.IO comes with preconfigured boxes with Ruby/Rails, Node.js, Python/Django and Go.
I’ve started using Nitrous, because I wanted to have an easy and fast access to programming languages without installing them on my Windows machine.
Lately I try to get my head around Clojure language (I’ve learned functional programming during my studies, but it was a long time ago, so I have to discover it again). Because of that I wanted to install Clojure on the Nitrous.IO platform. It isn’t hard, but requires few steps to do. Below I will show you, how you can do it (this tutorial is inspired by ‘Installing Erlang’ guide).
Create a new development box (I’ve used the one with the Go language, but it doesn’t matter) or use the existing one.
Connect to the box – you can even use the web page – start terminal then.
The easiest way to install Clojure on any system is to use Leiningen tool. First lets make a folder where we will store installation script:
then we should get the script:
Once the script is downloaded, we need to modify ~/.bashrc file to add the .tools directory to our $PATH – we can do it with the vim:
Last Friday (20th of September 2013) I was at the DevDay conference in Krakow, Poland. This was a free event, but – in my humble opinion – it could easily compete with the paid ones and it would probably won.
First of all, the conference organizers invited well known and good speakers. Second there was superior service (lots of good food and drinks) and a crew willing to help (cheers for the debugging team!). Ending on the enthusiastic participants.
The conference started at 8am and took whole day. Expect the first and the last talk, two sessions were taking place simultaneously.
I’ve attended to those:
“Back to basics: the mess we’ve made of our fundamental data types” by Jon Skeet
A funny presentation about how even simple things in programming (like float, string, date and time types) can be complex when you use them without understanding. Additional benefit: you could see how Jon spoke with “Tony the pony” ;)
One of the creators of the Nancy framework talked about how simple and clever design “tricks” can encourage developers to use API their created. This talk gave me few ideas and I will definitely use them in my code.
“Building Startups and Minimum Viable Products” by Ben Hall
If you think about a startup, then this talk is for you. Simplifying the essence, you should focus on creating product fast and evaluating it in real world – waiting one year (or even more) with the release isn’t a good idea. I’ve listened this talk with the enjoyment.
I’m Lucene user at work and I’ve also learned about searching during my studies, the first part of the talk was not so interesting for me, but the second part about Elastic Search makes that I’m very happy that I attended to this session. Itamar is one of the Apache Lucene contributor and a good speaker, so I recommend watching this talk.
An overview about architecture of a site, that every developer probably know (and if not, then he should!). You could learn some interesting facts about the team and the way they create this great website.
“The software journeyman’s guide to being homeless and jobless.” by Rob Ashton
An inspiring, funny and probably too short talk about Rob’s one year journey during which he met people, coded and drank ;) I have to say that Rob has lot’s of charisma and is a very good speaker, so you listen him with the real pleasure. Be aware: if you’re Belgian then this talk probably isn’t for you ;)
I’m very happy that I was invited for this conference and I hope I will be there in the next year. One more time thank you guys for creating such a great event!
As I wrote previously I’m a big fan of tools and programs that helps me in my day-to-day work. I also like to test new programs, which is probably the reason that Patrick Smacchia contacted me with a proposition to evaluate his program: NDepend.
In simple words NDepend is a tool that helps improve .Net code quality, by measuring and presenting information about code metrics. It supports C# and Visual Basic languages and integrates nicely with Visual Studio (from 2008 to 2012), providing an easy usage for users.
The list of features that NDepend provides is quite big. From my perspective the most interesting parts are:
Queries and Rules Explorer/Editor
in addition there are also modules for:
In this blog post I will focus only on the main functionality.
In our life we can describe objects by simply telling about their properties (like mass, dimension, speed and so on). Using those properties we can compare objects and evaluate which of them is better (for example: which car is faster). In science and engineering we use predefined system of measurement to define item attributes, where every attribute is expressed in its own unit of measure (like kilogram, meter…).
The same approach is introduced in computer science – for the last 30 years, or even more, researchers introduce many metrics that can describe software and code. Those metrics can tell us:
how hard is to introduce changes
how large and complex the code is
number of lines of code
how good the code is documented
lines of comment
… naming only few from the big list.
NDepend offers 82 most popular code metrics that can be calculated and shown.
Because of hierarchical nature of code elements (fields and methods are in type, type is in namespace, which in in assembly) the metrics are shown using treemapping technique. Depending of selected scope (level) code element is represented by rectangle, which size is determined by the code metric. The rectangle can contain other, smaller rectangles (i.e. namespace has methods). This allows to easily spot problems and patterns. For example if we select a ‘method’ as our scope and ‘Lines of code’ as a metric, the big rectangles will indicate the methods with many lines of code (usually this isn’t good and those methods should be split to smaller ones). The metrics view is one of the most unique and helpful parts of NDepend.
I should mention that some (not many) metrics can’t be calculated and shown for code written in Visual Basic, so if you use VB please be warned.
Queries and Rules Explorer
In essence NDepend provides mechanism for querying your code base for various code metrics and problems that occurs in it. To achieve it, it defines CQLinq (Code Query over LINQ) language, that should be familiar for every .Net developer. For example to find all methods that have more then 30 lines of code we could write such a query:
By default NDepend comes with big number of predefine queries which cover such topics as:
Object oriented design
Those queries help spot the places in code that should be improved: methods split into smaller ones, types renamed, complexity reduced and so on. Working with NDepend creates a workflow, where you look for the problem, fix it and then check again if the metrics are improved. After some time your code should be cleaner and easier to maintain.
The nice part about those queries is that you can modify them and even write your own. This gives you full flexibility in adjustment
the tool to your needs.
When the application comes bigger and bigger it is harder to see the big picture of it. We lost idea about dependences in it. The easiest way to see them is to paint a graph, that will reveal all the dependencies. Here comes NDepend, it can create such a graph for us. The graph can have many levels, that shows dependences between assemblies, namespaces, types or even members (methods and fields).
When we work with NDepend, in Visual Studio, we can use it to get various information about the code elements (types, fields, methods, namespaces or assemblies) in the solution. We can query about direct and indirect callers/callees, inheritors, implementers, type usage and so on. All such queries can be shown in a graph, which is nice and helpful addition.
There is only one problem with the graph representation, it becomes blurry, when there is too much objects in it. I had such problem when I used NDepend with large and quite legacy project – the graph was so big that I wasn’t able to read it. I even ask Patrick what should I do, to be able to work with the graph in this project. He pointed me that I should use dependency matrix instead.
As you probably know a graph can be represented as adjacency matrix. This idea was used by NDepend to present a solution dependency graph as a matrix. The main benefit of such representation is that it is more compact and clear to read. This is especially important when you have many assemblies in your solution – in such case graph is too big to be easily read.
At first I didn’t feel comfortable with dependency matrix and it took me a while to be able to read it correctly. The context-sensitive help speeds the process of learning and after few days the matrix was completely natural for me.
There is also one, big, advantage of dependency matrix over the graph. The matrix allows you to spot the structural patterns, which are nice described in the documentation – that I highly recommend you to read.
Visual Studio integration
By default NDepend comes as a standalone application called Visual NDepend, in addition you can integrate it with Visual Studio. After installing plug-in, you see new menu in the main bar, new context menu in Solution Explorer and few other items here and there. From the menu you have access to all features of NDepend, you can start:
Queries and Rule Explorer/Editor
Dependency Matrix and Graph
Coverage by Tests
and few others.
To be able to use NDepend in Visual Studio we need to create new project file and add to it all assemblies, that we want to analyze. The project file can be added to the solution file, but this isn’t required. After the analyze is finished the NDepend is ready to go. It is worth mentioning that an HTML report, that summarize all information about your code, is generated after the analyze ends.
The integration is nice and gives impression of well organized. For sure this is very strong point of this tool.
NDepend is very interesting product. It offers wide range of features focused on improving the quality of the code you and your team write.
There is also another, very useful, usage of NDepend that I would like to mention. Sometimes in my work I get a source code from completely unknown project and I need to estimate how much work is to introduce changes to it. In such case I start NDepend, run queries and look at the metrics – if those aren’t bad I can assume that changing this code won’t be so hard. Of course this isn’t always true, but if you need to do the time estimation, everything can be helpful.
Note: I’ve used source code from Nancy project in the presented screenshots
The thing, I’ve complained about in my review of the Tesoro Durandal G1N keyboard was the noise. It was especially disturbing late night, when I was still working on my PC and my wife wanted to sleep ;). To solve this problem I’ve decided to reduce the noise of my keyboard by applying sound dampeners – a special soft rubber O-rings that are installed on every keycap stem.
After some searching I’ve found that good quality O-rings can be bought from the WASD Keyboards company. This is an American store, but the shipping cost, even for European clients, is quite low – sending it by ‘USPS First-Class International’ (normal envelope) costs around $7 and it takes about 10 days to ship.
As for today the shop offers two types of O-rings:
– 40A-L (0.2mm Reduction) Red
– 40A-R (0.4mm Reduction) Blue
I’ve bought the 40A-L red ones, because they reduce the noise of the keyboard with only minimal impact on the writing experience. Right now I’ve been using them for more than a month and I’m really happy with the effect. When I hit the key the sound isn’t so “plastic” as before and it’s much more deaden. Still I can easily feel the moment when the key switch has been activated.
Unfortunately I wasn’t able to test the blue one (40A-R – 0.4mm reduction), so I can’t write about the differences between them.
O-rings installation is a bit painful, because you have to remove every keycap, put the O-ring into the stem and then put it back into keyboard. To see how to do it properly I recommend you to watch this short movie created by WASD company. It took me about one hour to install them on all stems. To pull out the keycap I’ve used two thin wires, that I put on the opposite sides of the keycap and then pull them up. After 10 keys you can do it without thinking ;)
If you like your mechanical keyboard, but you think it’s too loud, you should use those O-rings and probably you will be happy with the result – at least I’m.
A few weeks ago I’ve decided to change my keyboard. For the last two or three years I’ve been using Microsoft Wired Keyboard 600, which is nice, low profile keyboard. During my research for the new keyboard I’ve found many articles about mechanical keyboards and how good they are in the comparison to “traditional rubber domes” ones. This convinced me to buy one. Still there was a question about exact model. So again I’ve spent some time reading materials about key switches and their purpose (I can recommend this thread – it contains lots of useful information). The final decision was to buy keyboard with Cherry MX Brown switches.
Unfortunately in Europe and especially in Poland there is problem with getting mechanical keyboard, not saying about the possibility of choosing the type of keys switches. You can buy some keyboards with Cherry MX Redswitches, because those are used in the “gaming keyboards” and therefore more popular. Of course I could import a keyboard from the USA, but then the price would be too big for me – the shipping cost is pretty big, plus I would need to pay duty and value added tax. All of this makes that I bought Tesoro (in the United States it’s Max Keyboard) Durandal G1N mechanical keyboard, which has just shown on the European and Polish market.
The keyboard has simple, US international layout. There is one additional key – Fn which allows using multimedia functions keys that are mapped to keys from F1 to F6 (mute, change volume, play, pause, rewind). The keyboard looks almost like the “normal” one, except the right, upper corner, which is a bit bigger and has lighting sign of Tesoro company. You can also see the name of the brand on the bottom of the keyboard, just beneath the space bar. The maximal dimension of the keyboard is 46 cm (18.1 in) length and 17 cm (6.7 in) width. The front case imitate brushed metal, which looks good and prevents leaving fingerprints. On the back of the case there are rubberized elements that prevents slipping keyboard on the table. The keyboard itself is heavy and made from good quality of plastic. It has braided cable, which is also a nice addition. In summary I can say, that I’m pleased with the quality of my new keyboard.
This is my first mechanical keyboard and I have to admit that writing on it is a real pleasure. You can easily feel the moment when the key switch has been activated (for the MX Brown switch it’s in the half way through the key press) and you can release it. This allows you to use less force to write something on the keyboard. The result is that you can write faster and your hands are less exhausted. Unfortunately I haven’t used any other mechanical keyboard so I can’t compare this one with others – maybe in the future I will be able to do this ;)
I’ve decided to buy keyboard with the brown switches because they are advertiser as quieter than the blue ones (for the blue switches you can hear the ‘click’ sound when you press the key), but still good for typing. Despite of it I have to admit that this keyboard is quite loud. For me this isn’t a problem, but for my wife it is ;) She complains about the noise, so I have to close the door to my room when I’m typing a lot of text or playing any game. To solve this problem I’m going to buy the rubber o-ring switch dampeners to reduce the noise. When I do this I will try to write something about it on my blog.
If you are looking for good and not expensive keyboard for writing and occasionally playing games I can recommend you the Tesoro Durandal G1N keyboard. I’ve been using it for more than a month and I’m very happy with it. My wife apparently not …
I’ve decided to move, my not very often updated blog, to the new platform. I’ve made a choice to use Octopress blog engine. Octopress uses Jekyll, a static site generator in ruby, that basically takes bunch of templates files and produce a set of html pages. I could use Jekyll, but Octopress extends it with additional files, themes and plugins, so you can create your blog very fast with small effort.
Till now my blog was powered by Wordpress engine, so why I wanted to change it? The main reason is that Wordpress is quite complex engine (with many plugins and settings) that I’ve never fully understood. Changing something in it was more like hacking for me than full understandable programming. Additionally Wordpress uses mysql database to store posts which adds complexity to backup strategy – I needed to store all Wordpress files, plus database with posts. This is why I decided to change it.
What I like in Octopress:
customization – there are many plugins you can use (twitter and github integration for example) and the design of the blog can also be easily changed by tweaking Sass (*.scss) files.
beautiful, built-in code highlighter with support for many languages – it uses Solarizedcolor scheme (light or dark) which looks great;
possibility of writing post as a simple text file, using markdown – you can create/edit them in your favorite text editor (Sublime Text is my choice);
easy backup – I store all files in a git repository;
a chance to work with ruby language – currently I’m trying to extend my knowledge about it, which gives me a lot of fun.
Finally I would like to say few words about my transition from Wordpress to Octopress. The migration process I’ve started from exporting all my posts from Wordpress to markdown files – I did it by using WordPress to Jekyll Exporter plugin. After this I’ve tweaked generated posts, installed default theme (I’ve changed it a little bit – my inspiration was darkstripestheme by Alessandro Melandri) and set base settings in _config.yml file. The final results you can see here, I hope you like it.
Recently I’ve been working on the WPF application that extensively uses Caliburn.Micro framework for MVVM pattern. MVVM usually force you to write many properties in the ViewModel. Those properties should typically notify View about their values changes – to do that every ViewModel has to implement INotifyPropertyChanged interface and in the setters of the properties we need to rise NotifyPropertyChanged event, for example like that:
In Caliburn.Mirco your ViewModel can inherit from PropertyChangedBase class (or other classes that internally inherit from PropertyChangedBase class – like Screen, Conductor and so on) and then in properties you can use NotifyOfPropertyChange method:
Because in my project I have to write many properites with NotifyOfPropertyChange method in their setters, I’ve decided that I write Resharper Live Template for this purpose. To do this you should go to the ‘Resharper‘ menu in Visual Studio, then ‘Live Templates‘ and there you should select ‘New Template‘ button. After this you will get the window like this one:
In the left part you can write the code of the snipped. In my case it was:
The most tricky part of this template is setting properties of the template in the right pane of the window. This should be done in this way:
In the Editable Occurrence column we specify the order of defining elements of the template – first the type and the name of the field that will be used for this property.
In the Value column we can set how the value of the template field will be calculated – the value of $PROPERTYNAME$ property is set as name of the private field with first character as upper case.
The last thing to do is to set a shortcut for this snippet (in this case: propnot) and the description. And this is it, after saving you have a new live template that can be use in code editor by simply writing “propnot“. If you do that you will get something like this in Visual Studio:
I decided that in the next few weeks I will write series of short blog posts with code snippets that I use during my everyday work.
Very often I have to check if a string contains specific sequence of characters, to do it I write something like this:
and after few seconds I realize that it won’t work correctly because Contains method is case-sensitive. To solve this problem I’ve written an extension method that does case-insensitive checking. Here is my method:
Sometimes I write a class that has many similar methods. All those methods start from initialization block, then there is a processing part and at the end there is finalizing segment. In other words those methods are only different in processing code – rest is the same.
When I see that kind of class I immediately start thinking about using template method patter. You can read about this pattern here . The general idea is that you have an abstract class that creates template method for concrete classes that derive from it and add its own functionality to this method.
I will show it by examples.
First let’s assume we have to write a class that will process a text file. The file contains only one line with an integer number. Our task is to write a methods that will increment (n ), decrement (n–) or multiple by two (n=*2) this number.
As we can see our class has three methods: Increment(), Decrement() and MultipleByTwo() – the only difference between them is in line where we change integer variable, rest is the same. There is lots of redundant code that should be removed, to do it we can introduce a base, abstract class.
In IntegerFileOperationBase class we have a method ChangeNumber() which is a template method. This method opens a text file, reads its content, parses it as an integer and then invokes DoOperation method to change the integer variable. After all the new value is saved to the file. By various implementation of DoOperation method we can change the way that ChangeNumber method works. Here’s how we can do it:
The result of our refactoring is a code without redundancy. I don’t like this solution, because I feel it’s too complicated for such an easy task (we have four classes instead of one). We can solve this problem by reimplementing it with delegate mechanism. Instead of an abstract DoOperation() method we can use a delegate that will be passed to the ChangeNumber() method as a parameter (I use generic Func<int, int> delegate as a type – read more. To implement Increment(), Decrement() and MultipleByTwo() methods we use ChangeNumber method with lambda expression as a parameter: