{"id":419,"date":"2012-12-12T23:14:39","date_gmt":"2012-12-12T23:14:39","guid":{"rendered":"http:\/\/www.muratyaman.co.uk\/wp\/?p=419"},"modified":"2020-04-01T12:09:10","modified_gmt":"2020-04-01T11:09:10","slug":"oop-is-under-attack","status":"publish","type":"post","link":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/2012\/12\/oop-is-under-attack\/","title":{"rendered":"OOP is under attack!"},"content":{"rendered":"<p>Yes!<\/p>\n<p>Main attacker is jQuery using ugly techniques such as <a href=\"http:\/\/en.wikipedia.org\/wiki\/Anonymous_function\">lambda\/anonymous functions<\/a>.<\/p>\n<p>* * *<\/p>\n<p>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.<\/p>\n<p>* * *<\/p>\n<p>jQuery is popular but like any other tool if you don&#8217;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:<\/p>\n<p>1. Bad example: especially when HTML, CSS and JavaScript codes are not in separate files.<\/p>\n<pre>\r\n$(function(){\r\n    $('#btnSubmit').click(function(event){\r\n        \/\/do something \r\n    });\r\n});\r\n<\/pre>\n<p>2. Good example:<\/p>\n<pre>\r\n\/\/prepare functions needed by giving meaningful names\r\n\r\n\/\/when submit button on main form is clicked\r\nfunction myApp_frmMain_btnSubmit_onClick(event) {\r\n    \/\/do something\r\n}\r\n\r\n\/\/initialize the application\r\nfunction myApp_start(){\r\n    \/\/bind event listeners to relevant objects\r\n    $('form#frmMain').find('button#btnSubmit').bind('click', myApp_frmMain_btnSubmit_onClick);\r\n}\r\n\r\n$(document).bind('ready', myApp_start);\r\n\r\n<\/pre>\n<p>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!<\/p>\n<p>Happy coding..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes! Main attacker is jQuery using ugly techniques such as lambda\/anonymous functions.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[94,26],"class_list":["post-419","post","type-post","status-publish","format-standard","hentry","category-technology","tag-jquery","tag-php"],"_links":{"self":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=419"}],"version-history":[{"count":5,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419\/revisions"}],"predecessor-version":[{"id":928,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/419\/revisions\/928"}],"wp:attachment":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}