Programming for the web (Part 2)

I will keep on ranting and raving about the ugliness of web development. Ιt is so frustrating I really wonder how a normal programmer could stand such unnecessary complexity, absolutely offending to “The Art of Computer Programming”, so firmly established during the seventies. I really don’t know web designers’ opinion—they may get carried away with the artistic aspect of their job, but for programmers it is as bad as it could get.

In the previous part I confined myself to the client side of the web. Alas, there is more (and worse) to grumble about in the server side, where the web server and the database live (for now let’s ignore the intermediate application server). Mainstream language there is PHP.

In a smartass recursive fashion, PHP stands for “PHP Hypertext Preprocessor” which is wrong, as PHP is a plain hypertext (HTML) preprocessor producing no PHP code, as some functional languages (Lisp) do.

PHP is embedded in HTML using <!?php ... ?> tags, as if they couldn’t simply use <script type="text/php"> ... </script> or even <php> ... </php>. I dislike the superfluous echo/print vs document.write, but I respect DOM hierarchy.

PHP syntactically resembles C, but, strangely enough, PHP’s commands are case insensitive! But, wait, its variable names ARE case sensitive. Forget not, that JavaScript is case sensitive, whereas HTML is not. Perverts!

Logical operators can be written Pascal-like as and, or, or C-like as &&, ||. Even worse, some twisted mind decided to assign different priorities to && and and. Thankfully, xor has no C-like analogous, and ! has no Pascal-like analogous. I really wonder why did he miss introducing a times operator for lowering the priority of the * multiplication, and so forth. Unbelievable!

To break the tradition of mocking PHP, I value its use of the $ (although I would like to optionaly alias it with ). Seriously now, preceding variable names with a $ may perplex you, but it offers the opportunity of explicit dereferencing, once or twice. And doubly dereferencing is the proper syntax for passing parameters reference in function calls. That I like! However, if dereferencing were to be used consistently, assignment should be coded as num1 = $num1 + 3;

I could go on pinpointing ugliness in arrays, in foreach, but honestly PHP has overwhelmed me. If I were a translator program, I would get pimples chewing it and indigestion while post-processing it.

Programming for the web (Part 1)

If you thought client-server, distributed, asynchronous event-driven programming were hard, you haven’t seen anything yet. Enter web programming!

To develop a decent web page, you need to master a host of languages with disparate syntax, having to communicate with each other.

Client-side

HTML Case insensitive, consisting of lower-case tags, usually-but not always- coming in (nested) pairs, comments enclosed in <!-- --> (what perverted mind proposed it?). Should you have to read or perform maintenance on existing HTML code using some collapsible editor, you would certainly come across incomprehensible embedded CSS styles and [Java]scripts–not to mention depreciated HTML<5 tags and attributes. Thankfully, there is a multitude of tools to write and ‘debug’ it. Some inexplicable masochistic attitude leads us to prefer plain text editors, like NotePad++ and actually brag about it. Hopefully, they will offer color-coding and rudimentary command completion.

CSS Its use is based on a sound principle: disengage content and style. However, why did its syntax have to be so distant from HTML/XML/SGML? It improves its readability, but what an impedance mismatch with HTML! At least the comments are /* */ — an improvement over HTML’s.

JavaScript I disliked it from the moment I learnt the reason it took its name. Executable parts in a web page are useful – no objection. Why not use an existing programming language, whose syntax and semantics programmers already know? One that can be both interpreted in the browser and optionally compiled and sent over to the client as bytecode to protect the developer’s rights? (Yes, it could be Java with applets, or whatever.)  JavaScript’s sloppiness manifests itself in its type system: so ugly I can’t stand even describing it. But it gets much worse than this.

DOM In case you thought that learning three languages (one for markup, one for decoration and one for scripting) would suffice, you are naive. Relax, DOM is not a language, it is a (language independent) convention allowing the scripting language to access and manipulate HTML’s content and structure. It’s the mechanism that binds those two. Using DOM hierarchy you can write the JavaScript instruction which refers to HTML/CSS tags and attributes.

jQuery Writing event handlers in JavaScript is difficult (not that it has been easy in Java – only VB was straightforward in this task). Hence jQuery is the mainstream library for extending JavaScript. However, it distorts its syntax to the point that it becomes incomprehensible, unless you ‘understand’ jQuery. I really wonder: JavaScript was made for web page scripting in the first place. Why so obvious and necessary tasks should come in the aftermath?

Oh, by the way, since JavaScript+DOM+jQuery are programming beasts, you would expect robust, easy-to-use IDEs offering debugging facilities, such as step-by-step execution, variable watches, GUI design, right?

And you would take for grantedthey have the functionality of Visual programming languages have had since the 90s, such as developing interactive data-bound master-detail forms, right?

Wrong.