Tuesday, 22 May 2018

PHP allows for the design of X

Fig 1. A thing I said
Starting complicated twitter conversations should be avoided, I know this, and yet blurted this out on twitter recently ...

This was met with a flurry of responses and I couldn't reasonably reply in tweet form. I'm going to respond to some of those tweets (indirectly) and further explain my original tweet.

PHP is not always the right tool for the job

First and foremost, I was misunderstood by some people; They thought I was saying you should use PHP for everything. Obviously, that would be an untenable position, which I do not assume.

Give a task to a polyglot and they won't spend time enumerating for possible exclusion all of the languages they know. It doesn't work like that, you don't start thinking about the most unsuitable language for a task and somehow work your way to a suitable language. Choosing a suitable language is a thing you want to call an instinct, but it isn't an instinct, it's guided by an understanding of the task, and prior knowledge of domain support among your chosen poisons ... I mean languages.

There are totally legitimate reasons to choose other languages over PHP, even in the domain where PHP excels - on the web. But it doesn't have very much to do with PHP, and has everything to do with the chosen language and the task. You likely weren't thinking about PHP when you made the decision.

PHP is not a templating language

Whenever someone says "but PHP was designed as a templating language", I almost want to cry.

Who actually cares what PHP was in the year 1997, the number of lines of code from that software left in PHP is minuscule, if there are any present at all.

In the year 2018, we don't even care what PHP 5 was, we don't care about it's shortcomings, because we should not and do not use it.

Today, when we talk about PHP, we are talking about PHP 7 ... here are some actual facts (the things you can't have your own opinions on):
  • PHP 7 is fast
  • PHP 7 is a general purpose scripting language
I'm a C programmer, I spend most of my time writing C, and spend some time at levels below that playing with machine code, JIT compilers and so on. When I say PHP 7 is fast, I mean to say that as a C programmer, it's difficult to write code (of equivalent complexity) as efficient as the code Zend generates in the vast majority of cases. It's also as near as makes no difference impossible to JIT Zend opcodes into machine code and have them be more efficient, the facts of the matter are that the assembly that is generated when Zend is compiled is as efficient as any assembly you could hand craft inline, or generate just in time (that's not a guess, I've personally tried  both hand crafting inline asm and JIT compilation of ze3 opcodes).

Obviously PHP is stuck with one data structure, but it's not just a dumb HashTable in PHP 7 anymore, it's smart and will perform optimally most of the time. The structure of a HashTable and the shortcomings of those structures are less important when our applications are heavily object orientated. Reading/writing/interacting with properties on PHP 7 objects is almost entirely unaffected by those things; Given a warm runtime cache, reading a property from an object consists a relative load (a very simple machine code instruction), there is no ht lookups involved. This is also true of HashTables in some cases (they can behave like C arrays).

PHP allows for the design of X

When a project like AMP shows up on the scene, you can't say "PHP wasn't designed for asynchronous execution", it's a nonsensical statement since PHP is a general purpose language, given that support has emerged in this new domain, as a matter of fact PHP does support it, and not accidentally.

Is the support for this new domain as mature as another language in your arsenal ? I don't know what languages you have, whatever this is not a reason to assume that the people working on AMP, or X, are wasting their time because of some imaginary (and it is mostly imaginary) shortcoming in PHP.

Reddit was recently discussing a GUI extension I wrote; It's very frustrating to hear people who don't really know what PHP is capable of decrying it as a waste of time, or no better than software from 10 years ago.

Almost every extension I write gets the same sort of response: "Just because you can, doesn't mean you should". What they are communicating is "It doesn't matter if you can, you shouldn't", which is somewhere between silly, and harmful.

It really does matter if you can.

When support emerges for a new problem domain, let's be pragmatic and observe that expanding the horizons of PHP in any direction is good for the community that relies on PHP (and maybe PHP alone) to make a living. Let's not rush to take new solutions to production tomorrow, but let's not dismiss anything out of hand because of some imaginary short coming in PHP. 

Ideally, let's find time to learn about the new solution to see if it's useful to us, perhaps try to use it in our prototypes and drafts, and in so doing improve it.

PHP 7, as a matter of fact, is internally designed to bend to the programmers will ...

When support emerges for a new domain, take that as proof that PHP allowed for the design of X.


  1. Thank you for writing this! It gave me some confidence that I'm not learning a shitty language.

  2. Thank you. The whole PHP hate will slowly decay as more and more realize that in fact, they do not know PHP, at all, thus they cannot judge and once they get to know the current PHP, coding it the right way, they wont bark anymore.

  3. Have you seen the https://github.com/gabrielrcouto/php-gui

  4. But but but ... some random argument I copied and pasted from a post that's over 10 years ago ... you didn't cover all "my" points ... especially the ones with the typos and poor grammar!!!!

  5. Okay, let's nail using microscope, we don't need any hammer. I think that good engineer would choose appropriate tool for the task. It's senseless to use PHP for realtime video compression, or 3D (or even complex 2D) rendering. There is a lot of different tasks that can be solved easily in different languages, but not in PHP.

    The other thing is ecosystem, what kind of libraries are available for different areas. PHP has several libraries for building GUI, it's great. But if I need to develop complex GUI for enterprise application, I'd never choose PHP for that. It just cannot be compared to GUI libraries available for Java, or C# (or even Python).

    Software developer needs to clearly know possibilities and limitations of the tool he/she uses, library or programming language - all has it's costs and we should consider carefully all pros and cons.

  6. As being a lead developer, it is not about the language you use but the what can you make the language do. I cringe hearing 'language does not do X' from a developer rather I like to hear from a developer I can 'make a language do X' and is it successful in your current requirements goal. Developers who say 'it cannot do X' limit their selves and their ability, instead pushing their limits and looking beyond the skills.

  7. Cool Stuff. Kanhasoft is the top-notch PHP web development company India providing offshore services. Get affordable and reliable web solutions with us.

  8. Your blog very helpful for job seekers. Thank you for hard working. Also, it’s help more. new government job circular

  9. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! every door direct mail® postcards for cheap

  10. Well said. Although I can't think of a situation where I would use PHP as a UI language -- that I CAN use it for such a purpose is a testament to PHP's power and flexibility.

  11. Thank you shares this article. I found this article more information. new government job circular

  12. The developers can use native functions to keep the PHP code readable and clean. But they must remember that the execution speed of individual PHP functions differs. Also, certain PHP functions consume additional resources than others.https://medijo.lt/plakatai/

  13. This is a very amazing post for cheap web hosting services. in this post, you have provided all the basic information regarding.

    website builder for reseller

  14. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    private label website builder

  15. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    white label website builder

  16. Very Helpful and informative blog! Keep sharing such blogsSoftware Development Company in India

  17. Thanks a lot for writing this up! Hats off.
    I believe that whining about the imaginary short comings of Php have become the attitude of few people just to ignore the true capabilities of Php and for no reason. Mostly we don't really know if it's a limitation in Php or not.