Evaluating NDepend on current codebase Part 2

In Part 1 we saw a first approach to NDepend starting off with analyzing a project of 2 assemblies and focusing on the smaller assembly. In this part we will focus on the main executable and the gems NDepend discovered in it TL; DR Memory leak detected...


Photo by Daan Mooij on Unsplash

Enter 3 years old WPF project - Main executable

Going back to the dashboard I see the "usual" long types or methods errors, some immutability warnings, which I would have set as errors and 400 violations of "Avoid namespaces mutually dependent" some with debt time of 4 days. "Oh come on.. what 4 days. How hard can it be..."

Drilling down into the code (a wpf application) I realize that there is a single class that is injected in the constructor of every view model and I hardly see any services in the system save for calls to the DAL assembly.

Without drilling down into the class I changed it's namespace and made the necessary, albeit sisyphic, changes to all the classes. While at it I noticed that some view models where creating instances of view models for dialog boxes, panes and popups and injected the Container class to them as well. 

Once the change was completed, I run NDepend on the result and I had 800 violations of the namespace rule plus some API breaks. Oh my...

A lesson learned: Always drill down before making such change

The injected class, let's call it Container, has 2 properties pertaining to 2 classes, Let's call them Singletons and Factories. 

A first look reveals nothing suspicious; Singletons holds services and Factories creates view models when needed. Sounds reasonable right? Wrong... To quote myself:
there is a single class that is injected in the constructor of every view model 
In fact, every time the Factories class creates a class it injects in its constructor... you guessed it, the Container class. Moreover, elements in the Singleton class created view models via the Factories and these view models in turn require use of these same (or other) singletons. In fact, some view models also serve as service classes and there is more than one way to create a view model; By factory or by directly initializing via constructor. Here is a diagram of the dependencies between these classes.

There really aren't enough lines to describe this

When there is a "God" obejct in any system it almost always ends up looking like this. Sometime weird performance issues are detected in the system and people tend to use GC.Collect to deal with them and blame some 3rd party black box or may some obscure Microsoft bug, not that this isn't known to happen. However when some GC.Collect calls seem to solve the problem that means that there is a memory leak and a misbehaving object ruining loose.

Going forward with the D in S.O.L.I.D

A lot of time will be spent fixing this one obviously, mainly by introducing a proper dependency injector and IOC container. And in every step of the way this code as well as any new code in the development team will have to be analyzed by NDepend to catch problems on time. The build engine integration of NDepend should be of great value to catch code smells as they are committed. 

Apart from the features portrayed in these posts NDepend is feature rich, including code coverage files (which I have yet to test), trends, metrics and graphs to show you your project analysis from any view and angle possible. I am hooked. How do you perform your static code analysis? Leave a note in the comments below.

Comments

  1. In those moments when it seems that the problem is being solved very quickly, you should not rejoice as this indicates a data leak and even bigger problems.

    ReplyDelete
    Replies
    1. I most definitely agree. It was too easy to be true. When I actually fathomed the graph of dependencies I had a face-palm moment.

      Delete
  2. I also agree with the previous commentary. What's more, our evaluation is trustworthy and reliable, so we can easily perform your static code analysis without any worries.

    ReplyDelete
  3. The Essentials Hoodie line is built on the idea of versatility. Neutral colors, clean cuts, and iconic branding allow you to mix and match effortlessly with any outfit, making it the go-to choice for every occasion.

    ReplyDelete
  4. Our journey began with a simple mission: to make sourcing essential products easier, faster, and more cost-effective. Over time, Davril Supply has grown into a reliable partner for companies across multiple sectors, offering tailored solutions that meet both commercial and personal needs.

    ReplyDelete
  5. Sp5der Hoodie is a leading streetwear-inspired brand that combines modern fashion with comfort. Known for its distinctive designs, bold graphics, and premium materials, the brand has quickly become a favorite among fashion enthusiasts and hoodie lovers worldwide.

    ReplyDelete
  6. Welcome to our platform dedicated to the iconic Comme des Garçons Samba, a collaboration that merges the timeless style of Adidas with the avant-garde creativity of Comme des Garçons. We provide detailed insights, authentic product information, and resources for enthusiasts who value fashion, culture, and originality.

    ReplyDelete
  7. Sisters & Seekers is a contemporary fashion brand that has quickly become a favorite among style-conscious individuals looking for comfortable yet statement-making clothing. Our collection of hoodies is at the heart of our brand, blending minimalistic aesthetics with high-quality fabrics designed for everyday wear.

    ReplyDelete
  8. Welcome to Akimbo NY Hoodie, a brand inspired by the vibrant streets and bold culture of New York City. Our mission is to bring you premium streetwear that blends comfort, style, and originality. Every hoodie we design reflects the fast-paced energy, creativity, and individuality that NYC is known for.

    ReplyDelete
  9. At Alchemai, we believe in transformation – much like the alchemical process that inspires our name. The Orchid hoodie represents elegance, resilience, and modern style, blending timeless aesthetics with contemporary streetwear culture.

    ReplyDelete
  10. At [Your Site Name], we are passionate about bringing the most iconic Pokémon cards and collector sets to fans worldwide. Our highlight product, the Charizard EX Special Collection, is designed for trainers and collectors who value both power and prestige in their Pokémon journey.

    ReplyDelete
  11. Our brand focuses on quality craftsmanship, making each Trapstar jacket a statement piece. Whether you’re into bold graphics, minimalist designs, or limited editions, our kurtkas are made to match your lifestyle.

    ReplyDelete
  12. Mr. Winstons is a trusted name in providing quality products and services designed to make everyday life better. With a focus on customer satisfaction, we combine innovation, reliability, and professionalism to ensure our clients receive nothing but the best. Our mission is simple—deliver excellence at every step.

    ReplyDelete
  13. Bluza Stone Island is your ultimate destination for premium Stone Island apparel. We specialize in high-quality hoodies, jackets, and casual wear that combine comfort, style, and durability. Our mission is to bring authentic, fashion-forward pieces to enthusiasts who value both trend and functionality.

    ReplyDelete
  14. Pink Palm is committed to sustainable practices, from ethically sourced materials to eco-friendly packaging. We strive to make a positive impact on both people and the planet.

    ReplyDelete
  15. Essentials Clothing is a modern fashion brand committed to creating high-quality apparel that blends style, comfort, and affordability. Our collections are designed for individuals who want to express themselves through versatile and timeless clothing pieces.

    ReplyDelete
  16. Denim Tears is a streetwear brand that celebrates culture, creativity, and individuality. Our signature hoodies blend modern fashion trends with timeless style, making them a must-have for anyone looking to express themselves through clothing. Every piece is crafted with attention to detail, ensuring comfort and quality for daily wear.

    ReplyDelete
  17. At 7 Heavens, we combine quality and innovation to bring our customers premium solutions that truly stand out. Explore our range of products and services designed to enhance comfort, style, and convenience.

    ReplyDelete
  18. Lattafa Perfumes is a premium fragrance brand renowned for crafting luxurious scents that captivate the senses. Combining tradition with modern perfumery techniques, our perfumes are designed to leave a lasting impression, whether you’re at work, a social event, or a special occasion.

    ReplyDelete
  19. The Orange Chrome Heart Hoodie is more than just casual wear—it’s a statement.

    ReplyDelete
  20. The exclusivity of Matty Boy drops has fueled a thriving resale market. Limited runs often sell out within hours, and pieces can fetch double or triple their retail price on secondary platforms.

    ReplyDelete
  21. Kroen joggers are built for comfort, often made from a cotton blend that feels soft against the skin while offering breathability for long hours of wear.

    ReplyDelete
  22. HMDD Clothing frequently releases limited-edition drops, which adds a sense of exclusivity. Fans often anticipate these launches, creating buzz and ensuring collections sell out quickly.

    ReplyDelete
  23. Sp5der sweatsuits are generally made from premium cotton blends with brushed fleece interiors. The fabric is heavy, giving the pieces structure while maintaining softness. Kangaroo pockets, ribbed cuffs, and adjustable drawstrings add practicality.

    ReplyDelete

Post a Comment

Keep it clean, professional and constructive. Everything else including ethnic or religious references will be removed.

Popular posts from this blog

NUnit Console Runner and NLog extension logging for your tests

Tests code coverage in Visual Studio Code with C# and .Net Core

Visual Studio Code setup I use for C# development