CleanCode logo
NAVIGATION: first page in sectionprevious pageup one levelnext pagefinal page in section


Principles and Practices

The Zen of Code Reviews
Using a code review tool like the one within TFS is valuable but most people do not use it to their best advantage. This series explains some tips and best practices for doing code reviews.
Zen of Code Reviews: Pre-Review Comments,, March 10, 2015
Zen of Code Reviews: Best Practices,, August 24, 2015
Zen of Code Reviews: The Reviewer's Tale,, November 16, 2015
Zen of Code Reviews: Review As If You Own the Code,, March 7, 2016
Code Smells: Raw Strings and the Subtle Syntax Catastrophe,, January 5, 2017
Some important advice on best practices in regard to that humblest of data types, the simple string.
Fighting Evil in Your Code: Comments on Comments,, June 28, 2017
Wherein I identify the nine types of comments you might use in a program along with the degree of evil associated with each!

Test-Driven Development (TDD)

A TDD Journey (August 1, 2014)
This series is designed for the beginner to get over the rather daunting learning curve of Test-Driven Development, but should also be useful to those who already practice TDD. Excepting part 1 which introduces necessary prerequisites to the reader, the remaining parts take you through building a class from scratch using TDD. The test-and-code building are interleaved with additional concepts that are immediately demonstrated in practice.
Part 1: Introduces the key concepts of TDD
Part 2: Naming tests; mocking framework; dependency injection
Part 3: Test doubles; test frameworks; assertions; ReSharper accelerators
Part 4: Tests as documentation; false positive results; component isolation
Part 5: Tests vs. code; refactor friendliness; test parameterization
Part 6: Mini-factory pattern; don't care terms
Practical Unit Tests (and TDD!) in PowerShell (November 5, 2014)
By the time you're using PowerShell to automate an increasing amount of the system administration, database maintenance, or application-lifecycle work, you'll probably need to automate the unit-testing of the PowerShell scripts themselves. This series introduces you to Pester, the leading test framework for PowerShell, and provides "tips from the trenches" on using it most effectively for unit tests (with a gentle prodding towards a TDD style).
Part 1: Getting Started with the Pester Framework
Part 2: Mock Objects and Parameterized Test Cases
Part 3: Validating Data and Call History


4 Keys to a Clean Angular Implementation,, October 6, 2016
Best practices I have learned about separation of concerns when working with AngularJS.
XPath, CSS, DOM and Selenium: The Rosetta Stone,, April 4, 2011
This article presents a wallchart (in two versions) that is a cookbook; It includes an extensive recipe list for--and cross-reference between--XPath, CSS, and DOM, with attention for any Selenium considerations (since Selenium uses all three technologies). It is a useful reference for any of the separate technologies on its own merits, though!
Web Testing with Selenium Sushi: A Practical Guide and Toolset,, February 9, 2011
Selenium is a powerful, flexible, yet easy-to-use web testing platform. This article illustrates how to stretch Selenium's boundaries with my open-source extension Selenium Sushi, providing both a support library and a .NET project framework, to make Selenium more useful and make you more productive. It lets you, among other things: retarget different browsers and different application servers without recompiling, handle file URLs automatically and, most importantly, convert a standard code file emitted by the IDE into a substantially smaller piece of source code.
Acceptance Testing with FitNesse
While a reasonably good tool and I like to use it, FitNesse has a lot of "pain points". With my latest plunge into FitNesse I put in the effort to alleviate many of these pain points and wrote it all down. This is a seven-part series; here is what has been published so far:
Part 1: Overview of FitNesse, July 31, 2013
Part 2: Documentation and Infrastructure, August 23, 2013
Part 3: Naming and Layout, October 15, 2013
Part 4: Debugging, Control Flow, and Tracing, November 15, 2013
Part 5: Symbols, Variables and Code-behind Styles, January 16, 2014
Part 6: Multiplicities and Comparisons, February 6, 2014
Part 7: Database Fixtures, October 3, 2014

Source Control

Subversion and TortoiseSVN Cookbook
This is a developer's cookbook, full of a wide assortment of recipes for working more effectively with Subversion, mostly through TortoiseSVN but with a sprig of command line SVN and a dash of PowerShell mixed in.
Part 1: The Basics, November 3, 2011
Part 2: File Operations and Subversion Filtering, November 21, 2011
Part 3: In, Out, and Around, Janaury 16, 2012
Part 4: Sharing Common Code, February 13, 2012
Part 5: Instrumenting Files with Version Information, February 21, 2012
Part 6: Snapshots, March 19, 2012
Part 7: Managing Revisions, May 30, 2012
Part 8: Log Messages, September 11, 2012
Part 9: Servers, Repositories, Statistics, February 11, 2013
Part 10: Source controlling SQL Server, plus complementary clients, February 12, 2013
Part 11: Subversion and Oracle, April 3, 2013
Database Source Control Basics
Subtitled You"ve Been Doing Source Control Wrong... and How to Fix It, this series discusses how you need to source control both your code and your database, and how to do it in SQL Server Management Studio (with SQL Source Control), Visual Studio (with SQL Connect and AnkhSVN), and your file system (with TortoiseSVN).
Part 1: Getting Started, October 9, 2012
Part 2: The Essential Operations, October 9, 2012
Part 3: The Unified Solution, October 9, 2012
Wallchart reference


PowerShell Time Saver: Automatic Defaults,, January 30, 2017
PowerShell has a little known technique wherein you can provide defaults to cmdlets you use everyday--even system cmdlets. So you can do things like: always want to show help ina popup when you use Get-Help; always use -Confirm on cmdlets that accept it; specify a certain path parameter when you remote to a certain machine, etc.
Writing Cmdlets
PowerShell cmdlets can be written in PowerShell, of course, but sometimes needs dictate that you write them in C#. With just a bit of adjustment to your development perspective, it is rather straightforward to do that, particularly with this step-by-step guide.
Part 1: The Basics , February 19, 2016, shows how to get a working cmdlet written in C# in just 15 easy steps.
Part 2: Beyond the Basics, July 22, 2016, takes you to the next level, adding 5 more steps that provides some spit and polish to your cmdlets.
Persistent PowerShell: The PowerShell Profile,, May 16, 2016
The PowerShell profile gives you a mechanism to configure your PowerShell environment with modules, functions, aliases, and variables upon startup so that by the time you get your first prompt, everything you use regularly is already loaded for you. The complication is that there is not just a single profile, but actually 4. No wait, 6. Well, possibly more than that...
Documenting PowerShell
A PowerShell master should know how to generate content for Get-Help from cmdlets written in PowerShell and cmdlets written in C#, along with generating a web-based version of your module's complete API. The latest installment in this series shows the unified solution in a one-page wallchart.
Part 1: How To Document Your PowerShell Library, June 25, 2013, shows how to document a whole PowerShell library with the open-source DocTreeGenerator.
Part 2: Documenting Your PowerShell Binary Cmdlets, December 3, 2015, explains how to document binary or compiled cmdlets--those written in C#--as easily as those written in PowerShell. This article introduces XmlDoc2CmdletDoc, an open-source utility that fills the much-needed gap.
Part 3: Unified Approach to Generating Documentation for PowerShell Cmdlets, April 22, 2016, brings together all the necessary components in a one-page wallchart/infographic.
Ins and Outs of the PowerShell Pipeline,, October 22, 2015
Pipelining is an important technique for conserving memory, improving actual performance, and enhancing perceived performance. While PowerShell provides an ample supply of constructs for pipelining, it is all too easy to write code that simply does not pipeline at all.
Complete Guide to PowerShell Punctuation,, September 30, 2015
PowerShell seems to have more than its fair share of geekiness when it comes to its lexicon of punctuation. What does $_ mean, or % {...} or @{...} or [...]::... etc.? I've gathered together all the symbols and punctuation into a convenient wallchart to make navigating the PowerShell universe easier.
Build Your Own Resource Monitor in a Jiffy,, September 14, 2015
Figure out your PowerShell recipe to emit a data table of anything you like (a list of files or processes, actual DB data, whatever) and feed that to MonitorFactory to generate a near-real-time monitor of your resource.
Complete Guide to Using Quotes in PowerShell,, August 11, 2015
As simple as it sounds, the "how, when, and why" of using quotes in PowerShell--and what type of quotes to use--is not very well-known. Find out everything you need to know.
A Plethora of PowerShell Pitfalls
PowerShell can provide a tremendous boost in productivity for administrative-type tasks. However, as with any complex technology there are a variety of ways-some a lot more obvious than others-that you can cause problems for yourself without even realizing it. Test your PowerShell wits with this quiz on common PowerShell practices that can sneak up on you and yield unexpected results.
Part 1: Pesky Parameter Problems, April 2, 2015
Part 2: A Portion of Potential Puzzles, May 12, 2015
Part 3: The WallChart, June 25, 2015, which brings together pitfalls from the above with those from a wide array of other sources so you have the best of the worst all in one place.
Do Anything in One Line of PowerShell
PowerShell provides a tremendous boon to productivity for computer professionals of all types. It can be a bit daunting to get up to speed though. Indeed, as someone who has a fair amount of experience with it, I still find myself having to look up how to do things--frequently. So I started writing down the things I was using the most. And came up with a list of 400 or so, published in 4 parts.
Part 1: Help, Syntax, Display and Files, April 4, 2014
Part 2: Variables, Parameters, Properties, and Objects, April 24, 2014
Part 3: Collections, Hashtables, Arrays and Strings, May 13, 2014
Part 4: Accessing, Handling and Writing Data, June 5, 2014
PowerShell Data Basics
It's all about the data. This series shows you how to work with line-oriented data (by line, by index, by filter), field-oriented data (fixed width, ragged right, variable width), string data (hash tables, property lists, ini files, json), excel data, and XML data (with either XPath or object accessors).
Part 1: File-Based Data, December 2, 2013
Part 2: XML, January 3, 2014
Practical PowerShell for SQL Server Developers and DBAs
This series gives you a running start at setting up and using PowerShell, showing how easy it is to run queries with the sqlcmd equivalent in PowerShell and how to navigate in "SQL Server space" just like you can in "file system space".
Part 1: Configuration and Queries, July 23, 2012
Part 2: Navigating and Working in SQL Server Space, August 15, 2012
Practical PowerShell: Pruning File Trees and Extending Cmdlets,, April 23, 2012
Understand how to extend cmdlets with a practical example: extending Get-ChildItem to take an -ExcludeTree parameter to let you prune whole subtrees.
Further Down the Rabbit Hole: PowerShell Modules and Encapsulation,, August 24, 2011
Modules allow you to use standard libraries that extend PowerShell's functionality. They are easier to use than to create, but if you get the hang of creating them, your code will be more easily-maintained and re-usable.
Down the Rabbit Hole- A Study in PowerShell Pipelines, Functions, and Parameters,, July 14, 2011
For an experienced programmer to learn a new language can be a journey quite like Alice's in wonderland. Paradoxes, unexpected twists, blind tangents, bafflements and nice surprises. This examination of practices and pitfalls of functions yields some fascinating results.
Harnessing PowerShell's String Comparison and List-Filtering Features,, June 7, 2011
When you are first learning PowerShell, it often seems to be an 'Alice through the looking-glass' world. Just the simple process of comparing and selecting strings can seem strangely obtuse. This handy wallchart illuminates everything you need to know.


The Manual That Time Forgot
A primer on Red Gate's new foray into the MySql space, mirroring their outstanding products from SQL Server and Oracle:
MySql Compare, May 3, 2013
MySql Data Compare, May 28, 2013
The Definitive SqlDiffFramework,, April 30, 2010
I literally wrote the book on SqlDiffFramework--plus the application itself! This 150+ page user guide for SqlDiffFramework reveals everything you need to know to get the most out of comparing dissimilar data sources including SQL Server, Oracle, MySql, and any ODBC data source (e.g. Access, Excel, CSV, etc.).
Build a Generic Histogram Generator for SQL Server,, July 3, 2008
Histograms help people analyze large amounts of data, whether you display them as tables or as charts. This article shows you how to do both.
Add Custom XML Documentation Capability To Your SQL Code,, January 23, 2008
By adding XML-based documentation capability to your SQL code, you can automatically extract tagged comments and format them into truly useful documentation. Unlike other SQL documentation generators that document the schema and structure of a database, this article discusses a tool to generate a true API for the procedures and functions in your database.
Bring Array Mapping Capabilities to SQL,, November 1, 2007
Simplify your SQL tasks by giving your queries and stored procedures the ability to iterate over arrays of table names or values.
See also:
A Unified Approach to Multi-DataBase Query Templates
.NET Building Blocks: Build a Configurable Database Credential Selector
Practical PowerShell for SQL Server Developers and DBAs


A Visual Lexicon of LINQ,, April 25, 2017
This 3-part series brings illumination to the mysteries of LINQ in a highly digestible, easy-to-use set of reference material.
The main article enumerates every LINQ operator with not just a description but a visualization making it easy to grasp how the operator works.
The one-page wallchart dives deeper, providing the properties of every operator in a condensed table, identifying query or lambda syntax, where in a chain the operator may be placed, laziness (and not just deferred or immediate execution, but also to what degree of lazy!), time and space complexity, and a handful of optional properties.
Finally, for Powershell users, High Performance PowerShell with LINQ reveals the secret incantations necessary to use all the power of LINQ in your PowerShell code.
LINQ Debugging
LINQ has the capabilities of providing a great productivity boost. LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques. This turned out to be a two-part series:
Part 1: LINQ Secrets Revealed: Chaining and Debugging,, December 1, 2010
In this first part I talk about the standalone LINQPad utility, with its amazing Dump method, plus several techniques to use within Visual Studio, including a similar Dump method, and even using LINQPad's data visualization capability inside of Visual Studio.
Part 2: LINQ Debugging and Visualization,, December 1, 2016
Part 2 finally reveals--exactly six years later!!--the new OzCode feature to truly visualize and debug LINQ effectively.
LINQ Lycanthropy: Transformations into LINQ,, January 5, 2011
In this article I attempt an explanation of my thought process as I convert conventional code into LINQ code.
LINQ Secrets Revealed: Chaining and Debugging,, December 1, 2010
LINQ has the capabilities of providing a great productivity boost. LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques. In this article I talk about the standalone LINQPad utility, with its amazing Dump method, plus several techniques to use within Visual Studio, including a similar Dump method, and even using LINQPad's data visualization capability inside of Visual Studio.
Using LINQ Lambda Expressions to Design Customizable Generic Components,, January 27, 2010
The traditional means for making a generic component that is customizable is the callback method. With LINQ one can do the same thing with just a bit more panache. I like to present my ideas grounded in specific, practical applications: in this case, I chose a file masking user control, allowing a user to filter a list of files from a directory by specifying one--or more--file masks and displaying a dynamic list of matching files. I then add on top of that a thorough discussion--with sample projects!--for injecting additional, arbitrary constraints in the form of LINQ lambda expressions.
Using LINQ to Manage File Resources and Context Menus,, May 8, 2009
This article takes a fairly simple technique involving both LINQ-to-Objects and extension methods (both new concepts in C# 3.0) and uses it as the heart of two moderate complexity components that could themselves be immediately incorporated as building blocks in a production application. What is interesting is that the two components are quite different on the surface: one involves managing an application's external (file) resources; the other involves initializing choices in a context menu upon a right-click to open the menu. I present a thorough discussion of the LINQ and extension methods that comprise the key portions of the code.
See also:
Using Three Flavors of LINQ To Populate a TreeView

Windows Presentation Foundation (WPF)

Mixing WPF and WinForms,, August 10, 2010
One of the earliest-but still important-tenets of software engineering is the concept of reuse with "software building blocks". In the .NET framework, user controls are the quintessential building blocks, giving you a simple yet powerful way to encapsulate a set of visual components into a more complex one. This holds true both in the WinForms realm and the WPF realm. What is not well known, nor particularly obvious, is that you can build hybrids, embedding WPF controls in a WinForms application or WinForms controls in a WPF application, using simple adapters. And you can do this either with your custom user controls, or with the set of the full set of .NET controls if the "other" technology has a control you need.
Creating WPF Prototypes with SketchFlow,, June 18, 2010
Typical prototypes take too long, cost too much, or achieve too little (or some combination of those). Think back to when you were designing and writing code before Visual Studio. And then, one day, you discovered the capabilities that Visual Studio provides. You could create WinForm applications by dragging and dropping controls from a toolbox and editing their properties! You could create and connect data sources; develop class diagrams; etc. Visual Studio was an earthshaking paradigm shift in design and development. With the advent of SketchFlow the landscape for creating prototypes has changed. SketchFlow is new, not very well known, not even a standalone product. But it is earthshaking in a similar way.
Essential Tools for the WPF Novice,, May 19, 2010
WPF is simultaneously enticing and intimidating. It offers potential for amazing flexibility in UI design but there is a mountain of learning to climb. In this article I present a collection of little known but useful utility applications that can assist you as you learn and develop WPF code.
From WinForm to WPF: A Quick Reference Guide,, March 23, 2010
A handy wallchart to help migration between WinForm / WPF, VS 2008 / 2010, and .NET 3.5 / 4.0.

Visualization, Documentation, and XML

Ten Unsung Visual Studio Time-Savers,, April 6, 2017
A collection of lesser known VS extensions to assist editing, documentation, and more.
Taming Sandcastle: A .NET Programmer's Guide to Documenting Your Code
The most effective way to document .NET code so that others can understand and use it is with XML Documentation and SandCastle. But the documentation for creating documentation is--quite ironically--hard to come by! This article and wallchart is a guide to the process and the pitfalls.
Taming Sandcastle article, September 13, 2010
Wallchart on Sandcastle Help File Builder, October 11, 2010
Taking XML Validation to the Next Level: Content Assembly Mechanism (CAM)
Part 1:Introducing CAM, March 5, 2009
Part 2:XSD Schema vs. CAM, March 13, 2009
Part 3:Explore CAM's Expressive Power, March 16, 2009
XmlTransform: A General-Purpose XSLT Pre-Processor,, January 23, 2008
Use this XmlTransform application to generate sets of HTML pages, SQL documentation, or apply it to your own particular needs. XmlTransform is a general-purpose XML transformer and validator that operates on an arbitrarily deep directory tree containing files you want to transform, optionally generating multi-level indices and adding navigational linkages.
Visualizing Data: Self-Documenting Ant files,, October 10, 2007
How one visualizes a concept can greatly impact how well one understands it or, perhaps more importantly, how well one may communicate the concept to others. In this case study I focus on Ant build files and show how different perspectives on the same code allow you to absorb more information faster, reduce errors, and provide intuitive methods to help you comprehend, modify, and test build targets.
See also:
How To Document Your PowerShell Library (scripted cmdlets)
Documenting Your PowerShell Binary Cmdlets

User Controls for .NET Windows Forms

A Unified Approach to Multi-DataBase Query Templates,, September 30, 2009
Part 1 (of 3) of my series on the QueryPicker control: No matter how good your SQL skills are, walking into a new situation with unfamiliar databases is only going to make that task trickier; and most large companies - and many small ones, too - will have a heterogeneous database environment, unless you are very fortunate. Mixtures of SQL Server and Oracle are fairly common, and every database type will have different structures and different syntax to remember. This article describes a .NET control called a QueryPicker, a cross-platform query template solution to make life easier.
How to build a Query Template Explorer,, October 23, 2009
Part 2 (of 3) of my series on the QueryPicker control: This article presents the technical details on how to integrate the QueryPicker into applications both simple and complex. With screenshots and code samples, this has everything you need to build your own powerful SQL editor or query template explorer.
Using Three Flavors of LINQ To Populate a TreeView,, December 2, 2009
Part 3 (of 3) of my series on the QueryPicker control: For LINQ lovers, this provides a treatment of how the QueryPicker populates its TreeView from XML using LINQ to Objects, LINQ to XML, and LINQ to XSD.
.NET Building Blocks: Custom User Controls
Part 1 delves into the nitty gritty details required to create, test, use, inherit, install, and distribute .NET User Controls of all types. Part 2 explores the differences between the various types of custom controls, and shows how to integrate your controls into Visual Studio and make them easy to use.
Part 1: Custom User Control Fundamentals, May 15, 2008
Part 2: Custom User Controls In Practice, July 9, 2008
.NET Building Blocks: Build a Configurable Database Credential Selector,, September 14, 2007
This handy control provides a complete solution for interactive handling of database credentials, giving you everything you need to control how users input usernames and passwords, select servers, and choose connection types. After I created a few different proprietary applications where I had to create a custom login form for each, I decided it was time to make one generic enough to be flexible and configurable with just a few lines to set properties.
.NET Building Blocks: Build a RichTextBox-Based Syntax-Highlighting Editor and IDE,, August 1, 2007
By using a SyntaxHilightTextBox control, you can build an editor for the language of your choice that highlights keywords, quoted strings, and comments. The article further shows just one example (a VBScript interpreter) of how easy it is to build an IDE leveraging this control.

Explorations into .NET

.NET Reflector: Through the Looking Glass
.NET Reflector is a tremendous productivity tool but is not very strong in documentation. This series fills in the gaps.
Part 1: Installation and Basic Usage, January 14, 2013
Part 2: Meat and Potatoes, January 15, 2013
Part 3: Analysis and Exploration, January 18, 2013
Part 4: Extending Reflector, January 21, 2013
Creating Tray Applications in .NET: A Practical Guide,, November 4, 2010
This article is different: you can read it backwards or forwards. If you have seen those old books-with two books literally pasted together back to back so that if you flip it over you have a different book to read-this article is like that. It discusses tray applications in WinForms or WPF or both, with consideration of three techniques for mutual exclusion, and presents a tray application framework that you can put to immediate use. It also presents--as a real-world example of the framework--a utility to switch your host file servers from development to staging to production with one click, called HostSwitcher. So you can download either source or an installer for HostSwitcher.
Exploring Secrets of .NET Keystroke Handling,, October 23, 2008
If you've ever been frustrated trying to figure out how to intercept or assign specific keystrokes to specific controls, you'll be glad you found this article. It reveals not only the fundamentals about how keystroke handling is exposed in the .NET framework, but also provides a handy Keystroke Sandbox to actually observe how keystrokes flow through an application, and concludes with a "cook book" detailing how to instrument your code for all the common key handling hooks.
Exploring Secrets of .NET Diagnostics,, March 14, 2008
Diagnostics, or program tracing, is a crucial-and often overlooked and underappreciated-component of application development. It is useful not only during program development but even more so once your application is deployed. Ongoing maintenance costs are one of the largest segments of software's true cost, and well-instrumented diagnostics can reduce maintenance costs significantly.
Exploring Secrets of the .NET DataGridView and Dynamic Data Manipulation,, June 22, 2007
Find out how to use a single DataGridView to display dynamic queries, adjusting columns automatically, and how to format individual cells exactly the way you want users to see them.
Exploring Secrets of BindingSource Filters,, April 23, 2007
Visual Studio gives developers the extraordinary capability to build a database application with a working graphical user interface using just a few mouse clicks. Populating the DataGridView requires a round-trip to the database every time the underlying query needs to be refreshed. This article discusses a technique to eliminate that round-trip, dynamically updating the underlying query of a DataGridView virtually instantaneously. The perceived performance difference is dramatic (akin to the difference between browser-embedded JavaScript updating versus page refreshing from a web server).
Exploring Secrets of Persistent Application Settings,, March 6, 2007
The MSDN documentation includes a lot of material on persisting application settings in a Windows application. But like much documentation, it's primarily a reference rather than a practical implementation guide, giving the complex and intricate usage details of settings without giving a clear and concise discussion of typical simple uses--exactly what a large number of users will be interested in. This article attempts to provide some tips on implementation.
Exploring Secrets of Windows Form Validation,, January 12, 2007
Input validation is something that every program needs, and every programmer dreads. Most developers craft hard-coded program logic to verify that a phone number consists of 7 or 10 digits; that an IP address consists of 4 octets; that a country name matches 1 of 193 choices, etc. While .NET 2.0 provides some support for streamlining input validation, it barely scratches the surface of automating and simplifying the input validation process.
Valid XHTML 1.0!Valid CSS!Get CleanCode at Fast, secure and Free Open Source software downloads
Copyright © 2001-2015 Michael Sorens • Contact usPrivacy Policy
Usage governed by Mozilla Public License 1.1 and CleanCode Courtesy License
CleanCode -- The Website for Clean DesignRevised 2015.12.16