Being a magician

This post is about a thin line between a helpful utility and full on magic show.

In programming languages there exists the concept of syntactic sugar. This means you can write with fewer characters a solution that would otherwise be a lot of boilerplate or superfluous code.

The other concept is that you annotate or decorate parts of your code and it will be automatically modified to enhance it somehow or just apply a bunch of standard transformations that eliminate a lot of boilerplate.

Sugar sugar...

So the concept of having a little syntactic sugar is I think very nice. Like having a null coalesce operator, meaning you can do stuff like

var a = obj ?? "Empty";

Instead of manually checking of null and then assigning it through either a function or a ternary operator . Because what check do you go for ?

var a = obj == null ? "Empty" : obj;

Or

var a = obj != null ? obj : "Empty";

The style is up to you.

There also exists too much syntactic sugar. For example Ruby is almost all syntactic sugar and it takes so much away from the developer that aside from becoming hard to read the fact is you kind of lose the sense of what is actually going on.

Automagical

So there are also frameworks that make you annotate and then automagically stuff will happen. In a simple sense this is nice, like decorating a function to map to a REST API endpoint route. It is clear, concise and easy to reason about. Plus you do not need the low level plumbing of getting the request, parsing it and finding the path and then get the function responsible for it.

There is a downside to the magic. That is it takes away control and more importantly it hides what is actually going on. In Spring Framework using Spring Boot and Spring Rest Framework the annotations become more than actual code if you don't take care of controlling it. Then it is no longer clear what actually happens, what endpoints get created and how they are authorised or not.

The argument for faster developer cycles is moot I feel. It takes as much time to make a controller with a function calling a service calling a repository and now you have one route exposed that does exactly what you need and not more. There exists some CRUD boilerplate where you have simple services that just do that. However even in CRUD there usually exists who can create it and what are the functional requirements belonging to this entity. Therefore it usually is much faster to do it by making a controller connect to a service and repository. For repository you can also read DAO layer. In essence the class that is responsible for doing actual work with the database.

I feel like making a post to sketch a simple and powerful overview that will set you up for success in making any web application.

Now again king, nay God, of the magical and automatic is Ruby with its Ruby On Rails framework. You only have to subclass a specific class and that is it. All will work afterwards.

As with all in life a good balance and moderation is required, so use not more than is necessary in terms of automagical generation of code.

Unless you want to be a magician instead of a software engineer. Or maybe be part of the crowd of people that call themselves Django programmers, or Symfony programmers or Spring developers or any other <insert framework> developer. Not that these people work on the core of these frameworks but they are like Dexter saying omelette du fromage being the solution to every problem you pose.

Then party on with the weird, uncontrollable and magical that is provided to us.

#devlife #code