While most implementations of memoization are stateful, it is precisely the immutable functions themselves that makes this kind of memoization safe. It could be argued that referential transparency holds as long as the program's behaviour is consistent observationally -- disregarding execution time in this case.
But there is no way to import the contents of an entire namespace because PHP doesn't really have a proper concept of namespaces. Namespaces are just prefixes that are added by the compiler. Things can be added to the namespace later on.
This would definitely be a possible variation. And it works quite well for method calls. The original is a lot more flexible though, because it works for any callable.
Yeah, I partially went with isset to support any ArrayAccess object. Might not be worth it though, considering it breaks on null values. I'll consider replacing it will array_key_exists, thanks.
Author here. I'm aware of functional-php, and have used it in the past. The C implementation is great until it's not. The problem is that you need to find a C programmer willing to write the lazy implementation. And that's one of the reasons why it has not happened yet.
That's the reason why I am promoting nikic/iter over it.
What you are looking for is known as "A/B testing". It is quite common to track the variant used in the session and use something like statsd to increment counters on their performance (in terms of business metrics).
The main issue with goto is that you have no stack for those jumps, which means you can no longer tell how you arrived at a certain place. That is a major issue while debugging.
A lot of VMs these days use a JIT (just-in-time compiler) that will actually compile the language opcodes to machine code. The JVM that runs Java is most notable for this, and it is also what V8 (used by chrome and node.js) and HHVM (the new PHP runtime from facebook) do. It is very performant and also compiles rather quickly.
The article actually contains a section about prefer-stable. It helps a bit, but you may end up getting things you did not actually want. For example: 'I was using 1.0.4 and now the new 2.0.0 release broke everything.'
This is true for any code you install via composer.
That's pretty cool. Have you thought about doing this at the bytecode level?
Completely agree on the intellectual sham part.
While most implementations of memoization are stateful, it is precisely the immutable functions themselves that makes this kind of memoization safe. It could be argued that referential transparency holds as long as the program's behaviour is consistent observationally -- disregarding execution time in this case.
That's hilarious - if you're 9 years old.
Looks a lot like twitee: http://twittee.org/
You can specify a bunch of functions as a list:
But there is no way to import the contents of an entire namespace because PHP doesn't really have a proper concept of namespaces. Namespaces are just prefixes that are added by the compiler. Things can be added to the namespace later on.
Dear /r/php,
Why are you so obsessed with micro-optimizations?
Love, Igor
This would definitely be a possible variation. And it works quite well for method calls. The original is a lot more flexible though, because it works for any callable.
Your first argument is basically "I don't want to learn about
map". Which is fine, I suppose. But it's clearly quite subjective.The second argument I do agree with. It is unfortunate that PHP's callable type forces you to pass around strings and arrays.
That said, personally I'd much rather write this:
Than this:
But the latter works too, and you even get IDE auto-completion with it.
You may want to check the performance considerations for the PhpOption library: https://github.com/schmittjoh/php-option#performance-considerations
It's actually a copy-paste error from the previous post. Thanks for the fixes, they have been merged!
Yeah, I partially went with
issetto support anyArrayAccessobject. Might not be worth it though, considering it breaks onnullvalues. I'll consider replacing it willarray_key_exists, thanks.EDIT: Done. :)
Wow, I had no idea references behaved that way. Very cool, but also rather unexpected.
https://wiki.php.net/rfc/use_function
Author here. I'm aware of functional-php, and have used it in the past. The C implementation is great until it's not. The problem is that you need to find a C programmer willing to write the lazy implementation. And that's one of the reasons why it has not happened yet.
That's the reason why I am promoting nikic/iter over it.
What you are looking for is known as "A/B testing". It is quite common to track the variant used in the session and use something like statsd to increment counters on their performance (in terms of business metrics).
Relevant:
The main issue with goto is that you have no stack for those jumps, which means you can no longer tell how you arrived at a certain place. That is a major issue while debugging.
I highly recommend you read Dijkstra's "A Case against the GO TO Statement": http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html
For almost all use cases a hash map (associative array) will do just fine.
A lot of VMs these days use a JIT (just-in-time compiler) that will actually compile the language opcodes to machine code. The JVM that runs Java is most notable for this, and it is also what V8 (used by chrome and node.js) and HHVM (the new PHP runtime from facebook) do. It is very performant and also compiles rather quickly.
The article actually contains a section about
prefer-stable. It helps a bit, but you may end up getting things you did not actually want. For example: 'I was using1.0.4and now the new2.0.0release broke everything.'My advice is: Try it.
The symfony console component is not a REPL.