All change here

adrian smith
2 min readSep 17, 2016

--

This is a continuation of https://medium.com/@sfyire/everything-in-its-right-place-dae94cbe15b7#.7ojixyu8z

$articles are great they resonate really well with my brain’s tendency for one overriding opinion in a reality where absolute truth doesn’t exist.

But I’m thinking our happy little $valid_articles need to all say follow me on twitter because that’s the world we live in.

Let’s do that in the most convoluted way possible:

Great, we’re at a good point so far, performance is down and the code is slightly more convoluted to read, (Hope you know the order of parameters for filter, map callbacks by heart!)

Before we move on to anything else I want to mention array_reduce, array_reduce is when we want to derive a value from our existing collection it’s actually a kind of shorthand for filter and then map most of the time so let’s give an example of that

Now that we’ve reduced our reality down to sponsor mentions we have also covered the three important loops, not while, foreach and for, but filter, map and reduce let’s start talking about problems, so many problems…

Problems

  • Scope

The main problem I have not showcased here is scoping, what if we were not selling out to one sponsor but in fact many.. one inline option is to use use() on our callback like so

Now our function is bound directly to the scope so we cannot refactor this function into its own independent function or method…

  • Performance

For PHP calling functions is relatively expensive performance wise…

  • Indirection

Map, Filter and Reduce all have a level of indirection in terms of behaviour making readability more difficult..

tl;dr don’t use functional programming

There’s some more I guess — https://medium.com/@sfyire/everything-is-relative-8bb3b552ee0f#.79czq0y66

--

--