Hacker News new | ask | show | jobs
by TazeTSchnitzel 4067 days ago
Yes, and as the person who came up with that, I was well aware of the irony. It was originally this:

  declare(strict_typehints=TRUE);
However, I changed it to the form that you see there because it was shorter. I felt that in the grand scheme of things it's not very important: declare() isn't a function, it's a language construct, and saving 5 chars from something that'll be typed very frequently is probably worth it.
4 comments

> saving 5 chars from something that'll be typed very frequently is probably worth it.

This mindset is something that I've personally seen uniquely permeate every layer of the PHP community, more than anywhere else. I'm honestly curious, what makes communities seem to value things like typing less characters over clarity and correctness? The most important thing to me is reducing the amount of mental state needed for a human to read any line of code.

Because PHP is for really fast development, and not for slow movers who actually think a lot. That's what I sense after joining a company using PHP.

The language itself feels like a bag of features copied over from top contenders from the TIOBE index. You can see the fastness in the core of the language design.

After all, you use PHP to perform MySQL queries in the middle of HTML tags. If you want to do this, you know some principles are merely burden for your smooth execution of the web site development, and should be throw out the window at first thought.

Just because you can do something doesn't mean you should

The sort of approach you're describing is not suggested or used by anyone with half a clue what they're doing.

Indeed, no one with half a clue what they're doing uses PHP.
We program so hard we don't have time to think. Or type. At least not with as many characters as a sane person would.
In this case I don't think it sacrifices much clarity, and it avoids the word "typehint" which is controversial (correctness is disputed). Using TRUE wouldn't necessarily be more correct, it's fairly arbitrary.
I sort of wish you had done:

  declare(types=strict);
instead. That way other options can be added in the future.
Not syntactically legal, unless it's special-cased or we unusually make a lowercase constant for that purpose. declare() takes a constant value.

Well, it could've been this:

    declare(types="strict");
Alas, we are beyond feature-freeze now. Also, I quit PHP development.
I believe there was some discussion of using the same strict declaration as javascript ('use "strict";'), but there's already an "easter egg" in PHP that causes your program to exit and prints out something like "I think you're using the wrong language."

For some reason, this Easter egg was deemed too important to displace with an actual language construct.

Well, there's also the fact that something that changes the language behaviour really should be a pragma and not a magic import statement.
i quite like this concept too, but both are still better than Hack's

    <?hh // strict
Strict what?
Hack's is a comment, not a proper pragma, too.
Yeah that's kinda sucky too. I assume it's because they also support their "strict" mode with regular php files?
Well, there are non-ironic alternatives:

    declare(strict_typehints=TRUE); // not ironic, not short
    declare(strict_types=1); // ironic, short
    declare(strict=true); // not ironic, even shorter
JS has one strict mode, this could've been an opportunity to introduce an umbrella mode for strict coding in general.

Also the declare syntax could've been augmented to support passing implicit boolean parameters without setting a value:

    declare(strict); // oh yeah.
So... you know. Not that it matters what you call it, but choosing ugly (and ironic) over pretty (and sane) shouldn't be taken so lightly.
As someone who will be typing it very frequently, I wish the more verbose and obvious version had won out.