Postmortem: .NET MVC and Knockout

In my current job, one of the clients uses .NET MVC for its products and they wanted a "simple" administration panel. I was assigned this client for a month, and I stayed two. One of the reasons was that they didn't have a good scope of all the web services the admin panel was going to use. Therefore, many web services were developed in parallel with the admin panel screens, and guess who was in charge of developing the web services? I.

On the back end

I don't have much experience with Microsoft tools, and even less with .NET MVC, but I can say that it is a great tool. Visual Studio is superb as a development IDE and even superior than many other tools at debugging. However, even the best tools can become a nightmare if good practices are not followed:

  • Use only one language (natural) for variable naming, it is difficult to read when there is a nuevoCustomer variable (mixing Spanish and English)
  • Use consistent tabbing. It doesn't matter if you use tabs or spaces, but try to have a consistent structure in your code. Use a tab of size 4 and four spaces, or a tab of size 2 and two spaces, just try to be consistent.
  • Be specific with the exception handling. Don't just put a try catch block in the last execution method. Use useful messages and catch accordingly.

Personally, I prefer the open curly brace of a method in the same line where the function definition is. It was difficult for me to follow the C# way, but at the end, I got used to it.

On the front end

For the administration panel I use Materialize as theme, and Knockout as MVVM (Model view viewmodel) framework. Why did I chose Knockout? I was asked to use Angular.js, but it could be an overkill, I wanted to use something simple but useful at the same time; since most of the pages will be server-side rendered I just needed to keep states for some animations and controls in each page; thus I chose Knockout.

Knockout is really simple to use, and it can be very powerful. The downside is that it requires the model as a json object and I had my model in html markup (remember the server-side rendering). I wrote a new Knockout directive to load the model from markup; it was not beautiful but it worked really well. I enjoyed learning and working with Knockout, but to be honest, I would not use it for some big project, I would go instead with Angular or Ember (I could go with React or Vue, but they are only rendering libraries).

In summary, .NET MVC is a great tool to develop web services and web pages, I'm just not a big fan of Windows, although I use it frequently to play video games. Knockout is a good MVVM library for JavaScript, and it shines for small projects. Usually, which tool you use to solve a problem doesn't matter as long as you use good programming practices (please always be consistent).