Hacker News new | ask | show | jobs
by birkbork 4349 days ago
This is great news for the PHP community, and I for one applaud their effort. Contrary to what many HN hipsters seems to believe, PHP is quite a capable language, and HHVM / Hack is really pushing things forward.

* Hack introduces type hinting, imo the major lacking part in PHP.

* HHVM introduces speed to php. On a personal project calculating perlin noise, I got about 8x speedup on HHVM.

* The specification helps pave the way for more implementations of PHP.

5 comments

> Contrary to what many HN hipsters seems to believe, PHP is quite a capable language, and HHVM / Hack is really pushing things forward.

This attitude really frustrates me. I'm a developer with over 20 years of experience. I don't use PHP because (a) I have had poor experiences with it in the past, (b) I am enjoying my current stack (Java8/Clojure/Groovy), and (c) would go with stacks like RoR over PHP if I had to choose, simply because I've had good experiences with Rails.

You're implication that this has something to do with trendiness is frankly insulting.

Not parent, but if you make those (completely reasonable) points when you criticize PHP he's not talking about you when he says "HN Hipsters." He's talking about the "What kind of idiot uses php?" crowd, which unfortunately hangs out here too much, and frankly doesn't understand which parts of php actually are good or bad because their entire opinion is based off blog posts not experience.

I don't think you're one of those.

Agree. PHP started itself out with the handicap of a lot of shitty misfeatures, and now that they've beaten it into a state that it's possible (though in no way encouraged) to write decent code in it, anybody who doesn't put on a "PHP: It's not that bad!" party hat gets called a hater.

I'm afraid they're going to have to show me reasons it's actually superior to other languages before I'm going to jump on the train. This "it's less broken than it's ever been" stuff isn't going to cut it.

One thing that makes me chuckle every time I decide to give PHP a fair glance again is "<?php" at the beginning of all the source files. It's hilarious to me that with all the well understood best practices about separation of logic and presentation, people are still seriously using a language where you have to use a little signal to the compiler that means "ok, here's where the HTML stops and the code begins!" I assume at this point it's a vestigial tail, but it's just one irritating reminder that this language was originally designed for half-ass hacks.

So, if your PHP programs don't embed HTML in ?><?, and you use a framework with its own URL routing instead of multiple files, and your framework has plugin autoloading and initialization on every page request… why are you using PHP?
In case that was not a rhetorical question: I'm not using PHP.
> a fair glance

If you're going to harp on the most unbelievably trivial things, no, you never intended to give it a fair glance.

That, by itself, is not trivial.

Compounded with a hundred small little annoyances, it makes the code comparatively unpleaseant.

<!doctype html>
Sorry if i offended you. I really did not try to imply this has to do with trendiness, but it was a frustrated outbreak from my end. I've seen way too many poisonous hater comments against everything PHP here since I started visiting.

I myself use (besides PHP) C#, Javascript, Python, and recently revisited C++ to check out C++11 (I am thrilled). I have been working developing in mainly PHP since 1999 so I have seen most of it's ugly sides.

This thread however was about PHP, not wether Java is good or bad.

> I am enjoying my current stack (Java8/Clojure/Groovy)

Not just trendiness, but also whether a spec exists, from which alternative implementations can be reliably built. Some language despots (e.g. Python's) have even had moritorium periods of no new features specifically to help other implementations catch up. The spec announcement is a step forward for PHP.

Your current stack is at widely varying extremes along the spec continuum:

* Java 8 is fully spec'd to intricate detail, and Java has implementations other than Oracle's. Anyone can build an implementation as long as they don't call it Java.

* Clojure is informally spec'd by the comments in the functions, and what little grammar there is is explained on the clojure.org website. Alternative implementations exist to varying degrees of compatibility, e.g. ClojureScript doesn't have native macros.

* Groovy has virtually no spec at all after 11 yrs. Despite it being spec-driven at first, its JSR was inactive for 7 yrs, then changed to dormant status 3 yrs ago. My personal experience is the Codehaus project management actively prevent other implementations being built.

I was untder the impression that a Java implementation that wants to call itself Java can actually call itself Java if it is made to pass specification test suites.

There is currently one major Java(-like) implementation that does not do that, and that is the variety that runs on Android. But there are plemty of other Javas that call themselves a Java.

Right, you have to buy and pass the test suites (TCK).

The thing with Android is they are not close passing the test suites (AFAIK Harmony was close but Android is only a fraction of Harmony).

Compare what Android implements: http://developer.android.com/reference/packages.html And what they would have to implement: http://docs.oracle.com/javase/6/docs/api/ Of course the difference is even bigger for newer Java Versions (NIO.2, Date Time API, Fork-Join, …).

In addition I believe the linking semantics in Dalvik are slightly than in Java, eg. slf4j needs a special version to not fail during dex translation.

I'm not sure whether there is actually an official Java implementation that does not have a license of the implementation from Sun/Oracle or uses OpenJDK. If not they would have to reimplement all of the classes including AWT/Swing. Azul for example does have a license for Zing. I'm not sure if IBM already builds on OpenJDK.

Meanwhile, that user presumably has the impressive track record of 2 days of posting on HN, making him/her a true expert on the HN crowd.
2522 days here. He's pretty much spot on. You, however, with your trivial sub-500 day membership, don't understand why calling out such things are immature and not welcomed here on HN.

Seriously, calling people out merely for their account age? Really? You really think that's a valued contribution? I mean, your comment amounts to nothing more than a weakly flung insult.

Really? Seriously!? Really? You're hard-hitting reply makes me feel filled with shame. I repent!
Don't assume that just because an account is new that the person behind the account hasn't been reading the site for years.
That's why I said "presumably", and only referring to posting on HN, specifically (i.e. could have had previous accounts).

This is very subjective, but I find people who (again, presumably) haven't been involved in a community who all of a sudden start right off the mark by posting in that community with a phrases like "HN hipsters", to be rude.

Alright, I'll say it then. I've had an account for 1300~ days, 3 times as long as you and I've been reading for longer then that.

HN hipsters dislike PHP.

So do scarred ex-PHP-developers.

Divining which is which from posts is a dicey proposition.

It is not a matter of what was said, it's a matter of the fact that it was said by a (presumably!) newcomer.

I'm not a web-developer (or whatever you would classify PHP as), so I don't feel hit with the remark.

I don't think it was an attempt to be rude.

"Hipster" is a term commonly used to describe those who advocate so-called "Web 2.0" technologies like Ruby on Rails, JavaScript, HTML5, NoSQL, and so on. These people openly admit that they dislike the previous generation of web development technologies built around languages/platforms like Perl, PHP, and Java.

There are many of those people here, so it makes sense to refer to them collectively, especially given their typical stance toward PHP. Asking them to revisit their current state of PHP is a reasonable enough request.

Now, "hipster" is also often used as a derogatory term, too. It's quite understandable, after dealing with some of those kind of people. But I don't think it was used in that sense in the earlier comment.

I've only seen "hipster" being used in a derogatory way on the Internet. But maybe this is some more HN-specific way that I haven't seen/before, which shows that I'm too inexperienced on here. :}
> PHP is quite a capable language

I don't think anyone is complaining that it's not turing complete (or whatever), it's all the times php has dropped the ball in the std library, both with respect to being consistent with itself and just being plain broken. I don't think any sane person would switch from a language INTO php, given how many languages that are just as capable as php without having all of its various historical burdens (sigils, stdlib, mediocre type system).

Amen. I think this thread could use a little: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

It has never been about whether PHP can get shit done, it's that given languages that actually had formal design processes and make your days as a coder a joy, why would you move TO PHP.

There are simply so many other options.

There are many other options, none of which enjoy the ubiquity of PHP (as far as being installed on such a vast majority of hosts).

The barrier to entry is higher if you want to run a site on something else.

That is the sole reason PHP is as popular as it is and part of the reason why it stays popular and powers so many of the internet's top websites.

Other reasons why it stays popular is that they really have improved it a lot over the years and knowledge on how to run PHP at scale is quite easily available. The community is improving along with the language.

Yes, the standard library is frustrating but that is a pretty minor inconvenience honestly. Every language has a frustrating part of its design. This wart on PHP can be fixed and there are some great recommendations on how to transition to a better std lib in other comments on this OP.

> There are many other options, none of which enjoy the ubiquity of PHP (as far as being installed on such a vast majority of hosts).

What is this really an issue for? I mean, sure, there may be more choices of low-cost low-feature shared hosts that support PHP than other languages, but its hardly as if there aren't a sufficient quantity of low-cost (even, in some cases, with free tiers) platforms for apps in a wide variety of languages.

Unless you are literally compelled to choose a host at random, the fact that a randomly-chosen shared host is more likely to support PHP shouldn't really matter.

> none of which enjoy the ubiquity of PHP (as far as being installed on such a vast majority of hosts).

So, choose the language based on the ease of the first 15 minutes of your startup?

I could say it worked pretty well for Facebook but that would be too easy. Seriously though, I know it is very in vogue to hate PHP or at least favor X language over PHP and has been for a long time. I'm not trying to sell you on the idea that PHP is objectively the best language or even a "good" language. That is beside the point I'm trying to make which is that it literally (still) powers the majority of the internets' websites. Tons of new websites are still being made using PHP and THAT is a tough pill to swallow for many people of the opinion that it has no merit.

I don't personally enjoy programming in PHP but the way people act as if it isn't massively important strikes me as obtuse and/or petty.

I think that depends on whether an individual can get past that first 15 minutes. Me, I can have a virtual host running anything I want in a couple of minutes. You too, I'm sure. But for people who aren't pros, just getting something hosted can be a major battle. Not as major as when PHP got its start, but it's still too hard.

That's the lesson I'd love to see other ecosystems learn. PHP, by being very novice-friendly, has developed an enormous user base. How much better off would those people be if they had started with a language that was awesome not just for starting, but for the long term?

(As an aside, I'm throwing no stones here. My first programming language was BASIC, and it took me a long time to unlearn the bad habits it gave me.)

I'm talking about people who need websites in general. Not your fancy startup. Also please name me a single startup that for some reason could not flourish using PHP as opposed to some other language?

It's really more about the talent of your team than the language you choose to write your app(s) in.

> It's really more about the talent of your team than the language you choose to write your app(s) in.

If you have a talented team, why on earth did you choose PHP?

If you slog through that, might as well read the rebuttal http://forums.devshed.com/php-development-5/php-fractal-bad-...
The PHP Bad Fractal Design article is The Godwin's Law of PHP programming discussions.
For me this is the important part.

I have a team with java/php/javascript experience. PHP will not be an option for my use case. I need a json based rest interface with a decently discoverable web interface. Java has stupidly powerful rest interface libraries with jersey or full application servers, and javascript has hugely powerful frontend interfaces with angular or other frameworks, based on a strong rest interface. And the strong rest interface goes right back at java.

And we are just a limited team with java* experience. I don't know what teams with django or other twisted libraries will do, or what ruby shops will do. The era of "just make it easy to print html" is gone.

Dingo for Laravel might be worth a look for you.

https://github.com/dingo/api

edit: I misunderstood your post I think.. But if you're looking to generate APIs, Dingo is still worth a look just for reference.. :-)

>I need a json based rest interface with a decently discoverable web interface.

php has apigility for this.

Though if you don't have php experience I wouldn't switch languages to get it

https://apigility.org/

That's the beauty of an API. It doesn't really matter what backend language you decide to use. To the front-end client, it's just good old endpoints sprinkled with JSON.
Have there been any implementation decisions that have forced PHP to take a step backwards?

There are many things that they language has had to fix, and some that still need to fix. But I honestly don't feel that the direction in which the language is headed is encumbering the language further.

I don't think many would claim that PHP isn't capable. It's that some of us just don't enjoy it and find it to ugly. Especially given how mature competing languages have become.
I work at a PHP shop, coming from a Python background. I chose to come here for the team, certainly not the language. When I asked about why some things are inconsistent in PHP compared to other languages, its age was a common defense. I was shocked to find that Python is older than PHP, and Ruby is the same age!
However, Ruby didn't see the uptake of usage that PHP did. It was popular -- one of the first languages that you could use as an alternative to CGI!

However, age isn't why it's got so many sharp edges. That's Rasmus' fault, and the core team's.

I agree, but there are many with a large investment in PHP, and since it isn't going away, it's very much worthwhile to make it better.
All due respect it is easy to write shitty code in PHP but you can also craft elegant design patterns that are easy to grok.

I can't think of a language that has out of box adoption for web development similar to PHP.

Perhaps time to revisit PHP some time then? It also has become more mature :) Much of PHP's old built-in functions are crap (side effects, inconsistent parameter order, wierd naming), but you can't really (and shouldn't) compare those parts with another language as there is no correlation.
>Hack introduces type hinting, imo the major lacking part in PHP.

Hack extends PHP's type hints, it doesn't add them. It also makes PHP statically typed.

I stand corrected.

PHP does not have type hint for their internal datatypes (int, float, string). Only array is supported. Type hinting for your custom datatypes is supported, when used as function arguments.

Also hack introduces type hint for function return type.

Scalar (int, float, string) type hinting may be added in a future PHP version, and there's currently an RFC for return types (I expect it'll pass myself). PHP already let you type hint for classses.
You can also hint on interfaces. If strict typing is important, I use the SPL primitive wrapper classes like SplString or SplInt http://php.net/manual/en/class.spltype.php
Cool! I wasn't aware of the RFC. Must be this one then? https://wiki.php.net/rfc/returntypehinting
Yep.
> It also makes PHP statically typed.

I disagree. PHP finds this perfectly acceptable:

    class Foo {}
    class Bar {}
    function foo(Foo $x) {}
    function bar(Bar $x) { foo($x); }
PHP is clearly checking types (actually, class tags) at runtime, every time a function/method is called. That's dynamic typing, not static typing.

Crucially, static types can be erased before execution without affecting the behaviour of a program: http://en.wikipedia.org/wiki/Type_erasure

I meant that Hack is statically-typed, not PHP. PHP is obviously dynamically-typed.
Hmm. Looks like Hack still includes files based on strings: https://github.com/hhvm/hack-example-site/blob/master/index....

How can a language be statically typed when the instructions telling it what code to use are dynamic?

include "foobar.php", IIRC, is executed at compile-time, and I assume must be in Hack's type checker too.

Also, I don't see how pausing execution and re-invoking the compiler at run-time to load the rest of the code base (which you can do in PHP with a conditional include, don't know about Hack) can't be done with static typing.

Let's say we have the following:

file1.hh:

    <?hh
    $giveMeAnArray = (time() > 1)? function(array $x) {}
                                 : function(stdClass $x) {};
    $anArray = [];
file2.hh:

    <?hh
    $giveMeAnArray($anArray);
file3.hh:

    <?hh
    list($f1, $f2) = (time() > 1)? ['file1.hh', 'file2.hh']
                                 : ['/dev/random', '/dev/random'];
    include $f1;

    if (time() > 1) $anArray = new stdClass;

    include $f2;
As far as I understand it, the following will happen when we run file3.hh:

- HHVM will compile file3.hh. This phase doesn't know what $f1 or $f2 will be, or whether $anArray will become a new stdClass, since they depend on the output of time().

- HHVM finishes compiling file3.hh

- HHVM will execute file3.hh, setting $f1 to 'file1.hh' and $f2 to 'file2.hh'.

- HHVM will compile file1.hh. This phase doesn't know what $giveMeAnArray will be, since it depends on the output of time().

- HHVM will finish compiling file1.hh

- HHVM will run file1.hh, defining $giveMeAnArray = function(array $x) {} and $anArray = []

- HHVM will resume running file3.hh and set $anArray = new stdClass

- HHVM will compile file2.hh, which contains a type error. How does it know?

The most likely answer is that type information is stored in values and checked during usage. That is not static typing, it's 'dynamic typing' (tag-checking).

There is an alternative possibility: the state of the compiler could be preserved between files, so type information from file3.hh and file1.hh is available when compiling file2.hh. However, this information wouldn't include knowledge that "$my_account = new stdClass" has been executed, since that's dynamic run-time information which is only knowable after file3.hh and file1.hh have finished compiling.

There is no way (to my knowledge) that interleaving static type-checking with dynamic execution can produce a type-error when file2.hh is compiled. The type-checking must have access to the execution state of the program, ie. it must be dynamic.

If type-checking happens during/alongside/interleaved-with execution, the compilation phase (which must be done prior to execution) cannot know the types of the code it's compiling. Without this knowledge, the first unit of code it produces is forced to use dynamic types (AKA a unitype). Once that unit is type-checked/executed, the runtime information gained may be used to partially-inform subsequent compilation, somewhat like a JIT, but there would always need to be dynamic fallbacks. Of course, a dynamic fallback defeats the main point of using static types: being informed when there's an error. There may be incidental benefits from doing this though, like faster code.

nit:

It makes it gradually typed. The types are only as static as you choose to make them.

It does have a fully statically and strictly-typed mode, though, and regardless of its strictness, it makes PHP fully static in strict mode, to my understanding.
PHP the language and the development environment around it is quite capable, however the unwashed masses of "developers" and the plethora of code spewed forth from them would cause you to avoid PHP like the plague.