Thursday, 12 May 2016

Analysing .NET code dependencies–Visual Studio Code Maps

This is the second in a series of posts on reviewing tools to help analyse code dependencies in .NET

Code Maps is a feature that was first included in Visual Studio 2012 Ultimate. It remains an Enterprise-only feature in 2015, though Professional and Community editions can view previously created diagrams.

Code Maps operate from the cross-project solution level right down to the method level.

Dependencies

To generate a map of project dependencies, go to the Architecture menu, and choose Generate Code Map for Solution.

A new window opens and gradually items appear on the diagram. Usually this will trigger a build of the solution, and then the analysis process will run, eventually displaying the dependencies between the projects.

Code Maps - Solution

If your solution uses solution folders to group similar projects, then you’ll see that represented in the diagram (the OLW solution doesn’t currently do this).

You can then expand this out by selecting all the nodes (Ctrl-A) and choosing Group, Expand from the context menu.

Code Maps - Solution expanded with externals highlighted

You can see two things – the OpenLiveWriter.PostEditor project seems to be the most significant project, and also there’s an ‘Externals’ block with all external assembly references. To just focus on strictly code from the solution, you can select this group and press Delete. This removes it from the diagram.

Editing a Code Map diagram doesn’t mess with your source code, as the diagrams are a bit like a snapshot of your code at the time they were created. In some ways this is a limitation, but one positive aspect is that you can use Code Map diagrams to model or prototype changes to the class hierarchy and dependencies without having to commit those changes in code.

Let’s focus in on the PostEditor project. If we select that node, we can choose New Graph from the context menu. A separate diagram is now displayed with just the contents of the previously selected node. You can use the Filters tool window to select which elements you want to display. I de-selected Assembly so that I can now focus on the namespaces.

Code Maps - HtmlEditor assembly classes

Let’s keep going further in. Select the OpenLiveWriter.PostEditor namespace, and open this in a new graph again. To drill down to the class level, select all nodes again (Ctrl-A) and choose Group, Expand again.

Code Maps - OpenLiveWriter.HtmlEditor namespace classes

Let’s click on that top node – BlogPostEditingManager. Repeating the same process again, and filtering down to just methods, we get the following:

Code Maps - BlogPostEditingManager Methods

We now have a call graph of the methods inside the class. I also changed the layout for this graph to be ‘left to right’. The two blue nodes represent classes defined inside this class.

Usually, you’d expect to see public methods on the left, and non-public methods going to the right. Unfortunately there’s no way distinguish between them apart from hovering over a node and reading the tooltip that appears, or by selecting a node and reviewing the details in the Properties window.

Debugging

You can also display Code Maps while debugging. If you have stopped at a breakpoint, you can right-click and select Show Call Stack on Code Map.

Code Maps - Call stack

Basically just a different way see the same info that gets displayed in the Call Stack debugging window, and unless I’ve missed something obvious, I think I’ll stick with the latter.

Summary

That’s a quick overview of some of the things that Code Maps can show you. They are entirely visual, so unlike NDepend, there’s no way to do any custom querying out of the box. On the other hand, the fact that the diagrams use DGML (directed graph markup language), it would be possible to write code that queried the file directly.

Friday, 29 April 2016

Analysing .NET code dependencies–NDepend

This is the first in a series of posts on reviewing tools for analysing .NET code dependencies.

I last wrote about NDepend briefly four years ago, and with a bit more detail way back in 2010. Some of the features added since then include:

  • Support for Visual Studio 2013 and 2015
    • Now a proper VSIX extension (v6)
    • NDepend project can be included in VS solution.
  • New Dashboard Panel – state of your code base at a glance
  • Focus on recent rules violations – only show rule violations on added/modified code
  • UI enhancements – improved menus
  • Better path management – UNC paths and support for environment and MSBuild variables.
  • Windows Store and Windows Phone support – honours the TypeForwardedToAttribute
  • Trend monitoring – monitor trend metrics and view via trend charts
  • Share rules between projects
  • Rules
    • Rule descriptions and fix suggestions added
    • Reduction in false positive detection
  • TFS integration
    • 2013 (2015 is coming)
  • SonarQube integration
  • TeamCity integration
  • Report enhancements – report includes trend metric charts
  • More console options – additional parameters to support file and directory variables.
  • Coloured Code Metric view – treemap elements can be coloured to indicate second metric
  • Code coverage shown with red/green colouring
  • Improved handling of compiler-generated code
  • Async support
  • High DPI support
  • Visual Studio theme support

So let’s take NDepend v6 for a spin and see what it can do.

I’m going to use the Open Live Writer code base for these reviews. The writer.sln contains 28 projects and around 3,000 types.

The OLW solution is special in that most projects point to the same single output folder. As a result you might have to tell NDepend to look in this output directory rather than just relying on it to examine the solution’s projects. Once the assemblies are selected, the analysis begins.

Analysis might take a minute or two, but when it finishes you are prompted to view the results. I chose the Dashboard view:

NDepend Dashboard view

To dig into the dependencies, let’s look at some useful diagrams. First up, the Dependency Graph. Go to NDepend, Graph, View Application Assemblies Only.

Assembly dependency graph

By default, the size of each ‘node’ indicates the relative number of IL instructions in that assembly. From the graph above, it’s obvious that OpenLiveWriter.PostEditor is the largest assembly. That sounds reasonable given that OLW is all about editing posts.

Switching to the Matrix, here again is the ‘Application Assemblies Only’ view:

Matrix View of Dependencies

The intersections where there are 0 methods used from the assembly reference bear further investigation. Sometimes there might be a valid reason, but quite often this represents an unnecessary assembly reference that can be removed.

The query language is very powerful. I’d like to find assemblies that are only referenced by one other assembly. Matching assemblies could be candidates for merging with the parent assembly if there’s no good reason for keeping them separate.

I came up with this custom query:


from m in Assemblies.ExceptThirdParty()
where m.AssembliesUsingMe.Count() == 1
select new { Parent = m.AssembliesUsingMe.First() , Child = m}

Which returned the following results:

  • OpenLiveWriter.FileDestinations
  • OpenLiveWriter.HtmlEditor
  • OpenLiveWriter.InternalWriterPlugin

Are all referenced only by OpenLiveWriter.PostEditor. That’s useful to know.

Jumping back to the dashboard, let’s drill in to see some of those “Critical Rules Violated”. Clicking on this heading in the dashboard opens the Queries and Rules Explorer, with the “14 Critical Rules Violated” filter selected.

Selecting the top item in the list opens the Queries and Rules Edit window, with the top half showing the actual query that was used to search for the violations and the bottom half showing a tree of matches for this rule (in this case it’s the offending methods). So that Init() method takes 15 parameters. Maybe that’s ok, maybe not.

NDepend Queries and Rules Edit

I love digging around the results of these kinds of rule queries. Particularly the ones around potential dead code, where you end up identifying and removing code that isn’t being used anymore.

NDepend has really progressed over the years. It’s particularly nice to see the improved integration with Visual Studio. Ideally every developer would have NDepend in their toolbox to use themselves, but a first step is probably including it as part of your build pipeline. That way, at least everyone can view the reports it generates as part of the build results.

Analysing .NET code dependencies–Overview

How can you tell if modules/components in your application are loosely-coupled between each other, and tightly cohesive internally? You could read the code line-by-line, but that becomes difficult once the codebase becomes large.

It can be very valuable to be able to visualise the the dependencies between the various components that make up your application – both at the class and module/assembly level. These tools analyse code, either by parsing the source code, or by analysing the compiled assemblies to produce various summaries and reports about the state of the code.

I’m planning to spend a bit of time in future blog posts reviewing a number of these tools that can help with this analysis, including:

I’m also interested to hear what you use. Let me know in the comments of your experiences with these or other tools I haven’t mentioned.

Monday, 11 April 2016

My new Dell XPS 15 laptop

My birthday has come early this year. I've finally bought a new laptop! It wasn’t the cheapest either, so I think that will cover a couple more birthdays in the future too Smile

I'd been evaluating a number of different manufacturers and models, and eventually went with a Dell XPS 15 (9550). I'd had a pretty good run with my old XPS 1645 and that counted in the XPS 15's favour.

I bought the 1645 in 2010, so I was expecting to buy something that represented 6 years of technology improvements. So far I think the 15 delivers that.

  • 16GB DDR4
  • 512GB SSD (PCIe)
  • 4K Ultra HD (3840 x 2160) touch display

Modifications

Out of the box, the top row of the keyboard defaults to the feature keys. I make use of the Function keys (F1, F2, etc) much more than I'd use the feature keys (Mute, Volume Up/Down, etc) so I went into the UEFI firmware settings and changed that to default to function keys.

Here’s a comparison of the keyboards of the 1645 and 15 (the shiny strip above the main keyboard on the 1645 has the feature keys). Obviously fashions change too – from glossy/shiny to matte.

XPS 1645 KeyboardXPS 15 keyboard

I HATE touchpads that simulate a mouse click with a single tap. Maybe it's my hands but I find I end up 'clicking' a lot more than I intended. So it's another thing I try to disable if possible. On the 1645 this was done through the Synaptics touchpad driver, but that isn't present on the 15. Instead it turns out that's a setting provided by Windows itself.

Windows 10 Touchpad settings

Old and new comparison

XPS 15 and 1645 closedXPS 15 and 1645 open

Here’s the 15 sitting on top of the 1645, to show it’s slightly smaller.

View from above of XPS 15 sitting on top of 1645

Side views show the 15 is a fair bit slimmer. The 1645 comes with VGA, HDMI and DisplayPort ports – the 15 just has a single HDMI, but you can get an external adapter with a second HDMI and VGA (as well as extra USB and Ethernet). No DVD drive in the 15 either!

XPS 15 and 1645 right side comparisonXPS 15 and 1645 - left side comparison

The rubber feet of the 1645 fell off a while ago – both the ones on the base of the laptop and the ones fixed to the battery bar. The 15 has two rubber strips. Time will tell if they last longer.

XPS 1645 underneath - worn feetXPS 15 - underneath showing rubber feet strips

My 1645 weighs 3.065kg. I’m pleased to see the 15 weighs only 2.040kg. (For those days when I need to carry it around, my back is also pleased!)

XPS 1645 Weight - 3.065KGXPS 15 2.040kg

It’s not easy to show the difference in displays, but this gives you a bit of an idea of the 4K display of the 15 next to the standard 1080 of the 1645. It doesn’t show up here, but the 1645 screen also got quite scratched over the years from rubbing against the keyboard. Probably made worse from the extra rubber pads falling off that should have prevented this. I’m looking into getting a protective cloth for the new laptop to try and reduce the chance of that happening again.
Comparing the displays of 15 and 1645

And check out the disk performance – almost 10x faster with the PCIe SSD – nice!

HDTune Benchmark Crucial CT512MX1 SSD - Average 111 MB/secHDTune Benchmark NVMe THNSN5512GPU7_NV - Average 897 MB/sec

Finally, I’d forgotten what it was like to have a battery that holds a decent amount of charge (the 1645 might say it has 1:45 left, but that’s pretty optimistic). I can sit on the sofa with the XPS 15 and it lasts the whole evening. Wow Smile

dell xps 1645 batteryDell XPS 15 Battery

Monday, 28 March 2016

Installing future SQL Server updates with confidence

Great to read that Microsoft are now making the “cumulative update” packages ‘recommended’ installs, and the updates themselves will be easier to obtain - no longer requiring a email address to download directly, and also being listed in Windows Update Catalog (and maybe in the future as an optional update on Microsoft Update).

As a developer, I’ve often installed the latest CU (cumulative update) just because I like to be current on my own PC – but I’ve traditionally been more conservative with production SQL Servers that I’ve had to look after over the years. In the latter case I’ve installed the latest service pack, but only added a CU if it seemed likely to address any issue we might be having at the time.

With this change, now pushing out the latest CU can be done with more confidence and probably should be considered part of maintaining your SQL Server infrastructure. Quoting from the above article:

You should plan to install a CU with the same level of confidence you plan to install SPs (Service Packs) as they are released. This is because CU’s are certified and tested to the level of SP’s.

A few years back I remember thinking that the SQL Server team had really set the standard for releasing regular updates for their products (especially compared to the lack of updates at the time to fix problems with older versions of Visual Studio 2005/2008). Since then the VS team have upped their game, and now they are pushing new major servicing updates out around every quarter. That doesn’t include out-of-band updates to VS extensions that are done more frequently.

So it’s great to see the SQL Server team stepping up the pace another notch.

Tuesday, 15 March 2016

How I first heard about Lean

A quick shout-out to Flinders Medical Centre’s Redesigning Care. They implemented Lean a few years ago to improve how their hospital functioned. After hearing about what Lean was and what they were doing, I then discovered that Lean had been applied to developing software too.

If you’re interested in learning more about Lean in a healthcare setting, contact them via their webpage, or check out their overview video on YouTube

Friday, 26 February 2016

Laptop comparisons

So after a bit more research, I’ve come up with a shortlist of laptops to consider. Most vendors (with the exception of HP and Microsoft) give you quite a few options to customise during the order process. For my own reference, I’ve also included the specs of my current laptop – the Dell XPS 1645 – to contrast how hardware has progressed over the last 5-6 years.

My mandatory minimum requirements:

  • i7 CPU
  • 8GB memory
  • 512GB SSD
  • Touch screen
  • Lighter than 3Kg

Nice to haves:

  • Xeon CPU
  • 16GB memory
  • PCIe SSD
Laptop feature comparison
Dell XPS 1645 (Circa 2010) Dell XPS 13(9350) Dell XPS 15 (9550) Dell Latitude E7450

HP ZBook Studio 15 E3 Mobile Workstation

ThinkPad X1 Yoga - Core i7

Microsoft Surface Book

CPU Core I7-820QM Processor (1.73GHz) i7-6500U (up to 3.1 GHz) i7-6700HQ Quad Core (up to 3.5 GHz) i7-5600U Processor (Dual Core, 2.6GHz, 15W) Xeon® E3-1505M v5 (2.80 GHz, up to 3.70 GHz), 4 cores)

Intel Core i7-6600U Processor (up to 3.40GHz)

i7-6600U
(2.6 up to 3.4 GHz)

Cache 8MB L3 4M 6M 4M 8 MB

4MB

4 MB

Memory 8GB Dual-channel 1333MHz DDR3 SDRAM (2 x 4GB) 8GB LPDDR3 1866MHz 16GB Dual Channel DDR4 2133Mhz (8GBx2) 8GB (1x8GB) 1600MHz DDR3L 8 GB DDR4-2133 (1 x 8 GB) 16GB LPDDR3 SDRAM 1866MHz 16GB LPDDR3
Storage 500GB 7200RPM SATA Hard Drive 256GB PCIe Solid State Drive 512GB PCIe Solid State Drive 256GB (SATA3) 256 GB HP Z Turbo Drive PCIe SSD

512GB Solid State Drive, PCIe-NVMe

512GB SSD
Video Video Card -ATI Mobility RADEON(R) HD 4670 - 1GB

Intel(R) HD Graphics 520

NVIDIA® GeForce® GTX 960M with 2GB GDDR5

Intel® Integrated HD Graphics 5500

NVIDIA® Quadro® M1000M (2 GB dedicated GDDR5)

Intel HD Graphics 520

Intel HD Graphics 520
+ Nvidia GeForce 940M GPU with 1 GB of memory

Display 15.6 Full High Definition(1080p)
1920x1080
13.3 inch QHD+ (3200 x 1800) InfinityEdge touch 15.6" 4K Ultra HD (3840 x 2160) InfinityEdge touch 14.0 FHD (1920x1080) 15.6" diagonal FHD UWVA IPS anti-glare LED-backlit (1920 x 1080)

14" FHD (1920x1080), IPS, 10-point Multi-Touch

13.5” PixelSense™  3000 x 2000 (267 PPI) 10 point multi-touch
Network Wireless Network Card -Intel(R) WiFi Link 5300 (802.11a/g/n) Half Mini-c DW1820A 2x2 802.11ac 2.4/5GHz + Bluetooth4.1 DW1830 3x3 802.11ac 2.4/5GHz + Bluetooth 4.1 Intel Dual Band Wireless-AC 7265AC 802.11ac/a/b/g/n 2x2 + Bluetooth 4.0 LE Intel® Dual Band Wireless-AC 8260 802.11 a/b/g/n/ac (2x2) Wi-Fi and Bluetooth® 4.0 combo Intel Dual Band Wireless-AC 8260, 2x2, Wi-Fi + Bluetooth 4.1, vPro

802.11ac Wi-Fi wireless networking; IEEE 802.11a/b/g/n compatible
Bluetooth 4.0

Battery 9-cell (85WHr) Lithium Ion 56WHr Integrated Battery 84Whr battery 4-cell 52 Whr Lithium Polymer 4-cell 64 WHr Li-ion prismatic

4 Cell Li-Polymer Battery 52Wh

12 hour
Weight 3.06Kg 1.29kg 2kg 1.56Kg 2Kg 1.27kg+ 1.516 Kg
Dimensions (W x D x H) 380 x 260 x ? 304 x 200 x 15 357 x 235 x 17

337 x 232 x 20

375 x 255 x 18 333 x 229 x 17 232 x 312 x 23
Service 3-Year Premier Service 3Yr ProSupport : Next Business Day Onsite Service 3Yr ProSupport : Next Business Day Onsite Service 3 Yrs Next Business Day Onsite Service 3 years standard parts, labour and on-site limited warranty 3Y On-site NBD upgrade from 1Y Depot/CCI 2-year hardware warranty
Price (as at 25th Feb 2016) $2,100 (as at 2010) $2,879 $3,379 $4,441.80 $5,481 $4,118.51 $4,199

Notes

  • Where choice was offered, maximum CPU and memory selected
  • All prices in Australian dollars, including GST. Enterprise agreements or other arrangements/discounts/specials might give better prices.
  • Enterprise and/or special business programs may offer additional hardware choices/customisations.
  • Where offered, 3 year support was chosen
  • No Office subscription was included
  • Windows 10 Pro 64bit

Thoughts

I think I’ll forget about a Xeon CPU - can’t justify the premium price. Maybe one day!

Most of these devices have built-in batteries, so the option of buying a spare battery (like I did with my 1645) simply doesn’t exist these days.

Looking at that list, I think the models that stand out are the XPS 15, X1 Yoga and Surface Book. I’ve probably been looking most closely at the Yoga, but the XPS deserves some closer attention – especially as the price seems a bit more affordable. The Surface Book looks nice, but for me I think it’s in 3rd place behind the other two.

Let me know of any corrections or suggestions for other models that I should consider and anything I’ve overlooked.

Sunday, 14 February 2016

Book review: Why

As part of their support for user groups, O’Reilly sent me a free copy of “Why: A Guide to Finding and Using Causes ” by Samantha Kleinberg to review.

Kleinberg is an Assistant Professor of Computer Science, so I was interested to see what she had to say about finding “causes”. It probably wouldn’t be the first book I chose if I was browsing, but I’m always interested in learning new things.

What I liked about this book was the use of written examples and illustrations. The first chapter opens with the story of Sally Clark. A tragic miscarriage of justice that resulted in Clark serving 3 years in prison for the murder of her babies. One of the significant pieces of evidence that was used to convict Clark was the suggestion that the probability of two babies dying of SIDS was 1 in 73 million. This is wrong, because the witness (a medical expert) didn’t understand statistics and probability. The expert witness believed Clark was the cause of death the two babies.

The Clark story isn’t the only one told. I’m glad for the generous sprinkling of those examples – without which it would be pretty dry going. It is very helpful to bring things back to something you can relate to.

A warning, this is a pretty in-depth book. I can’t say I found it an easy read, but there’s plenty of detail there.

Before reading this book I guess I assumed that finding the cause for something was a pretty straight forward. Turns out the correct method is “it depends”.

Trying to identify the real cause of an event is not always easy. Kleinberg takes us on a journey to better understand ways (and there are more than one) of finding causes – Beginnings (concepts), Psychology (how do we learn about causes), Correlation (correlation and causation aren’t the same thing), Time, Observation (watching to learn), Computation (automating the process), Experimentation (experiments and research), Explanation (this caused that), Action (making decisions).

The writer comes from the Computer Science field but she writes in a generally accessible (if a little bit academic) way. There are plenty of references (the notes and bibliography take up a not insignificant amount of the book). I noticed a lot of examples were medically-related, so if you work in the medical field, then I think you would get a lot out of it too.

Finally, a suggestion for the title of the sequel – “Just Because” Smile