Live data from Hacker News

PHP – The Right Way

phptherightway.com

171–180 of 349 posts

Re: PHP – The Right Way

#171

PHP is a language with various features that might make it attractive to certain people: • CGI-like execution model when used for the web, making resource leaks very difficult and encouraging scalable design • not only integers and floats, but also strings, lists and dictionaries as mutable value types (copy-on-write) — this is a big difference from JavaScript and Python • unusually for a dynamic “scripting” language…

* duct-tape style of arrays that Just Work(tm) as arrays, hash maps, etc. without having to use any boilerplate code.

It's the main reason why I still prefer PHP for quick&dirty scripting and data processing.

Re: PHP – The Right Way

#172
post #144
post #117

Earlier quoted context omitted.

Totally agree. This is beyond taste or preference. Yes you can build a great app in PHP. But so you can in Kotlin or Ruby or ... Yes some have a career by starting with PHP. But that does not make it a good language for beginners. Same can be said (and to me is verrrry true) fro JavaScript. Language design matters. It shapes how you think about code. Talk to people who've learned AND USED many languages including som…

For me, a "beginner friendly language" has these properties: * A welcoming, helping and open community. * Built-in guidance or enforcement away from The Wrong Way and towards The Right Way. E.g. by making the former hard to do and the latter easy. * Ecosystem of high-quality, properly designed libraries and sample code. I see this in e.g. Rust. But e.g. JavaScript or PHP fail on all my three points. As does my main l…

#2: Strict Programming lang's. I often seen frustrate new programmers, specially young new programmers making them want to give up on programming all together so I don't know if I would call that beginner friendly, I certainly would not call rust beginner friendly

I guess however we would need to define what a "beginner" target is, are we talking adults that want to learn programmed to change fields, or children wanting to inspire them to peruse programming as a career, or someone between the 2 groups

Re: PHP – The Right Way

#173

A language that changes the semantics of functions between minor versions has no "right way". "count()"less examples of crap. I have currently two weeks of code migration behind me because code running correctly on 7.0 fails on 7.3 -- while I see the reason for change was necessary I also see the hopelessness of rebuilding a flawed house with a fundament build on a pile of manure. And the good news given to me by a c…

I was curious about this rant since I'm maintaning a number of PHP projects and I haven't had any issues with "count". In the Changelog section of the "count" docs at https://www.php.net/manual/en/function.count.php we find: > 7.2.0 - count() will now yield a warning on invalid countable types passed to the value parameter. So in 7.2.0 they started raising a warning in cases where the application was doing a stupid t…

> In the next major version, they turned the warning into an error. Pretty understandable way to improve the language I would say.

Breaking changes (at runtime no less) are the worst way to improve any language. They should have created a new count method if they wanted to change behavior in a breaking way. Forcing millions of developers to comb through their code just because some designer doesn't like the way someone else does something is just narcissistic.

p.s. Semver isn't worth the shit paper its printed on, it can't even version itself and all it does is give shit developers shit excuses to impose their own naval gazing induced shitstorms on other developers.

Re: PHP – The Right Way

#174
post #134

Earlier quoted context omitted.

How do you feel about php7+ ? There were some serious changes.

I haven't worked with recent PHP versions, other than through WordPress, which, if I understand correctly, does PHP a big disservice. My last serious encounter was when I build and scaled a WordPress hosting company 5+ years ago. Which meant all my exposure to PHP was WordPress, which meant I wanted to avoid it as much as possible.

I guess laravel + recent ecosystem might be different.

Re: PHP – The Right Way

#175
post #89
post #74

Earlier quoted context omitted.

The fact that composer comes with an autoloader doesn't means that you have to autoload everything. You can manual include, define your own extra auto loader and use interfaces to quick swap for custom implementations. Like I said, +15 years. Composer is 9 years old. How do you think we handle this in our own Jurassic times?

You can manual include I don't think that will work with any code that came out in recent years. Because it all expects that its dependencies are automagically included via composer. In practice, every PHP based web application starts with Laravel or Symfony these days. So you are thrown into the composer workflow right away. And it would be a nightmare to fight it.

Web applications come in all shapes and sizes. If you have an application that just mediates data from database and exposes API to frontend then for couple of endpoints you don't even need router or any other packages, PHP has lots of stuff baked in. You just check if the request is GET/POST/PUT/DELETE/PATCH, work with data, output a header 'Content-Type: application/json', send the data and be done with it. Or output a html template with data or whatever. Or you can not use templates and mash it all together in PHP which already is a templating language. You can do it as simple or complicated as you need.

And then if you start needing additional functionality you can start adding packages with composer one by one. Of course it'd be stupid to build your own version of Symfony with it, but the beauty is that you can stop at any point you want if it covers your needs. This sort of thing would be much more hassle with say Java, without using any frameworks.

Re: PHP – The Right Way

#176
The best features of PHP are:

1. Core API of stateless functions. Compare this to the bootstrapping requirements of, say, Java or Python;

2. CGI-like resource management in that you tear down everything after a request. Many people get upset at, say, the "global" keyword but "global" here just means "request-scoped". There are no STW GC pauses and it's difficult (but not impossible) to leak resources;

3. Executing code for a request is single-threaded. This is almost always what you want; and

4. PHP's copy-on-write arrays (that are really hash maps) that maintain insertion order are so incredibly useful and is almost always what you want.

Crapping on PHP for things like function inconsistency (eg functions that use underscores vs those that don't, needle/haystack inconsistency) is a tired cliche and boring at this point. It really adds no value complaining about things that just don't matter and/or are historical.

My biggest grievance is that Hack (FB's fork) is basically better in almost every way. The collection types (vec, keyset, dict) are better (eg less weird coercion defaults). The type system is leaps and bounds ahead of anything PHP has. Nullability as part of the type system is amazing. It's a shame Hack didn't become the dominant dialect.

As for the book, I went through it and it's really solid. Good job to the authors and maintainers. It covers a lot of issues like register globals, sanitizing input, Unicode and so on. It also has links to more detailed information on any of these topics.

Re: PHP – The Right Way

#177
post #80
post #48

Earlier quoted context omitted.

What tools? What server language today except PHP (and its forks) is actually designed for the web and works as the web was intended?

What server language today except PHP (and its forks) is actually designed for the web and works as the web was intended? The implication of the question is that there's something designed into PHP that makes it better for working with web things. Why does the language need to be designed to work with the web? That part of any language can be filled out with a framework quite easily, and arguably that means it's much…

> That part of any language can be filled out with a framework quite easily

Consequence of that is that every other language is de facto is dominated by one framework provider that you almost always have to use. That in it self is the basis for a stagnant community.

Frameworks solves a general problem, you on the other hand solves a specific problem, sometimes those two are aligned, but many times they are not and then you are on your own.

> I don't think there's a good reason to design a language specifically for web projects

It definitely is because web has some unique properties and I think that one of the reason why we are unnecessarily shuffling JSON from backend to frontend where it is then transformed to HTML by async JavaScript (which gives a rather disjointed user experience), instead of sending a proper HTML document immediately from the server, because most backend languages suck when it comes to doing proper web.

Thus the industry creates these band aid solutions that constantly makes both the web and web development worse.

> language gets anything wrong that compromises the design of every project that uses it

Language design is overrated when it comes to producing customer value. What is important is how the general architecture works

  * memory model (shared, per request, etc)
  * request model (by the app or by the web server)
  * resource model (mapping URL to file)
  * compilation/build step
  * deployment 
  * hosting
  * tooling (IDEs, linters, testing, package manager, etc)
  * how to scale
  * available programmers
  * community
PHP wins by these metrics.

But if you want to have some fancy language feature to print out a proper HTML document, or what is more likely a JSON blob, go ahead, but it does not improve the end user experience at all.

Re: PHP – The Right Way

#178
post #176

The best features of PHP are: 1. Core API of stateless functions. Compare this to the bootstrapping requirements of, say, Java or Python; 2. CGI-like resource management in that you tear down everything after a request. Many people get upset at, say, the "global" keyword but "global" here just means "request-scoped". There are no STW GC pauses and it's difficult (but not impossible) to leak resources; 3. Executing co…

    3. Executing code for a request is single-threaded. This is almost always what you want;
And now with fibers you can launch "threads", which are not threads but work like them.

Re: PHP – The Right Way

#179

Earlier quoted context omitted.

What is your experience to make such ignorant statements?

I will just leave these here: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ https://software-gunslinger.tumblr.com/post/47131406821/php-...

That first article is a decade old.

Re: PHP – The Right Way

#180
post #117

Earlier quoted context omitted.

Totally agree. This is beyond taste or preference. Yes you can build a great app in PHP. But so you can in Kotlin or Ruby or ... Yes some have a career by starting with PHP. But that does not make it a good language for beginners. Same can be said (and to me is verrrry true) fro JavaScript. Language design matters. It shapes how you think about code. Talk to people who've learned AND USED many languages including som…

> Same can be said (and to me is verrrry true) fro JavaScript. Not if you use JS like Scheme: https://www.crockford.com/little.html In fact JS is much more pleasant to write than PHP, the main reason to move way from PHP after using it for over 10 years.

I guess it's a matter of preference because I find writing Javascript tedious, the forced async when not needed, or that for some reason Node doesn't give me a line and a description when I make a mistake, it just ... fails?
Post reply on HN