Hey, remember ASP.NET? That web framework with the crazy
runat=server postbacks that only ran on IIS and was incompatible with everything? And remember ASP.NET MVC, where they copied Ruby on Rails because it was popular at the time? Silly Microsoft, they don’t understand the web. So let’s dismiss the new .NET 5 that was released this month, right? Wrong!
Enter .NET 5
People have been sleeping on .NET and they’re missing out. This month marks the release of .NET 5, the successor to .NET Core 3.1. .NET Core was rebuilt from the ground up as a modern open source framwork and dropping the ‘Core’ from the name signifies the end of the old Windows-based .NET Framework 4.x that I referenced above. This illustrates Microsoft’s dedication to this ‘new’ .NET that feels equally at home in a Linux container as it does on Windows.
What is .NET?
.NET is a cross-platform managed software platform that comes with everything to build anything from CLI apps, web apps and API backends to native cross-platform applications, using the excellent C# and F# languages. Microsoft also promotes use of .NET for machine learning and Internet-of-Things applications. You can read more about .NET and its applications at Microsoft: What is .NET?.
C# Programming Language
C# (pronounced C sharp, like the musical note) is an incredibly popular language (PYPL, TIOBE). It’s relatively easy to learn and use but has has powerful modern features (generic programming, LINQ syntax, and functional concepts like immutable types and pattern matching). C# .NET compares well with Java and Go in full-stack benchmarks. Finally, it’s widely applicable. For example outside of .NET it’s popular for game development with the Unity engine.
// Example C# code
var names = new List<String>
foreach (var name in names)
F# Programming language
While C# is usually found in the top 5 of programming language popularity contests, F# doesn’t even make it to the top 20. F# is a functional-first multi-paradigm programming language that isn’t quite as popular as for example Scala, Clojure or Erlang and Elixir, but can definitely hold its own in a comparison. It’s a first-class citizen on .NET, so anything you can do in .NET with C# you can do with F#. On top of that it adds some very interesting features like Type providers.
// Example F# code
let names = [ "Ana"; "Felipe"; "Emillia"]
|> List.iter (fun name -> printfn "Hello %s" name)
.NET for Rubyists
I have been a Ruby and Ruby on Rails developer for over ten years. Reports of Ruby’s death have been greatly exaggerated, but to hedge my bets and prevent myself from obsolescence I’ve been looking at other technologies that might replace Ruby for me over the years. What I was looking for in comparison to Ruby was roughly:
- A language that is likeable and enables developer productivity;
- A skill that is in demand and easy to sell;
- A runtime that outperforms Ruby;
- A community rooted in open source;
- Something mature and with a large backing.
There have been many candidates along the way. So far Go was the one that stuck with me the longest. It’s easy, has great tooling, is mature, and is popular. However, coming from a Ruby background, Go felt a bit bare bones at times. Go is versatile, but it has a different philosophy that is often compared to that of Unix: here’s a large bag of small tools, feel free to combine them in any way you like. It worked, I enjoyed it, but in the end the lack of larger frameworks and conventions meant it wasn’t perfect for me.
Enter C# and .NET: a language paired with a batteries-included, opinionated framework that can do many things, yet is completely modular and easy to understand. I happened upon a .NET Core application that was part of a larger microservice architecture I was maintaining. Looking at the code it was very easy to understand and I had no problem getting it running in a local development container. After looking into C# and .NET by building some small apps I realized .NET ticked all five of my boxes. First WSL, then VS Code, now .NET? I’m still getting used to this new Microsoft!
IntelliSense for everyone
To me, as a Rubyist, the excellent tooling around .NET was another pleasant surprise. The Ruby language makes it hard to do static analysis and the dynamic nature requires a lot of testing to prevent nasty type issues from happening. Developing C# with the Omnisharp language server (that works with anything from VS Code to Vim) is amazing. After a decade of Ruby I forgot how nice it is if your editor shows you a red squiggly line indicating a problem without having to hit the code at runtime. We shouldn’t turn our noses up at this. Ruby is defined by terrible tools and there’s no salvaging it. The .NET tooling brings an instant performance boost.
It’s weird navigating the .NET blogosphere because a lot of tutorials start out with screenshots of the Visual Studio ‘new project’ wizard. But the dotnet CLI can do everything Visual Studio can and there’s an increasing amount of people from a non-Windows and OSS background, so you’ll notice a lot of the more recent material is tailored to a different crowd. Finally, the NuGet package manager is integrated in .NET and is the primary way of sharing libraries among .NET developers, not unlike Rubygems/Bundler and npm.
The business perspective
What’s interesting is that in recent months I’ve encountered more than one agency with a Ruby or Python background that made the switch to .NET, not just because they like it but also because it’s easier to sell ‘.NET on Azure’ than ‘Ruby on Heroku’. You can hate on that, but from a business perspective this is important. You need a technology that is easy to sell and one where you can find developers for. .NET 5 has both.
Of course C# is not the one language to rule them all. No language can make that claim. Performance is great for a managed runtime; it exceeds Ruby, but it’s no Rust. There is less ‘magic’ in .NET than in Ruby on Rails, but it comes at the cost of (a little) more boilerplate. From a pragmatic point of view, though, I think it’s one of the best languages out there for web and app development.
If you want to explore .NET, here are some resources I found helpful: