Image Image

Eradicate
Boilerplate Code and Architecture Erosion.

A modern open-source meta-programming framework for code generation, aspect-oriented programming, and architecture verification in C#.

  • Reduce code and bugs by 15%. Let the machine handle repetitive tasks, freeing engineers to focus on meaningful work.
  • Maintain clean and readable code. Simplify your codebase for better maintainability and collaboration.
  • Enforce architectural consistency. Define validation rules in C# and receive instant feedback directly in your IDE.

What Are Boilerplate and
Architecture Erosion Costing You?

#A Total Waste of Time

Manually writing boilerplate is not only boring and frustrating, but also a total waste of your time. Why manually do what a machine can accomplish more efficiently and swiftly?

Although allowing architecture to erode initially saves time, as it progressively accumulates, it makes everyone on the team less productive.

#Excessive Complexity

If your business logic is cluttered with boilerplate, the source code becomes so complex that it's no longer comprehensible.

As the source code diverges from the original architecture, more exceptions to the rule are introduced, increasing the conceptual complexity of the source code.

#Avoidable Defects

Boilerplate is often riddled with bugs because it's created by copy-paste programming and is largely untested. Production-readiness features such as logging or caching are neglected because they are too costly to build without the appropriate tools.

As the complexity of your codebase increases, its overall quality suffers: end-users encounter bugs and performance deteriorates.

#Expensive Maintenance

As both boilerplate and architectural erosion contribute to increasing complexity, small changes to your application become increasingly expensive. A larger refactoring becomes completely unfeasible, necessitating a complete rewrite of your entire codebase.

Intelligent use of meta-programming could extend the lifespan of your codebase by several years.

Image Image

Our Approach:
Compile‑Time Meta‑Programming

meta-programming (noun): The practice of writing programs that can generate or manipulate other programs or themselves at run time or build time. It involves creating code that can produce, modify, or analyze other code, often to reduce redundancy and increase code quality.

aspect (noun): A meta-class that encapsulates cross-cutting concerns, such as logging, caching, or code validation constraints, and can be applied to multiple classes or methods in a codebase. Aspects allow developers to separate these concerns from the main business logic, improving code organization and maintainability.

Show Me Code!
How Does It Work?

1. Create an Aspect Class or Use an Open-Source One

Aspects are meta classes that transform code using simple C#-based templates. They can also report warnings and errors or suggest code fixes.

Don't want to learn a new framework? No problem, dozens of open-source aspects are available on Metalama Marketplace for you to use or modify.

2. Add Aspects to Your Business Code

There are two approaches:

You can apply each aspect individually using a custom attribute.

Or, you can apply aspects in bulk using compile-time LINQ-like code with a fabric.

4. You're Done!

Upon compilation, Metalama seamlessly merges the aspect template with your business code. This process is executed on the fly to maintain the clarity of your source code.

The Result:
Clean, concise code adhering to architectural guidelines and design patterns.

Metalama

Boosting Development Efficiency

Metalama streamlines software development by reducing code by 10-50%, thereby enabling developers to focus on meaningful tasks. It enhances job satisfaction by eliminating repetitive low-level code and frustrating reviews. Furthermore, it acts as a talent multiplier, empowering architects and senior developers to tackle architectural challenges. New team members can contribute effectively without being overwhelmed by low-level technical details.

Taming Code Complexity

The separation of technical details from business logic results in cleaner, more readable code, which allows team members to work more efficiently. Strict adherence to the initial architecture and design patterns reduces complexity, ensuring a manageable, well-structured codebase. This approach helps to prevent excessive rules and violations, whether unintentional or due to unwarranted creativity, thereby maintaining overall simplicity and integrity.

Elevating Application Reliability

Aspects enhance the readability and maintainability of the codebase by separating technical and business logic. Meta-programming promotes consistency and streamlines reviews, thereby reducing developer oversights and limiting unwanted creativity. Additionally, aspects improve software modularity, preventing duplication and enhancing reusability, adaptability, and efficiency.

Streamlining Maintenance

Metalama's ultimate advantage lies in reducing maintenance costs and extending the lifespan of the codebase. Given that maintenance accounts for 55%-95% of a software system's costs, maintaining low complexity is crucial for post-release team member productivity. Considering that developers spend approximately 70% of their time understanding code, maintaining simplicity significantly enhances the efficiency of the maintenance team.

Use Cases

How Does It Compare?

MetalamaPostSharpRoslyn Plug-InFody
Transformation of the compilation using low-level APIs
YesYesNoYes
Addition of behaviors to source code using simple custom aspects or templates
YesYesNoNo
Introduction of new members or interfaces and referencing them in the source code
YesNoComplexNo
Analysis of the source code and reporting of warnings and errors in real-time
YesRequires RebuildComplexComplex / Requires Rebuild
Debugging and exporting of transformed code
YesNoN/ANo

What's Holding You Back?

Can I achieve the same results with classic C# and Roslyn API?

You might be considering using directly Roslyn's low-level APIs such as analyzers, generators and interceptors.

Not only does Metalama provide a simpler and more integrated solution on the top of Roslyn, but it also adds features Roslyn simply don't offer.

Metalama is Simpler. Meta-programming at the abstraction level of Roslyn is intricate, demanding years of experience. When approached naively, low-level meta-programming can resemble hacking and can significantly amplify complexity, especially after the departure of the developer who implemented the meta-code.

Metalama is Integrated. Metalama stands alone as the only tool that allows you to both generate code visible at design time and override hand-written code. To replicate what Metalama offers, you would need to juggle a combination of Roslyn APIs that lack integration.

Metalama is Engineered for Good Architecture. Metalama is designed to simplify development. It avoids offering hacks that render the code less predictable or comprehensible. Software development encompasses three cultures: hacking, science, and engineering. We identify with the last one while remaining mindful of the other two.

Metalama is a Complete, Well-thought-out Solution. Unlike alternatives that focus on the most common use cases and cut corners – for instance, by failing to properly implement async methods – Metalama goes the extra mile and incorporates enough extension points to ensure you never hit a dead end.

I'm concerned about losing control over my code.

Delegation is what you actually want. You want the machine to handle low-level, repetitive details, freeing up more of your time to focus on meaningful tasks.

You're already accustomed to This. Initially, people were apprehensive about losing control over performance when the industry transitioned from assembly language to C, and then to the managed, garbage-collected memory model of C# and Java. We've relinquished control over low-level details but have gained enormous productivity and reliability.

You're not completely losing control. Metalama offers numerous mechanisms to override default behaviors.

You can revert to the source code at any time. There is no vendor lock-in.

What if I am already using ReSharper, Rider, or CodeRush?

You can and should use both. We are also fans of refactoring tools.

Metalama reduces the amount of code. While refactoring tools help developers write code faster, they do not reduce the amount of code necessary to implement a feature.

Metalama simplifies the writing of custom rules and code fixes. Other refactoring tools often have more complex APIs.

Is Metalama difficult to learn and use?

While metaprogramming and AOP can introduce new concepts, Metalama is designed for a gradual learning curve.

Start simply, grow gently. Metalama's simple APIs can get you started in minutes. As you start understanding the technology and want to implement more complex rules, between 4 and 16 hours of learning might be necessary to master the framework.

Leverage ready-to-use aspects. Don't reinvent the wheel. Leverage the dozens supported and open-source aspects that cover the most common requirements. Find them in Metalama Marketplace.

Comprehensive documentation. It offers clear documentation, tutorials, and API references to help developers onboard quickly.

Team Learning. Not everyone on the team needs to learn Metalama in detail. Only architects or senior developers writing aspects will need a detailed understanding. For other team members only using aspects, a simple 1-hour training will be enough to get started.

Does Metalama make debugging harder?

One of the key concerns with metaprogramming is debugging, but Metalama provides tools to mitigate this.

Source Mapping. You can switch between source and transformed code debugging.

Code Preview. You can compare transformed code to source code before compilation, improving transparency thanks to Visual Studio Tools for Metalama.

Does Metalama introduce performance overhead?

Not at all. Metalama is a highly-optimized solution based on compile-time code inlining.

Compile-Time. Unlike runtime-based frameworks, Metalama does not rely on reflection or emitting dynamic proxies at run time.

Efficient. The transformations generate high-performance code that integrates seamlessly with the application. Unlike previous generations of AOP frameworks, Metalama does relies on code inlining (i.e. template expansion) and does not introduce performance or memory allocation overheads.

Will I still understand my code?

We believe that you will comprehend the business meaning of your code even better than before since it will not be cluttered with boilerplate. When the time comes to read the fine print, Metalama shows you the exact generated code.

Show or Debug Generated Code. Switch to the LamaDebug build configuration to see exactly the code generated by Metalama. You can even debug it!

Diff Preview. Compare source and transformed code directly within Visual Studio.

CodeLens Integration. See which aspects are applied to a method directly in the editor.

Aspect Explorer. See which aspects are present in the solution and how they affect the code.

Read more about Visual Studio tooling.

Is Metalama well-supported by development tools?

Metalama is built on Roslyn and is designed to work seamlessly with .NET development environments.

At design time, all editors that support Roslyn automatically support Metalama.

At build time, Metalama integrates with MSBuild and can be used in any build server.

Visual Studio Tools for Metalama are designed to enhance developers productivity but are not required for development.

What if Metalama is discontinued or loses support?

Metalama is actively developed and maintained by PostSharp Technologies.

Established Vendor. PostSharp Technlogies has a 20-year long history of supporting AOP in .NET, providing confidence in long-term support.

Fallback Strategy. Since Metalama generates regular C# code, applications can transition to manual implementations if necessary thanks to the Metalama Divorce feature.

Can excessive use of Metalama harm maintainability?

Like any tool, Metalama should be used wisely to maintain a clear and maintainable codebase.

We recommend:

  • to use Metalama to automate patterns that affect at least 20 classes or properties;
  • to avoid hacks and to preserve the semantical and conceptual integrity of the code (don't do anything unexpected);
  • to defensively validate the code to which aspects are applied, and reporting errors upon unsupported situations instead of generating code that might not compile.
Is Metalama overkill for most projects?

Metalama is designed for scalable projects but can be used selectively where it adds real value.

Progressive Adoption. Developers can start with simple aspects and expand usage as needed.

Pragmatic Approach. We advise against overuse and promote using aspects only where beneficial.

Get started with Metalama.