News for hackers. Stuff that matters.
Re:Modern PHP without a framework by megous on Saturday March 31, 2018 @08:47PM (#16726031)
Anyway, if this is how people use PHP these days, why not just use Java? I guess deployment is different (PHP is not compiled), but code/concepts seem pretty much the same at this point if you want to use this style of programming.
Re:Modern PHP without a framework by kilburn on Saturday March 31, 2018 @10:25PM (#16726370)
I'd say that web programming architecture has been converging between most languages. What's shown here is:

- Setup a library tracking system (composer, the autoload stuff)

- Setup basic Dependency Injection (using code in this case, but the same could be done through config files or annotations)

- Parse requests into a request class

- Setup a middleware chain, including a router, and dispatch a request through it

How is this different from flask/django (python), rails (ruby), or gin (golang)? I'd say the basic concepts are pretty much the same, except maybe the library handling part. In other words, I don't think there's enough "meat" in this example to appreciate actual relevant language differences.

Also, you can write "java-like, enterprisey" code (Symfony) that values explicitness over magic, or go the other way around following the "convention over configuration" mantra, and end up at Laravel that is much more Rails-like.

Finally, PHP is still has several advantages over java for many people out there:

- Every request starts from scratch, meaning it is impossible to accidentally provoke side-effects on other requests

- The package system (composer) is just a package management system, and hence MUCH simpler to understand than ant/maven/ivy, that are entire build systems that also want to control testing, deployment, and everything

- Development is faster-paced thanks to the lack of compilation. You can even easily setup an environment with auto-reloading and just "save updated code" -> "see result in less than a second".

- You can deploy your app to any of a horde of (cheap) hosting providers and let others deal with the ops side. The service may exist in java-land, but it certainly isn't as ubiquitous.

- PHP programmers are cheap (yes, cheaper than java-programmers).

Re:Modern PHP without a framework by wvenable on Saturday March 31, 2018 @09:47PM (#16726254)
...or C# or anything else. I programmed in PHP for many years and I agree. I mean there are good reasons for maybe not using Java but it's hard to imagine a good excuse to start PHP these days if you don't already know PHP.

On the other hand, things in PHP-land are improving at such a rapid pace (but without the churn of JavaScript) that if you are a PHP developer there isn't much reason to switch to something different but similar.

Re:Modern PHP without a framework by whamlastxmas on Sunday April 01, 2018 @12:22AM (#16726707)
Higher quality development jobs tend to use things other than PHP. I say this as a PHP developer. So there's at least that reason to get away from it.
Re:Modern PHP without a framework by RhodesianHunter on Sunday April 01, 2018 @09:32AM (#16728171)
Pretty much this. Switching from PHP to Java resulted in dramatic salary increases for me.
Re:Modern PHP without a framework by whamlastxmas on Sunday April 01, 2018 @03:58PM (#16730104)
What was that transition like for you? I'd like to get away from web development because I'm bored out of my mind with the front end aspect.
Re:Modern PHP without a framework by hrktb on Saturday March 31, 2018 @10:50PM (#16726428)
I think there is strong sense of “we’re not the old PHP anymore, we cut our hairs and wear suits with ties now” in the community.

In a lot of fronts it means mimicking Java, but I think it still is more flexible (and less reliable as the other side of the coin). It’s still very easy to drop down to “quick and dirty” code anywhere it’s needed, and it still benefits from a very low bootstrap cost to deal with single command/requests.

Re:Modern PHP without a framework by patricklouys on Sunday April 01, 2018 @06:20AM (#16727602)
PHP handles null better than Java. That's the one thing that kept me from switching to Java tbh.
Re:Modern PHP without a framework by linoge on Sunday April 01, 2018 @07:42AM (#16727787)
Implying that having null is a good idea at all.
Re:Modern PHP without a framework by gtsteve on Sunday April 01, 2018 @01:57PM (#16729558)
So how would you represent an absence of a value? In an enum that'd be easy, but there is a semantic difference between an empty string and a null string.

Or would you propose sending a boolean to indicate null as well as a string in a data type?

Re:Modern PHP without a framework by paulddraper on Sunday April 01, 2018 @03:43PM (#16730037)
See the Option/Maybe pattern, which uses sum types rather than unions or sentinel values.

https://www.lucidchart.com/techblog/2015/08/31/the-worst-mis...

Re:Modern PHP without a framework by patricklouys on Sunday April 01, 2018 @08:02AM (#16727832)
There is nothing wrong with using null in PHP...
Re:Modern PHP without a framework by RhodesianHunter on Sunday April 01, 2018 @09:33AM (#16728175)
Check out Kotlin.

String is not nullable String? Is nullable and the compiler/ide will force you to check for null when you use it.

Re:Modern PHP without a framework by tyingq on Saturday March 31, 2018 @08:50PM (#16726045)
Dynamic types, and less verbose.

Which, I agree, can be downsides as well.

Re:Modern PHP without a framework by megous on Saturday March 31, 2018 @09:25PM (#16726171)
Is it really less verbose for OOP programming than Java, if you're using type annotations, etc.?
Re:Modern PHP without a framework by tyingq on Saturday March 31, 2018 @09:33PM (#16726201)
Java is still burdened with a lot of this.that.this.that.whatever(something)

I don't know that I've ever encountered something like:

  RequestProcessorFactoryFactory.RequestProcessorFactory.getRequestProcessor(XmlRpcRequest)
In any other language. And that's not the most egregious example. It's quite common.
Re:Modern PHP without a framework by cutler on Sunday April 01, 2018 @01:21AM (#16726865)
Have a look at Zend's SDK. It's full of such nonsense. Symfony also tries very hard to look like Java, complete with verbose naming and files paths.
Re:Modern PHP without a framework by tyingq on Sunday April 01, 2018 @02:00AM (#16726979)
Maybe. I avoid stuff like that. See https://www.slimframework.com for example.
Re:Modern PHP without a framework by davidjnelson on Sunday April 01, 2018 @07:44PM (#16731207)
Seems more like a dig on inheritance and the resultant code than java as a language.
Re:Modern PHP without a framework by tyingq on Thursday April 05, 2018 @12:53AM (#16761877)
Well, two layers of factory classes, one calling the other, plus a big xml blob is pretty Java specific. I'm open to to common counter examples in some other language.

There's inheritance, and there's overindulgence.

Re:Modern PHP without a framework by davidjnelson on Saturday April 07, 2018 @01:57PM (#16781826)
Interface based polymorphism is pretty useful. Been thinking more functionally lately, and can’t remember needing it. Parametric polymorphism ( aka generics ) are still useful for the immutable state graph.