Back to the
bright side
of coding

Boilerplate:
the biggest downside of vanilla C#

C# lacks a pattern keyword

Unlike many other languages, C# lacks a modern problem decomposition mechanism to cope with features like logging or caching, design patterns like INotifyPropertyChanged, or threading models like immutable or thread affine.

Therefore, developers must write tons of low-level repetitive code that requires little ingenuity but is highly error-prone: the notorious boilerplate.

designpatterns

What is boilerplate costing you?

A Total Waste of Your Time


Boilerplate leads to increased development time; boredom and frustration; and waste of your time.

Your App is Unreliable


Boilerplate causes too many bugs; makes the code hard to fit your brain; and hardening features unaffordable.

Your App is Unmaintainable


Your business logic is unreadable; implementation inconsistent across the team; and boilerplate is difficult to refactor.

1. Boilerplate increases development time

It takes effort to write and test repetitive code, which means that you will either need more time to complete your project or add more members to your team.

2. Boilerplate is boring and frustrating

Solving the same low-level problems over and over again is exasperating. Smart people enjoy being inventive and feeling they are genuinely adding value.

3. Boilerplate is a waste of talent

Let’s face it, companies are limited by the number of good developers they can attract to their project. It’s a pity to get your most talented team members labor over problems that could be avoided in the first place.

1. Boilerplate causes too many bugs

It is mostly written by copy-paste, it is very boring, and often remains untested.

2. Boilerplate makes the code no longer fits your brain.

Many problems like thread synchronization, INotifyPropertyChanged or caching are addressed at an absurdly low level of abstraction and make it too complex to grasp even for the best developers.

3. Boilerplate makes hardening features unaffordable.

Features, such as logging or caching, are expensive and boring to implement because they affect every single part of the application. They are often neglected, and if they are implemented, their testing is often neglected.

1. Boilerplate makes your business logic unreadable

If the business logic is cluttered with loads of technical details, it becomes difficult to read and understand the code. A real nuisance if you consider that reading code typically makes up 80% of software maintenance.

2. Boilerplate is often inconsistently implemented across the team

Implementation guidelines, when they exist, are not always respected by different team members. Therefore, it takes more cognitive load to understand the source code and the architecture.

3. Boilerplate is difficult to refactor

It is very difficult to change the implementation strategy of features like logging, exception handling or INotifyPropertyChanged because it is potentially scattered among thousands of files.

Aspects:
the remedy to boilerplate

Aspects are like custom attributes that alter the way your code executes. They are special classes that describe how the compiler should enhance your source code. Aspects can also validate that hand-written code complies with predefined rules.

You can think of PostSharp as a next-generation aspect-oriented framework that includes the best from static analysis and metaprogramming.

Example aspects

  • Logging
  • Profiling
  • NotifyPropertyChanged
  • Caching
  • Immutable
  • Thread–Affine

Example aspect building blocks

  • Add try/catch/finally to a method
  • Intercept method/field/property/event
  • Introduce interface
  • Introduce custom attribute

How does it work?

1. Add the PostSharp package to your project and annotate code with [CustomAttributes].

2. The C# or VB compiler builds your code into binaries.

3. PostSharp analyzes the binary and injects the implementation of the aspects.

Your app, production-ready

At run time, both your business logic and the aspects are seamlessly executed. Your source code remains crystal clear.

The result:
your code is shorter and cleaner

More Time for Meaningful Development Tasks

PostSharp moves your implementation workloads from the team to the compiler; helps you focus on meaningful and inventive tasks; and makes the most of your team.

Your Application is More Reliable

PostSharp leads to less boilerplate which means fewer bugs; helps coding at a right level of abstraction and hardening becomes affordable.

Your Codebase is Easier to Read And Maintain

PostSharp helps writing crystal–clear code; improves code consistency and compliance; and improves architecture.

1. Move 20% of your implementation workloads from the team to the compiler

With PostSharp, you write the aspect once, then save time and reduce source code every time the aspect is applied. The result? Your codebase is reduced up to 23% for the same functionality and superior reliability.

2. Focus on meaningful and inventive tasks

Because you are now relieved from writing repetitive low-level code, you can focus on more inventive and value-adding tasks and feel more satisfied about your work.

3. Make the most of your team

Let architects/senior devs focus on the cross-cutting architectural issues; and new/junior team members get started faster as they can focus on discrete tasks and not worry about low-level technical details.

1. Less boilerplate means fewer bugs

In a typical business application, there is one defect for every 40th line of code . By reducing the amount of source code, you are not only decreasing the development cost, but also the number of defects.

2. The right level of abstraction

With PostSharp, you code at a higher level of abstraction. Most of the low-level details are reliably handled by the compiler. Your source code is simpler and therefore the number of defects decreases.

3. Hardening becomes affordable

With PostSharp, you can add comprehensive logging to your complete codebase in minutes and add features such as logging or exception handling without cluttering your business logic.

1. Crystal-clear code you can be proud of

With technical details clearly separated from the business logic, your code is cleaner, and easier to read. New team members need less time to understand the code, fix bugs, and add new functionality.

2. Improve code consistency and compliance

Validate user-written source code against implementation guidelines and avoid unwanted developer inattention or inventiveness that would otherwise result in defects or superfluous complexity.

3. Improve architecture

Increase the modularity of your software architecture to avoid source code duplication (better reusability) and make it easier to react to changes in requirements (lower coupling).

Professionally engineered

Developer–friendly License

  • Usage-based and user-based licensing.
  • Includes 1 year of support and updates.
  • Unlimited number of build servers.

Professionally Supported

  • Backed by a stable company.
  • Excellent documentation.
  • New releases every 3 weeks.

Platform Support

  • .NET Framework and .NET Core.
  • Visual Studio 2015, 2017, 2019.
  • Build servers, Azure DevOps, Docker.

A winning attitude:

  • Best-rated Visual Studio extension
  • Over 7.5M combined downloads
  • Serving commercial customers since 2005

Trusted.
From startups to corporates.

"PostSharp is a pretty amazing piece of software."

Stay DRY with aspect oriented programming by injecting repetitive code directly into your application. Abstractions like AOP are the whole point of what the computer is supposed to do for us, work that’s not fun, like logging and transactions. So why not hide that?

Scott Hanselman
Principal Program Manager, Microsoft

"PostSharp should be part of every C# developer's toolset."

PostSharp is amazing! If you are not using it, you should! The amount of code that can be reduced in logging alone is worth the price! I believe that PostSharp should be part of EVERY C# developer's toolset.

Eric Ziko
System Programmer, Wells Fargo

"Working declaratively is a dream!"

PostSharp is the best way to implement cross-cutting functionalities in a very elegant and efficient way. And when you want to enforce some design rules in your code, working declaratively is a dream!

Pierre-Emmanuel Dautreppe
.NET Architect, Thales Information Systems

"PostSharp simplicity is simply amazing."

PostSharp rocks! And I mean that as someone who is doing AOP for a long while, and has implemented some not insignificant parts of Castle.DynamicProxy. Leaving aside the amount of power that it gives you, PostSharp simplicity is simply amazing, wow!

Oren Eini
Author, RhinoMocks

"PostSharp is very easy to use."

Releasing developers from writing boilerplate or infrastructure code helps my team to complete features faster. We definitely save coding time with PostSharp. We’re relieved from writing INotifyPropertyChanged and creating ICommand properties needed for data binding.

Bernd Hengelein
Software Architect, Siemens Audiology