5 ms·
Async queries, great advice..do that. The rest meh... The bad: "Use HHVM". Do not do this, just upgrade to PHP 7. HHVM does have better performance [in some c
by verelo 9y ago
Async queries, great advice..do that. The rest meh...
The bad:
"Use HHVM". Do not do this, just upgrade to PHP 7. HHVM does have better performance [in some cases, not all], but it also has many unsupported modules [such as Memcache based sessions]. It's difficult to get improvements added and you're going to get frustrated by something people in the mainsteam PHP branch can do that you cannot do.
?int $var = null;
This is a question of style. Personally, i can read it, but it is a little odd and I've seen people get confused over it. I'd personally avoid it. The null check and type check is much clearer.
- cnowacek 9y agoIt's not just a question about style. ?int can be enforced at compile-time while the null and type check would be caught at runtime.
- verelo 9y agoGreat point, and for that reason I really like it, but generally my view is: "for most situations, humans are more expensive than the compute costs, so do the thing that is easy for a human to understand and pay the tax on your compute power". Obviously that doesn't always hold true, so place your bets accordingly.
- int_19h 9y agoWhy would it be hard for a human to understand a type declaration using a syntax that has been well established in some of the most popular programming languages (C, C++, Java, C#) for several decades now?
- verelo 9y agoThe longer [if based] format can almost be interpreted by any human that has no programming experience but a good grasp of logic, the other is just inherently more complex and less verbose. Edit: And my point here is basically that less experienced programmers will get it, which makes the barrier to entry lower. Going back to my previous statement, without a better reason, I'd encourage self documenting code and less abstract approaches. This is a pretty mild one, easily looked up...and probably a great thing for people to learn, but still more complex at the end of the day. Language is almost irrelevant here, it's a general statement.
- int_19h 9y agoI think you overestimate the readability of C-based syntax in general. A human that has no programming experience would have to start with parsing what !== means (and it's not at all obvious that ! is negation, or why = is doubled), and then move onto &&, although that's slightly more obvious. Nor is "int" obvious as a shortening of "integer" outside of CS - I've seen people interpret it as "internal", for example. Going further, to even figure out why you need to do all this, that human would need to know such concepts as variables, data types, and nullability. The notion that variables can have designated types is a pretty obvious takeaway from the first two.
- verelo 9y agoJust for fun, if you didn't know what "?int $var = null;" meant, how would you explain that to someone verbally, or better [like most programmers would] how would you search for this online? Finding the definition of "!==" is easy, simply searching that [including quotes] gives me the answer. Looking for something like "?int =" just gives me useless responses upon first glance.
- deleted 9y ago[deleted]
- dustball64 9y agoI'm a little confused and am seeing conflicting information everywhere. How can I use async queries in PHP right now? It looks like the code the author wrote is in Hack. Can Hack code be injected like that into the PHP file, or does it require me to write a separate file and somehow link it to PHP?
- verelo 9y agoThat that I know of, but [after a brief stint using Hack] I wrote up a custom module that supports this functionality using curl in PHP 7 to spawn up multiple threads. It's a touch messy to implement, but totally possible if you want it.
- deanclatworthy 9y agoI picked up on this straight away. Regarding some of the other things in the article: - http://php.net/manual/en/function.curl-multi-exec.php http://php.net/manual/en/function.curl-multi-exec.php will at least allow you to make multiple curl calls in parallel - Regarding typed arrays, writing a wrapper class that throws an exception is trivial, although it won't solve the editor problem. I found the article to be a little condescending to be honest. As you rightly point out HHVM is more or less ignored by the wider PHP community now PHP7 is out, and the majority of other points are solved one way or another.
- verelo 9y agoYeah, i wrote a PHP MySQL module that uses multi-exec curl as a means of creating parallel queries. I have been meaning to open source this for a while now, might try do it later this week...i don't see a better way to do it in PHP 7 as it stands today. My biggest holdback has been that it's just dangerous, essentially HTTP becomes the protocol for connecting to the DB, which means you need to ensure those requests are locked down and i suspect most people will mess that up and create a world of hurt for themselves.