Why JavaScript and PHP rule the web

JavaScript and PHP are excellent languages. It took some time for me to really understand their power, and I hope to clarify my point of view in this post.

I believe that those languages shine and survive for being permissive and by adopting an Assumption Inversion Principle (AIP) — I’ve made up that name, you may suggest a better one in the comments. 🙂

What is AIP?

Raw JavaScript does not have any module definition structure, no statements as “import” or “include”. Symbols available for a piece of code written in JavaScript are pure assumptions. Those assumptions must be satisfied by other pieces of code, and not by itself. It is incredibly easy to change behaviours by loading new script files before the one to be changed by changing the link of its assumptions. This “change by adding” relates directly with the “O” in the SOLID principles.

Old PHP code goes the same way, your piece of code has some assumptions that some symbols are available and you simply use it. It is not the responsibility of your piece of code to link those symbols, you normally end up putting all of your script loading in something like a bootstrap system.

Import statements are bad, because they hardwire the symbols in your piece of code. Then if you need to change something, you actually need to get into the file and change it. In my opinion, “change by changing” is more prone to errors than “change by adding”. Also, “change by changing” does not scale as well as “change by adding”.

JavaScript and PHP code can also inspect its environment and adapt. So it’s possible to keep adding files that keep changing stuff depending on what has already changed or what is currently available for the script. This is pure gold in software development.

Think about WordPress plugins, you don’t need touch a single line of the core code, you just drop a new file and you can get a whole new experience out of your web site. Some plugins add features, other plugins only change behaviours. So, it either “add by adding” or “change by adding.” It’s a win-win situation, core code is hardly changed to add a feature, so you won’t get any bug from features you don’t care. For the features that you care, you get the plugins, drop them in and live with the bugs, if you happen to find a scary security bug, just disable the plugin.

I know a lot of people who criticize this way of developing and would prefer that WordPress be more object-oriented than it currently is. For what? Then we would need a plethora of new abstractions to achieve the same stuff. As code is a liability, the less code we need to achieve something, the better.

I love Haskell and its type system, it’s phenomenal. But it suffers from the same problem as other languages like Java and C# suffer. Modules are hard-wired with their dependencies and code can’t inspect its environment. I’m not saying that those languages are bad and should not be used. They surely has their own good use cases.

For a fast and distributed development effort as the web is, we simply can’t afford anything that is unforgiving or strict. The code needs to be open for changes from the outside (change by adding).

So, for the web, I don’t like new PHP code that uses modules and neither the usage of ES6. They may feel faster for developers starting out new products, but my bet is that in the long run they end up killing productivity and/or quality.

Think about it for the current project you are working on, how much could you change of it by only adding new files? What could you deliver by adding a new file: a whole new story, a feature, a bug fix or nothing?

All this permissive environment with all these code based on assumptions can turn into a real mess. That’s the reason those languages are hated by some developers, then those developers try to fix it by creating new stricter languages for the web, the end of the story is always the same: JavaScript/PHP triumphs over all. Why? Is it because of AIP?

JavaScript and PHP has some hidden properties that newcomers tend to ignore. Those hidden properties make them a perfect fit for the web. What do you think?

Am I just an old-school guy talking bullshit? Please, be kind. 🙂

Advertisements

9 thoughts on “Why JavaScript and PHP rule the web

  1. I think that there’s another reason such languages rule the web. Both are easy to understand, easy to modify (as you already said) and you easily see the results of adding something. This is what make people productive on those languages also increase their popularity on the web with beginners learning and getting things done. Note that both languages doesn’t have a popular debug system!

    Liked by 1 person

    1. PHP has had Xdebug for a LONG time now, and it is very popular and excellent at what it does. JavaScript has a plethora of tools at it’s disposal, and browsers are getting better and better at providing debugging tools. I’m not sure I understand what you mean.

      Like

      1. You are right about availability of debug systems for both languages. I didn’t mean that it is something new or that it is not good enough. The word “popular” was not carefully chosen also. But what I was trying to express is that I see people programming those languages without debug for quite sometime. And they create nice stuff before find debug on browser and tools like xdebug. But this a narrow view of language newcomers that I have (which isn’t all that big).

        Like

  2. JavaScript is pretty much the only thing of its kind that can be used in the web, unless you go the plugin path with Flash, Java or what else (which don’t quite integrate with the web page). So there’s not much to say about it.

    As for PHP, it’s mostly because it’s easy. “Change by adding”, as you say, is very easy. But is the same as the Global Scope, which is pretty much frowned upon. In PHP, you can assume some stuff will be there and new code can just change those stuff that are there. And that’s global scope, which is evil.

    Why is global scope evil? Because when you assume something is there, it might not actually be or it is there but in a way you wouldn’t expect. A WordPress plugin could completely break the blog view. And that might be what you want but can also be unintended behavior.

    Another problem with global scope is that it’s hard to test, because anything might change the stuff you assume it’ll be there, so it might be different each time you test. So, if your WordPress blog is broken, could luck finding one in 500 files that caused the break.

    However, the main reason that makes PHP popular is because it’s cheap. You can find a myriad of free hosts that support PHP and even with some MySQL database. The free hosting for Ruby or Node.js are much more scarce (not to mention that they’re usually based on resource usage, rather than a simple space + traffic per month).

    PHP is also a legacy standard still used by major sites (like Facebook) and will be here for a while to maintain those (I’m not really aware about the PHP 7 changes, so I won’t comment on that). And so is JavaScript, though there never were a substitute language but versions of itself, as it’s much harder to make every client switch to something different than it is to use a different side-server system, which is transparent for end-users.

    Imports and includes might make things break a little more often, but they’re are very visible and easily spotted. Much better than a global break, which could be anywhere in your code base.

    Like

  3. I Honestly think they are so popular because at entry-level it’s incredibly easy to express yourself in PHP (past entry-level it’s hard to express your exact intent without side-effects in any language, so it’s no worse than any other languages in that respect).

    I’m looking forward to more PHP and non mathematician inspired languages; but as I language hop a fair bit, I do like to tell myself that means I am keeping an open-mind when I come back to PHP (or JS), and sit by the fire whittling the days away

    Like

  4. Complete and utter bullshit.

    I’m a Web Developer myself and this was the most ridiculous thing I’ve read my entire life.

    If you knew a damn about Scripting Languages you’d know, that for JS to be the language it is, it’s ALREADY bundled with everything you need. That’s why you don’t need anything to be “imported” or whatever you deem a bad thing.

    Isn’t it the same thing when defining a script before your main one to “import” something ? Or do you like fiddling around minified JS code?

    The moment you actually become a real developer you appreciate how good and actually how much more flexible the other languages are and how incomparable they are to JS. JS is for the web realm – there aren’t better alternatives but it has it’s flaws. Everything else is just plain better for everything else.

    I won’t even comment on PHP because it should honestly die off and to the previous guy that said it’s an easy language for a beginner I am not sure what kind of PHP he was using.

    They “rule” the web because they are fast for what they’re meant for, and with the exception of PHP are easy to program with.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s