Skip to content

u/igorw

In this archive from Jun 2012 to Dec 2014

8
posts
116
comments
0
media
553
score

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.

2 points

You can specify a bunch of functions as a list:

use function foo\bar, foo\baz, foo\qux;

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.

2 points

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.

1 points

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:

->map(method('getAddress'))

Than this:

->map(function (User $user) {
    return $user->getAddress();
})

But the latter works too, and you even get IDE auto-completion with it.

1 points

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.

EDIT: Done. :)

2 points

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.

3 points

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.

14 points

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.'

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.