5 ms·
They should have stuck with Paamayim Nekudotayim for the namespace and either 1) returned an error for ambiguities or 2) used some prefix for namespaces like !F
by kwamenum86 18y ago
They should have stuck with Paamayim Nekudotayim for the namespace and either 1) returned an error for ambiguities or 2) used some prefix for namespaces like !Foo::bar().
1) is less desirable because unlike C++ PHP is not compiled. I could imagine some random included file that you disabled for testing causing an ambiguity error.
2) could work if you choose a representation that is human readable and easily parsable. The exclamation point seems to fit that description.
- DougBTX 18y agoLets say bar() returns false. Are the following two lines the same? true == !false true == !Foo::bar() Paamayim Nekudotayim is the best option, you could even use it as a prefix in case of ambiguity: true == ::Foo::bar()
- randallsquared 18y agoEasily solved by using '!!' instead of '!'. But it doesn't matter to me. I like to complain about PHP while using it, and I get a lot of stuff done in PHP, but I don't really care about it.
- DougBTX 18y agoYou can chain !, so "true == !! true" is true.
- randallsquared 18y agoYou can, but I can't think of any reason to do so, which is why I mentioned it.
- qqq 18y agogenerated code to convert stuff to explicit true/false
- randallsquared 18y ago> generated code Not a problem: either the PHP generated is only safe for a particular version, or they can add parenthesis to distinguish the cases. > to convert stuff to explicit true/false I suppose. That would seem like a surprising use to me, and would merit an explanatory comment, but given that, it might be better to just explicitly cast ("(bool)$name"), which saves the comment, and only adds four characters over "!!$name".
- qqq 18y agoEvery syntax quirk that requires the code generator to do something (e.g. add more parentheses) makes code generation harder.
- randallsquared 18y agoI would naively expect every single expression to be surrounded by parenthesis by default, implemented in the lowest level writeExpression() function or whatever. But I've never written a translator, so...
- DougBTX 18y agoWhich of these would be the same? !(!(true)) ! ! true !!true Having !! not be the same as ! ! would probably be the first case in PHP of significant whitespace.
- randallsquared 18y agoI would assume that the first would be different than the second two, in the case that !! was some other operator. It's not clear to me whether other cases in which there are double-character operators tolerate having whitespace between them. Is "$name++" the same as "$name+ +", or is the latter an error, or neither? I can't be bothered to check right now. :)
- jrockway 18y agoThat all depends on whether or not PHP considers true == true. Knowing =='s track record... it wouldn't surprise me if it didn't :)
- kwamenum86 18y agoChoose some other prefix then as long as we can use Paamayim Nekudotayim for namespaces :)
- Sujan 18y agoLast one looks fine to me.