Live data from Hacker News

PHP – The Right Way

phptherightway.com

181–190 of 349 posts

Re: PHP – The Right Way

#181
post #11

Earlier quoted context omitted.

PHP share-nothing architecture is awesome. It's amazingly simple and it scales to arbitrary size.

PHP did not invent CGI and the whole selling point of mod_php was "share-something" architecture.

Obviously it's share something e.g. session state and database state.

But architecture of PHP applications is simple and it works. I like simple.

Re: PHP – The Right Way

#182
post #113

Earlier quoted context omitted.

I don't know that many nicer tools than Laravel, to be fair. Especially Laravel + Lighthouse, which is an extraordinarily neat GraphQL layer considering the huge deployability you get with PHP. PHP is progressing towards a nicer language in a way that JavaScript, IMO, is not. And taking tens of millions of programmers with it.

You should also have a look to api-platform ( https://api-platform.com/ ), it's based on Symfony and you can create Rest or GraphQL APIs with ease.

Or don't, if you have a business data model that is more complex than a hello world.

Re: PHP – The Right Way

#183

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…

I don't think fibers are that great. There's no indication that a function call will create a fiber and do things[1] that might screw with your current state. When you know fibers are around, you need to code more defensively.

[1]: https://withinboredom.info/blog/2022/01/04/thoughts-on-php-f...

Re: PHP – The Right Way

#184
post #120

Earlier quoted context omitted.

> And several libraries and frameworks built around it are flourishing. Yes. > PHP is actually a really decent option these days. I beg to differ. What comparative options do you have experience with to base your claim on?

I'm not the OP, but I have plenty of comparative experience working with Python and JS on the backend (node) and I find PHP to be a very decent option compared to those two. PHP has an amazing infrastructure of third-party libraries/packages around it, particularly if you're using PHP for web development. In comparison, Python simply does not have the same quality of framework for web like Symfony or Laravel. Django…

So compared to JS and $DYNAMICALLY_TYPED_LANG, PHP is "decent these days".

These languages all suffer from very similar problems.

Compare to C#/MVC.net, Kotlin/whatever, Go, Rust to get something noteworthy.

Re: PHP – The Right Way

#185
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.

Aren’t fibers designed from the perspective of usage in underlying libraries, rather than something for everyday end users in the fashion of async/await?

Re: PHP – The Right Way

#186
post #120

Earlier quoted context omitted.

> And several libraries and frameworks built around it are flourishing. Yes. > PHP is actually a really decent option these days. I beg to differ. What comparative options do you have experience with to base your claim on?

The main comparisons I have are building sites with Ruby/Rails and doing JS front ends attached to REST APIs. All three types of project have their own pros and cons.

The fair comparison: PHP/Laravel to Ruby/Rails...

How is PHP/Laravel better? I'm of the opinion it loses hard in every aspect.

Re: PHP – The Right Way

#187
post #172
post #144

Earlier quoted context omitted.

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 want…

If you want to learn programming, knowing how to use type systems is valuable skill from day one.

For children see this (very different objectives indeed):

https://www.rollapp.com/app/kturtle

Re: PHP – The Right Way

#188

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…

> not only integers and floats, but also strings, lists and dictionaries as mutable value types (copy-on-write) Lists and dictionaries are also mutable in Python. Strings are not. With CoW, are your referring to garbage collection? (value that is no longer assigned to a name will eventually be purged). That would be independent of (im)mutability, so I'm not sure I understand.

With copy-on-write:

    $a = ['a'];
    $b = $a;
$a and $b both point to the exact same bit of memory. Thus passing an array between functions is zero-cost.

When you do:

    $b[] = 'b'; // append 'b'
a new array is allocated, the old data copied to it, and 'b' appended to it (basically, but IIRC, it is a bit more optimized than that).

Re: PHP – The Right Way

#189

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-...

Ah I see, you partake in cargo cult development. Thank you for elaborating and have a good day.

Re: PHP – The Right Way

#190
post #67

Earlier quoted context omitted.

Well... I wouldn't recommend JavaScript. TypeScript is much nicer and removes a lot of the JS pitfalls.

Typescripts has an insanely complicated type system (at least for the low level of type safety you get), is dog slow to compile and has cryptic error messages. With PHP you can have your cake and eat it too. Have the productivity of a dynamic language, no compile step and a really smooth gradual typing experience with great tooling and linting. I really can't think of anything other that familiarity why one would pre…

Use JS + JSDoc comments with types + TypeScript to check types. No compilation step, but code is type safe.
Post reply on HN