News for hackers. Stuff that matters.
Re:Taking PHP Seriously by SCdF on Monday January 13, 2014 @08:04PM (#7054709)
At my job I maintain some PHP that we are slowly removing (and replacing with Scala for the backend and Angular for the frontend). My total experience with PHP prior was writing a tiny wordpress plugin a decade ago that added some anti-spam stuff to comments.

And you know, PHP, it's not so bad. It gets the job done, it deploys instantly (the rest of our code is mostly Scala. Oh. My. God. Just. Build. Already…). It can be pretty haphazard, you can do some funky stuff with it (the abilty to pass by reference on integers and other 'primitives' caught me by surprise) and I wouldn't pick it for new code, but it's certainly not the steaming heap of evil that people make it out to be.

Maybe our code is just awesome, idk.

Re:Taking PHP Seriously by Aqueous on Tuesday January 14, 2014 @12:57AM (#7055618)
I too have had to maintain PHP code that I've since replaced with Scala, and our Scala production cycle has gotten quite fast indeed. The thing about Scala is: the compiler is the worst, slowest part of the language by far, and admittedly frustrating. But I've also found it's not a deal-breaker. Particularly, using it with the Play framework gives you request-triggered recompiling, so you can go through the change code-browser reload-change code process just like you do with PHP. And the iteration happens just slightly slower than with PHP. But you get the benefits of static typing which guarantees program correctness unlike PHP. The lack of this guarantee means PHP is actually not as productive as people say. If something compiles at all in Scala it tends to work the way you intended, and you don't have to go through some user flow or interaction in order to find whether or not the change you made works. Obviously, sometimes you do, esp. if you change front-end js. But most of the time I have found I don't, provided that the program compiles.

So I'm not buying this argument from Adams that the PHP iteration is necessasrily faster. It definitely used to be that way, but I think other languages have caught up.

We are churning out complete web services two or three at a time in 6 person shop, every month or so. We weren't as productive in PHP. Maybe that's just us getting better as programmers, but I also think it has a little to do with the bugs and other things caused by the lack of static typing and various language quirks.

Plus, Scala has access to the entire Java ecosystem, which is arguably as or more mature than the PHP ecosystem. So I don't spend a lot of time reinventing the wheel, as the Facebook engineers have done with their custom framework.

Re:Taking PHP Seriously by virtualwhys on Tuesday January 14, 2014 @05:28AM (#7056290)
I would say that PHP, or any dynamic language for that matter, is going to result in faster iterations just by virtue of never having to wait for the compiler to catch up.

Even with incremental compilation and SBT subprojects (i.e. modules to keep recompiled code to a minimum) there's a compile time hit on _every_ source file change; that adds up over the lifetime of a project.

You guys may be more productive now than you were with PHP, but that's likely due more to the awesome libraries you're using than Scala development being inherently faster than PHP.

Re:Taking PHP Seriously by Aqueous on Tuesday January 14, 2014 @08:38AM (#7056920)
Right. But my argument is that the compile hit as at least mostly compensated for by the guarantee of program correctness, which PHP doesn't have. Forcing you to go through a user interaction to see if your change broke anything, which takes time.
Re:Taking PHP Seriously by virtualwhys on Tuesday January 14, 2014 @10:58AM (#7057669)
Goes both ways. In PHP you can take an arbitrarily complex object graph and marshall it to JSON with a few keystrokes; in Scala, unless you're working with MongoDB or other native JSON speaking backeend, you've got to go through a laborious manual process to do the same...for each complex object.

That's partly why Dynamic came about in Scala, to deal with the case where, shit, you've already got a type safe represention of an object in Scala, and now you have to create a type safe JSON version of the same -- pointless double duty...PHP, Python, Groovy, Ruby, etc. win this particular battle.

I am, BTW, completely playing devil's advocate here ;-), Scala's my daily bread; PHP, wow, I did some horrible things [shudder]

Re:Taking PHP Seriously by Aqueous on Tuesday January 14, 2014 @11:27AM (#7057850)
That's true about JSON - it can be quite tedious if you have to write JSON reads and writes for things like JSON validation. But Play can autogenerate the reads/writes combinators for cases where validation isn't needed, so it ends up being as simple as putting a JsonFormatter in your companion object for a case class - 1 line. Play (and Jerkson) usually knows what to do with it, assuming all nested classes have json formatters in their companion objects, too.

I am just glad to be done with PHP.

Re:Taking PHP Seriously by virtualwhys on Tuesday January 14, 2014 @12:17PM (#7058233)
Agreed, Scala JSON libs are taking the a lot of the boilerplate pain away, but still not quite at the foo.toJson stage.

> I am just glad to be done with PHP

shhhh, this is, you know, a PHP thread ;-)

Re:Taking PHP Seriously by pkolaczk on Tuesday January 14, 2014 @10:03AM (#7057380)
In PHP cycles are slightly faster, but Scala lets you do away with lot less cycles. Not only because of awesome library, but also because excellent IDE support with instant type-checking.
Re:Taking PHP Seriously by virtualwhys on Tuesday January 14, 2014 @10:51AM (#7057614)
> excellent IDE support with instant type-checking

heh, that's a stretch, perhaps compared to 3 years ago the IDE story in Scala is all roses. It's improved with time, but I still get arggghhh inducing moments where a given source file turns into a sea of red Xs despite SBT compiling the code just fine. Often an ./eclipse -clean is the only way to right the ship.

Perhaps IntelliJ provides a different experience (although I've heard there are issues with the Scala plugin there as well).

Re:Taking PHP Seriously by pkolaczk on Tuesday January 28, 2014 @10:48AM (#7137723)
IntelliJ IDEA provides a different experience. I tried the eclipse plugin a month ago - much better than it was 2 years ago, but still far behind Idea. Also, keep in mind, we're comparing it to PHP and not Java.
Re:Taking PHP Seriously by virtualwhys on Tuesday January 14, 2014 @05:16AM (#7056262)
PHP, unless it has changed radically since 2009, is pretty horrendous as a language, there are, IMO, far, far better choices on the dynamic side of the fence (e.g. Python, Ruby, Groovy).

It does get the job done, as you say, but being able to patch a running application with oh-just-this-one-quick-fix is not necessarily a good thing as it can encourage one to fall into the opposite of programmer best practices (was the case for me, I completely understand why DHH of Rails fame said [tongue in cheek], "PHP is the devil!")

Scala, on the other hand, basically changes your brain chemistry. Compared to where I was in 2009, floundering in dynamic language hacking with PHP, and later, Groovy, Scala has completely changed my approach to programming.

Obviously the rich Scala ecosystem has something to do with that, but the language itself really just helps guide you to "correct" solutions (FP constructs in particular). At this point I cannot imagine going back to a server-side dynamic language.

Re:Taking PHP Seriously by lxt on Tuesday January 14, 2014 @11:17AM (#7057789)
It's worth noting that yes, it's changed pretty radically since 2009. There is some amazing stuff going on in the PHP ecosystem these days.
Re:Taking PHP Seriously by farinasa on Tuesday January 14, 2014 @10:42AM (#7057569)
I think it really depends on how it's being used. If you just made html pages and shoved php statements all over the place, sure that's a horrible mess. But if you modularize your architecture and use classes, it can be quite maintainable.
Re:Taking PHP Seriously by jafaku on Monday January 13, 2014 @09:09PM (#7054940)
PHP is a server-side language as you might now, so you are not replacing anything of it with Angular for the frontend, that's just an addition.
Re:Taking PHP Seriously by SCdF on Monday January 13, 2014 @09:32PM (#7055011)
Krapp's right, but to clarify: PHP that generates HTML that uses jQuery is getting replaced with Angular that talks to the server via a REST interface written in Scala / Spray.
Re:Taking PHP Seriously by krapp on Monday January 13, 2014 @09:20PM (#7054972)
Angular can replace much of the MVC work typically done by a backend framework and template engine, by having it be done in the browser.
Re:Taking PHP Seriously by coldtea on Monday January 13, 2014 @11:25PM (#7055368)
>PHP is a server-side language as you might now, so you are not replacing anything of it with Angular for the frontend, that's just an addition.

Not really. Perhaps you've missed all the "front side templates" thing. You can for example remove all PHP templating code, and just send JSON to be converted to HTML client side.

Besides, your dichotomy is invalid in general too. You can do lots of backend stuff in the front end too, if you want. E.g if you have a PHP script that converts a POST text variable into Markdown, you can opt to do it in the client, with a Javascript Mardkown lib. You can do calculations, you can use the canvas to generate images you used to do with GD, etc.