Live data from Hacker News

PHP – The Right Way

phptherightway.com

31–40 of 349 posts

Re: PHP – The Right Way

#31
post #20

My problem with PHP is that it solves the issue of code reuse the wrong way round. In other languages, you can import code like this: import mail as mailer The external code ("mail") does not have to make assumptions how it will be called when it is used. In PHP, it is the other way round. Every piece of code needs to try avoiding namespace conflicts by prefixing the code with something like this: namespace Illuminat…

Other languages? It's the same kind of namespacing that Java or C++ has.

Re: PHP – The Right Way

#32
post #26
post #23

Earlier quoted context omitted.

You can `use Illuminate\Mail as Mailer` if you want

That is not what I mean. It would not prevent a clash with another "Illuminate" namespace. The problem is that the developer of "Illuminate\Mail" had to introduce the "Illuminate" namespace and hope nobody else uses it. Additionally it makes the code more complex. Every file needs to carry this "namespace ...." line now.

You can hope all you want but you won't be able to submit any duplicated namespace to Packagist.

Re: PHP – The Right Way

#33
post #20

My problem with PHP is that it solves the issue of code reuse the wrong way round. In other languages, you can import code like this: import mail as mailer The external code ("mail") does not have to make assumptions how it will be called when it is used. In PHP, it is the other way round. Every piece of code needs to try avoiding namespace conflicts by prefixing the code with something like this: namespace Illuminat…

The way I see it is that you alias the import mail as mailer. You hope there are no other libraries called mail in your import path. PHP fixes that by requiring all libraries called mail to be dependent on their own namespace so that there will be no collisions. I think that neither do make assumptions on how the code is called when used, only one is preventing name collisions.

    You hope there are no other libraries
    called mail in your import path.
Let's take Python for example. With Python, I am in control of the import path.

I can put those two mail modules in:

    stuff/mail
    tools/mail
And then use them like this:

    from stuff import mail as mail1
    from tools import mail as mail2
I don't have to hope for anything.

Re: PHP – The Right Way

#36
post #26

Earlier quoted context omitted.

That is not what I mean. It would not prevent a clash with another "Illuminate" namespace. The problem is that the developer of "Illuminate\Mail" had to introduce the "Illuminate" namespace and hope nobody else uses it. Additionally it makes the code more complex. Every file needs to carry this "namespace ...." line now.

You can hope all you want but you won't be able to submit any duplicated namespace to Packagist.

That is another consequence I don't like about the quirky namespace approach. It collects more and more problems like a ball of dust that gets bigger and bigger.

The consequence you mention is that one depends more and more on tooling and services.

Re: PHP – The Right Way

#37
post #11

Earlier quoted context omitted.

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

Complicated frameworks means the “shared nothing architecture” is unusable and you have to use fcgi/fpm to get acceptable performances out of your website. At which point there’s little difference from .

"Acceptable" is different for different folks. I don't understand the general sentiment of either you have enterprise level performance or it's a fail. Not everyone is building next Facebook or Amazon and yet most developers think that they are and vastly overestimate their needs. Also most hosting provides already have fpm configured for you and if you need to do it yourself for your VPS then it's not complicated.

Re: PHP – The Right Way

#39
post #11
post #5

But what's the point? The beauty of perl scripts, and later php templates, was in their BASIC-like simplicity. They were not secure or structured in any way, but very accessible. Once you add these frameworks, you realize you could have started with Python or Java in the first place and get more mature infrastructure and better language along the way.

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.

Re: PHP – The Right Way

#40
post #26

Earlier quoted context omitted.

That is not what I mean. It would not prevent a clash with another "Illuminate" namespace. The problem is that the developer of "Illuminate\Mail" had to introduce the "Illuminate" namespace and hope nobody else uses it. Additionally it makes the code more complex. Every file needs to carry this "namespace ...." line now.

You can hope all you want but you won't be able to submit any duplicated namespace to Packagist.

Java solved this by using domain names as unique identifiers. I can use com.banffy and be sure only a complete a*hole would make a package in this space.
Post reply on HN