Communication between controllers and views via symbol messages

Sometimes a new, simple idea allows us to see the world better and understand the limitations that previously we did not even know we have. We are all accustomed to code like this:

The problem is that sometimes we want to format the flash message. Maybe part of the text needs to be in bold. Maybe we want to display it entirely different. In such case we just need to remind ourselves that there is no need to generate and put the message into flash object in the controller. Maybe we should not generate such informational messages in controllers at all. If that action was performed by mobile device you probably would not generate the message that phone is supposed to display to the user. That does not feel right, does it? Instead, you would provide enough information so that the device can provide a meaningful message. Also, it would be the job of the phone to display it in a proper language. So, why don't we try the same approach with browsers.

And here is the final effect:

Despite the fact the almost every example in the web uses the first approach, we should remember the we are not limited to that. We can do better. The solution is very simple, yet it is so easy to forget about it. We are not limited to displaying sentences generated by controllers. We can even make such messages a state of the art. Do you know any good examples of that?

Popularne posty z tego bloga

Ruby vs Kotlin: Custom Comparable classes