OOP is under attack!

Yes!

Main attacker is jQuery using ugly techniques such as lambda/anonymous functions.

* * *

Unfortunately, programming for web is still very dirty! Even after 20 years: you can see a mess of HTML + CSS + JavaScript + (PHP or ASP or JSP and so on). Many programming languages have been influencing each other. Beware, the attacks on beloved PHP has increased since version 5 was released.

* * *

jQuery is popular but like any other tool if you don’t use it properly, you will end up with unreadable and unmaintainable code. One of the ways that can cause it is inline/lambda/anonymous functions. Check out the following pieces of code:

1. Bad example: especially when HTML, CSS and JavaScript codes are not in separate files.

$(function(){
    $('#btnSubmit').click(function(event){
        //do something 
    });
});

2. Good example:

//prepare functions needed by giving meaningful names

//when submit button on main form is clicked
function myApp_frmMain_btnSubmit_onClick(event) {
    //do something
}

//initialize the application
function myApp_start(){
    //bind event listeners to relevant objects
    $('form#frmMain').find('button#btnSubmit').bind('click', myApp_frmMain_btnSubmit_onClick);
}

$(document).bind('ready', myApp_start);

When you have so many pages, forms, objects, etc. you will see the jungle turning into a woodland with paths and even name plates on every tree!

Happy coding..

Leave a Reply