by cntainer · 4y ago · 0 comments
In the meantime I switched to other stacks but I've been keeping a distant eye on how PHP was evolving and I still am involved with PHP projects to a certain degree, though rarely at code level.
I really appreciate the effort put into fixing most of the things I hated about the language, though at times it felt like the language and some of the frameworks were trying too hard to copy the Java ecosystem, all while Java itself was starting to modernize.
I'm curious what is the value proposition of the latest PHP version(s). Why would I choose PHP when starting a greenfield project? I know one of the easiest answers is that there's a huge amount of developers worldwide that know PHP, but apart from this obvious reason is there anything else that would make someone choose PHP ahead of other stacks?
Otherwise, I think differences in syntax etc. are rather subjective and everyone has their preferences. For example, I really like PHP "arrays" because it removes cognitive load of choosing between different data structures. When writing business rules 90% of time I don't really care about optimization or memory, but about readability and communication.
Overall, PHP is rather dumb language and I love it for being dumb.
Python package management currently is a nightmare, but projects like Poetry seem on a good track to make it better. JavaScript is better than Python at package management, but it has issues with many small packages maintained by random people. Java ecosystem also seems quite a lot more complex, especially when you compare Composer and Maven. Compilation aspect also changes the way you work.
I have no experience with Ruby, C#, .NET etc.
Parts of the community seem to want to go over that limitation so things like Swoole and Roadrunner were developed. I guess it's interesting to have both options available even though much of the ecosystem won't readily function in both contexts.
While the ecosystem seems a bit weaker that what I would expect considering the number of developers (comparing to Java, Ruby, Python) I don't have a strong opinion on package management. I feel like all major platforms have gotten into pretty good shape on this front. Like you mentioned, if I start a new Python project I can just choose Poetry and avoid most of the drama.
1) CGI and similar share-nothing architecture like PHP, unaware of process model, threaded or processes, everything starts from zero. Any state needs to be handle outside of the runtime. Stateless thus a good conceptual fit for stateless protocol like REST.
2) Threaded frameworks like Java Spring or Python frameworks, the framework forks for you, but the architecture is leaky, you can share data between threads intentionally or unintentionally. Benefits from things like connection pools to be used between requests. Can be easier when need to handle a single mutex of a resource compared to 1), e.g only one job instance should run simultaneously. However most of the time you write code as if it was share-nothing, because fewer complications (no need to worry about locks, concurrent collections etc) and reduces risks of introducing any hard to debug and expensive mutex.
3) Single threaded event driven architecture, no need to worry about race condition thus you can keep global state within the application between requests, no locks or anything but with a big caveat, as soon as you start running your application as multiprocess, like cluster, that global state can no longer be used for data sharing, only for caches like database connection, thus the best way of writing application code is to write it as share nothing to avoid any state related bugs.
BUT single threaded event driven architecture also has a huge drawback, you can essentially freeze the entire application by programmer error or introduce hard to detect mini freezes because it is single threaded.
Proposition: the larger the single threaded event driven application becomes the higher the chance of freezing your application.
I think this is why nodejs shepherds you to write micro services and conversely PHP shepherds you to build monoliths because you don't care about the process model when writing PHP.
Conclusion: You should almost always design your code as share nothing. The only benefit of picking either of 1), 2) or 3) is for performance considerations outside of team expertise and community. 2) and 3) can have better performance than 1) due things like to connection pooling but 3) is bad choice in respect to longlivity because of the monolith mismatch. 1) is easier to reason about because the process model is irrelevant thus increasing longlivity.
I think more and more people have started to realise that typed languages make better, more reliable software. The incremental additions to PHP's type system are just a move towards this, I think and can be seen in other languages such as Typescript.
I'm just not a fan of dynamically typed languages anymore, even for small scripts.
> Why would I choose PHP when starting a greenfield project?
I think it depends on your greenfield project, but there are many domains where problems are just solved related to e-commerce or shuffling around content online.
To this point, PHP benefits just from the fact that it has been around for so long, and will continue to be supported far into the future.
Many PHP frameworks like Symfony have LTS releases that will ensure software is supported years into the future, with strong support from agencies.
Sure— thinking you’re going to save time writing more complex applications by avoiding boilerplate is flatly wrong. However, if boilerplate would be a double-digit percentage of your code, you probably will save time avoiding it because any unlikely dynamic typing issues will be easily resolved. But if it’s small enough to be inconsequential and you’re in the typed-language zone, why not use your typed language, anyway?
Avoid dogma and use the right tool for the job, I say.
Well, I originally started programming only using dynamic types.
Then I moved to typed languages, and I could avoid whole categories of errors. I don't see it as dogma, I think typed languages are just qualitatively better at creating software. I also think this is starting to become industry experience, as efforts like Typescript, and the incremental additions to PHP's type-system show.
How about for the type of task PHP is often used for? A nearly default CRUD web app w/loads of fields and tables? Rapid prototyping? How about a bunch of simple, standalone interface interactions in JS? The extra grammar won't provide much architectural or conceptual clarity in those super common coding tasks because they're already dead simple, or in the case of the rapid prototype, don't need to be durable. Most data transformation— e.g. from the database into hashes— is taken care of by worn-smooth libraries that won't likely cock things up. For these tasks, front-loading complexity for little subsequent benefit is a questionable choice. Maybe you're so used to working with types that you're just as fast,time isn't a factor? Great. If you're not, or another developer you're working with isn't, and time is tight, it's probably a bad choice.
What many of these systems are starting to offer is the option of adding type hinting which is exactly what they should be doing. Python's type hints have been great in a new nontrivial project I'm putting together with multiple developers. If I had to use them for every bit of disposable utility script I write and every little prototype proof-of-concept I stand up then I'd be much less productive.
I reckon skipping situation-specific cost/benefit analysis before asserting something is always better is definitely dogma. ¯\_(ツ)_/¯
Every time I see a regular Map with nested maps, I get a little annoyed.
I've worked across a variety of different companies and a consistent theme is the existence of "php developers" in these companies, and the bad quality software they produce. I'm currently working at a company (founded within the last 5 years) and their php codebase is AWFUL (no structure, 1k+ LOC methods, no tests, no ci, no documentation etc.)[1].
The problem is not php, it's that a lot of PHP developers are doing the same thing they did 10 years ago, despite the industry having moved on. As a Software Engineer, I think there's a very valid case for php over Ruby or Python or Node, however as a CTO or a team lead, I'd really, really struggle to justify it, which pains me to say. If you're trying to hire php developers, you'll be hiring a lot of people who haven't changed how they work since the late 2000s. I'd rather hire code school graduates to write Ruby than a php developer with a decade of experience.
[1] People can write bad code anywhere, but pre-historic php is especially terrible. A company with bad golang is an order of magnitude more penetrable than a company with bad php.
I think the main cause is the low barrier for entry. It's great that anyone can get started quickly and be successful but it also means that the resulting mess can be at a level that you rarely see in other stacks where the barrier for entry is a bit higher.
I can clearly see that the PHP ecosystem is there (mature libraries for mocks, tests, etc) but like you said, there are people that just don't care. The language and ecosystem evolved faster than a big chunk of the developer community and I don't think everybody will catch-up anytime soon, as old PHP code bases can still generate a nice revenue doing maintenance.
LAMP stacks are super ubiquitous, open source, cross-platform, and in many cases to deploy your app you don't need to configure anything, add any modules or dependencies... just copy your files in place. A small project (e.g. contact form with a CAPTCHA) could be just a small file named whatever you want, which you can place anywhere in the public directory, and it'll work.
If you don't want to maintain the server you can get a managed VPS and things will probably run and continue to run for years without any intervention on your part, even through software updates.
... The exception is that PHP breaks backwards compatibility often, but even then most hosting services let you choose between different PHP versions which they'll maintain for a while. Installing older versions from package managers is very easy as well.
That said, I don't think this is a strong reason to use PHP in most projects. I do think it could be one of the strongest ones to justify its use in some specific projects.
In my case if the hosting provider doesn't have something like DigitalOcean's droplets I'll still rely on docker compose instead of the default stack deployed on the system whatever stack I'm choosing. But yeah that's raising the bar too much for most people especially for a couple of scripts or pages.
For me, the answer is Laravel.
Ease? I have not professionally used php since php4, and last set it up in php5.x.
Last night I wanted to send some data to an http server, a small payload of json, that would be saved into a DB and queried later. Took me all of 5m to realise that my php test script that receives the file can be copied over to my el-cheapo webhost account unchanged and work fine.
No extra "database" modules to download, then install on a host I've no shell access to, sending email worked out the box, etc.
Php reduces the friction. I remember trying to use Python for something (with Django, I think) in 2011 and it was absolute hell to get deployed onto my webhost; fingers burned, I won't touch it again.
Php is basically batteries included, and works everywhere. I'm sure the Python, Node or Ruby alternatives are elegant, and neat, etc ... but if I wanted that, it means the project is expected to be large-ish, and for anything more than a few thousand lines of code I'm switching to a compiled language.
The value proposition *is* the ecosystem. Do I prefer coding Python to PHP? Sure (although it's not night and day difference by any stretch of imagination). Do I prefer Laravel or Django? Laravel. Do I prefer WordPress or ....? Actually, there's no equivalent, it's the one ton gorilla in that space.
When it comes to the 'classical' web (but also fun new toys like Laravel Livewire), there's very little that can compete with PHP as far as I'm concerned and the IMHO minor warts are certainly not worth losing the ecosystem for.
If you want to build something once and get passive income out of it for the better part of a decade, PHP has your back. Pinboard is a prime example of this business model.
If you're a fast-moving startup who will replace your entire codebase every six months, you might be better served by JS.
> If you're a fast-moving startup who will replace your entire codebase every six months, you might be better served by JS.
Noooooo... :)
If it's a lifestyle business or hobby project, it usually costs less to host a PHP app somewhere than to find a place where you can get decent performance out of the JVM. Even a small droplet can be a lot of money and effort for some people in some parts of the world. I often see kids pick up PHP for this reason alone. Then they stick with what they know.
Because you don't know better. If all you have is a hammer, everything looks like a nail.
Ruby + Rails is miles ahead of PHP + Laravel. If you want more static typing (which I currently believe is a good thing) I really like Kotlin (+ KTor or + Javalin). If you are okay without OO and like static typing Haskell + IHP is pretty complete. If you are okay with learning about low-level stuff, Rust + Actix is really nice.
All of this may require learning new things, and coming from PHP that's a good thing. PHP and JavaScript are not languages that help you become a better programmer. They are messy and lack important features (sum-types).
Wtf are you saying Willis.. but i guess it's a matter of preference, also consider that in PHP you can also use symfony which is my preference, but regardless of everything, you either come here with a list of things that make ruby on rails miles ahead or people is just going to classify your ideas as worthless
Is that a metaquote or something? Mr. Belvedere doing an impression of "the children's favorite programme?"
Things are improving as more and more "batteries included" projects are launched, and it's better today than it was a year ago, so I'm happy about the positive change and I am optimistic about the future, but right now I can't begin to imagine labelling TypeScript as even close to being one of the "best" languages, because delivering software with it is a nightmare. TypeScript is great to write but hell to turn into JavaScript.
One can do some really beautiful programming in both modern JavaScript and modern PHP. Both these languages can and have helped millions of programmers become better programmers. Today's JavaScript and PHP are no longer the hacked up languages they once were.