MVC client side frameworks, an option to avoid spaghetti code

I was reading about Discourse, which is a great Open source project, and I found this post:

The post is from Robin Ward’s blog and it gives some hints about when and why we should use client-side MVC frameworks. it is important to realize when our JS seems spaghetti code and it is as easy to debug and predict as assembler code.

Sadly, it is too common to find JS, which is really hard to maintain and debug. In my case I just had to take a look at my older projects.

If you have seen code of some WordPress plugins, look carefully, you can find examples in widely used plugins. Some of them have JS scripts, which are really fragile and depend of DOM structure.

Don’t get me wrong, WordPress is really powerfull but it doesn’t mean it is perfect, thats why you can find this kind of comments on some websites or forums:

Screen Shot 2014-04-22 at 11.39.50 PM

Take a look at the discussion:

I know it is a long process to adopt this kind of practices in robust application like wordpress or Moodle. At least Moodle is doing a great job using YUI, take a look at Moodle YUI modules.

I am just starting to put in practice this advices, indeed I am improving the JS of my Moodle theme called Archaius, because the JS was growing too much and it was time to use patterns and adopt some Moodle practices to improve maintainability. I don’t want to hear something like this about my work:

“Congratulations, your code is now spaghetti, your data is strewn out in the DOM and your logic is tied to a particular layout of HTML elements.” Robin Ward


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *