Yeah, I am super pumped to give this talk. I've given it a couple conferences thus far in the room has been equally as packed So thank you guys for continuing that trend for me It makes me feel great and that I hope you guys have had a great conference and that you leave here feeling inspired Especially after this session may be inspired to never again write another loop.  So my name is John Kerry I'm a software developer in the Kansas City area. I'm actually from Lawrence, Kansas, which is a little bit west of Kansas City and I kind of have lived there for a while and helped do a couple user groups in the area. So I love talking at my user groups I love talking at the areas around Kansas City. So this is my first time here at Drupal con, but I'm not a newbie to PHP I've actually been coding in PHP for about 12 years or so and I think this talk Feels really good and true to me and that it's kind of a culmination of that kind of 12 years 12 years of experience and Also with working with my juniors mid-levels and seniors throughout my career to kind of see where they struggle and where their code kind Of balloons into this unmaintainable mess and I think that really loops are the crux of that Loops I think have become a magnet for complexity and if you think back to when you very first started programming You likely learned about loops really early on in fact maybe you were taught that on your second day of at a keyboard trying to learn to program and The problem is is that we have this early success with loops and we continue to go back to them we continue to reach for them when they're easy when they're at hand and I think there's some other Programming concepts that we can use if we really want to communicate better to the rest of our co-workers to our future selves and I don't know whoever might be reading our code in the future, so Let's get down to business So I'm from Kansas City, which is just a short flight in from New Orleans and like I said I Help organize one of the user groups there and that is the Kansas City PHP user group So we have a great mix of developers that come through our user group we have everybody from absolute beginners that need help installing a web server and PHP and Have really never programmed before all the way to people more like myself that have been programming for a really long time So it's always a challenge as a user group organizer to keep all these people equally engaged So we kind of alternate between coding sessions like hack nights presentations social meet-ups we kind of try and cater to a lot of different people so one of the nights we were having a hack night and I had to think of a way to keep my people entertained for the entire night So I reached for what's called a kata or this repeatable programming exercise that you can do to refine your skills to Try out new techniques and things like that So there's a really famous one called fizz buzz and fizz buzz is super simple So you print out the numbers from one to a hundred and for multiples of three you print fizz for multiples of five You print buzz and if it's divisible by both three and five for instance 15 You print fizz buzz so the output for such a program would look something like this and a Canonical example for that would look something like this Nothing too difficult here nothing extraordinary There this certainly wouldn't win any awards But often this problem is a nice little signifier when doing a job interview just to kind of figure out One can you program under a little bit of pressure and two can you actually program at all? So this is super simple, but when somebody sitting there over your shoulder, it is a little complex so This is a really simple problem But I find that I learned best as a more senior person when I limit myself when I voluntarily put Constraints on myself to say how might I solve this really simple problem Maybe in a different way and then what can that different way lead me to believe about other ways of solving bigger more complex problems So I thought to myself and I tweeted this out at the time I said here's a coding challenge. Can you implement fizz buzz without using control statements? without using ternary operators without these different ways for switching and doing like if and else and and while and switch and looping and doing all this stuff and This guy that follows me Jeff Madsen Tweeted me back and he said that he had solved this in a really creative way and I think that this is just hilarious So you basically take an entire array and you build keys with those numbers three six nine with fizz another array fives five ten fifteen twenty with buzz and then multiples of fifteen with fizz buzz you take The the range computes basically a sequence from one to a hundred and then we replace all equivalents of three with fizz Five with buzz fifteen's with fizz buzz. I just thought that this was so creative So next time you have a job interview if you were to write this for me in a job interview I would Absolutely hire you because it just shows that you're thinking outside the box and maybe showing off a little bit. So Sometimes that's good. Sometimes it's bad that would just be awesome So if you don't get hired for that and you use this just let me know and I'll talk some sense into him So it really got me thinking and it said Why don't we use arrays for almost everything and I realized that this is a Drupal conference And you guys have been using arrays for so long you'd be like man We've been programming with the race since Drupal for three and four, right? so This is nothing new to us, but it's more of not just thinking with arrays But this idea of collection oriented programming and this actually isn't a new concept There's entire languages that are focused on this simple construct of collections of data and transforming them from like piece to piece The unfortunate consequence is that a lot of those languages things like APL K and J have this syntax. That's just it looks like calculus And that's not easy to type in like a regular ASCII keyboard, and it's really kind of mind-numbing to read It's a good mind-bender to actually look at it, but it doesn't make a lot of sense in day-to-day. So we can get back down to functional programming and this idea of having collections of Data and transforming them over steps to create new collections at each step I think is a lot more readable and a lot more maintainable, but you guys are probably also thinking this is a Drupal conference We've been programming with hooks and functions for a long time. This isn't quite the same thing This is a little bit different. This isn't the same functional programming that you might be used to so Before I kind of got into looking at some functional languages. I kind of thought functional programming was this This is a lisp. This is a modern lisp called closure And I don't exactly know what this does, but I pulled it from their standard library Just has a nice example that fits on a slide. So this isn't the kind of programming I'm saying you need to write code in this style to succeed. That's not true at all But I think that there are some core concepts that are in functional programming in this idea of collection Oriented programming that can help us in writing our PHP whether you're writing procedural code Your new object-oriented code in Drupal 8, whatever that might be So there's three concepts that I want to talk about today The first one is called map and what map allows us to do is to take one collection and make a one-to-one Transformation into a new collection in between is a function that we basically run every single element through to create a new a new collection so if we think about this in terms of cooking and Cooking analogies always seem to work their way into programming But if we have onions and we chop all of those onions all of a sudden we have chopped onions if we have a collection of ingredients And they all need to be chopped in the same coarseness We kind of have a map operation across those ingredients Filter is the next one and filtering allows us to segment our collections into Well, it doesn't allow you to split them like other operations But filtering basically kicks out ones or keeps ones based on a certain criteria So you could think of like a number like if numbers are greater than X keep them in this case for limes If we're cooking with a lime, we really only want the freshest nicest limes You might buy an entire bag and say I need four of these but I need the best quality ones So you might quantify that and then look at all of your stuff and then keep the best ones, right? Reduce reduces kind of a wild card It's kind of hard for me to explain reduce because I'm not sure that I fully understand all of its capabilities because you can do so much with it so I kind of paired it down to a really simple example for this talk, but reduce basically let you put into Let you take a collection put it in and run a function over it But you kind of accumulate data through each iteration and that accumulated data is available to the next Successive call and this will make a little more sense with a little more code But for our cooking example think of it like you've processed all of your ingredients into wet ingredients and dry ingredients And then all of a sudden you need to combine them together If we combine them together, we could bake a nice delicious cake So Something like that. So let's see what some code for this would look like So PHP in its core library has a couple different functions each a function called array map array filter and array reduce Array map is super simple. We can start with our collection here at the top Just one through five and we need to multiply all of those by two So the map operation first takes a callback and that's any callable whether it's an anonymous function closure I'll show you some other ways different ways of defining those callbacks But the result of that creates a one-to-one mapping We have five elements here and five elements here in the very bottom and we get our new results now This is a brand new array the result of that is a brand new array. So we end up with two arrays still in memory so that One of the common questions with this is John. How does this affect performance? So sometimes depending on what data types are inside of your arrays you can get increased memory performance But under certain circumstances you can also improve CPU optimization. So Long story short, you should definitely profile your code before and after Implementing something like this to see like where are my slow points or where am I consuming a lot of memory? There's no hard and fast rule. I can't say Only do it under these circumstances. You have to take each situation uniquely Sorry for the tangent there, but So a ray filter So we have in this case, we're taking the modulo operator, which is essentially it finds the Remainder in a division operation. So in this case, it's basically just defining all numbers divisible by two It works the same way that map does except for our resulting collection only keeps where our callback returns true So two four and six are all divisible by two and they can be kept into that new collection And here's an example of array reduce So in this case, we are only accumulating and summing all of the data that's in this array Now there are core PHP functions to do that operation But it's easy to understand reduce just from a basic basic example with some code like this So the result of that callback is passed to the total variable as the first argument to that callback there So we get one plus two is equal to three plus another three is six plus four is then ten plus five is then fifteen So if you're a fan of Voltron or if you don't remember Voltron power Rangers This is kind of a visual way to resemble this right so you have your guys They transform into these other guys and then they become the big guy So that's a thing So I think that these ideas this map filter and reduce are actually more expressive to their reader What happens is and I'll talk about this a little bit later is when you get to a loop You don't really know what's going to happen inside of that loop When you have an operation like map or filter or reduce You communicate to the reader that what they're about to read is a one-to-one change a one-to-one map An operation that goes over the entire collection and you get a new collection out of it This is all about communication But also we get benefits of code quality. So I'll talk about that a little bit later, too so This idea of expressive language I want you to think about the word cool for a second The word cool is used all the time in our just daily conversations We reach for it because it's easy, but it's not very descriptive, right? Like think of think of chess like you might say yeah, what chess is cool. I like chess Roller coasters are also cool if you like that sort of thing But have you ever played chess on a roller coaster because that's really cool And there's actually people out there that try and do this Which is hysterical, I love it. It's just like so rebellious. It's so against the thing, right? So um So if we're talking about chess chess isn't just cool. It's contemplative and Roller coasters aren't just cool. They're thrilling and Playing chess on a roller coaster isn't just cool.  It's I love it So anyway, yeah, this idea of expressive code map filter and reducer are more expressive Yeah I just thought of this so it's also like if you were reading a novel and let's say you're reading something like Stephen King And he's like the wolves emerged from the hedges and they looked cool Nobody really wants to read that that doesn't say anything It's like you want to hear about you know the snarling breath and everything so Don't use cool. So here's an example of a really simple for loop This is something you would probably see where it needs to grab the current element It needs to do some kind of operation on it and accumulate it into a new variable. Well, why do we need to use? Four in this case. Why can't we just use map? It's the same exact thing and it looks like same the same exact way that our example did from before if We were getting the even numbers from a list Looping over them would look something like this and we could say why are we doing this in a for each loop? When we could do this with array filter That's the same code that we showed from the example before Same thing with summing again. That's a really simple example and it's harder to communicate that in this talk, but Anyway, just for one more example before we kind of dive off into another tangent Let's imagine that we have like a list of users Oftentimes one of your first loops as a PHP programmer might be looping over collections of data from a MySQL database I don't know Lots of people probably copied that from the PHP docs and then just used it right away and not thought much about it But again what happens is we start sticking more and more code inside of this for loop over our records And that could grow to be 20 or 30 lines long. That's not maintainable. So in this case We're just transforming this array to we're casting it to an object which then becomes an instance of standard class Let's we'll use this in the next slide to where then we say users of age less than 18 are kicked out We need to find it where we need to keep them like Jamie and Megan are our minor kids And maybe we need to do something with them and maybe we need to count how many Miners we have so of course we have to or we could have counted the filter from before So that's another instance of reduce. We're taking that collection and we're reducing it down to a new value in this case Sometimes it's a string sometimes. It's an int sometimes. It's a brand new array. It's really kind of whatever you want So this idea of functions really really like functions And I'm going to continue to show you why but I think that this image shows a really good example of why and that is Functions that their most simple core are are very simple. They have an input And they have an output that might seem like well, what do you mean John? Of course they do but The real benefits of functions happen when we start to drive all of the all of the functionality inside of this function to depend Strictly on the inputs that the output should be directly Related to the input that we shouldn't be able to execute this function multiple times with the same input and get a Different output this allows us to reason about the code and not need to reason about the other state That's in our system which might be a database. It might be a cache. It might be some global variable that you're trying to depend on Strive to write functions that depends solely on their input and return the same output So just a little bit of quick review on Callables if you're an experienced programmer this will end up being some review if you're still kind of getting into Writing PHP this should be a good little introduction So we can define functions as global functions where they're not within a namespace. They just kind of Exist and can be called from anywhere. So these are our global functions They usually have input like say hello if we need to say hello to somebody's name We can pass that name in as an argument Static functions can be defined on a class and then those static functions can be invoked from anywhere They're similar to global functions, but you need to qualify that call with the class name before you invoke it and often Time static functions are great because you need to kind of group some functions together Maybe on a user maybe in some type of utility class It's just a good way of grouping functions together and they can be invoked from anywhere Object methods are a little bit different if you've been playing with Drupal 8 You should be familiar with what an object method looks like but what's cool about an object method is it has access That object has access to its internal state. So you can see here in this line We're defining a new user and we're passing in the name John later when we actually call get greeting We have access to that name John And then it just says hello John So we don't need to litter the outside of our program by always continually passing in John We get this joined thing together where we have the object all of its state and its behavior kind of passed as one Anywhere in our program Anonymous functions are are kind of close to what I was showing so far, but they allow us to just in sorry, they allow us to Define a function anywhere, but instead assign it to a variable And what we can then do is pass that variable to different places in our program to either invoke it later Maybe even to serialize it and store it somewhere if you have some special code to do that There's a little bit of code in here to do that Later so anonymous functions are are just that And then we have this concept of scoping Scoping has to do with what data your function or your code has access to when it executes So this is the most basic example of scoping so we have this function called hello and it takes a name as its argument and We have this extra variable method here and methods actually not used in our input, but it's used Outside of this function call at the very top. You'll see that when we actually invoke that method There's no way that method can be bound inside of that method Sorry, that was confusing Yeah, so you can't use it you'll just get a PHP notice as a result saying hello with a global Method or I'm not going to pick bad terms for this. Sorry guys If you use this keyword called global Which you may or may not have seen within Drupal before when you kind of want to reach out into the global scope and say I want whatever value you have inside of this method value here, and then we could actually use it This is definitely a discouraged practice because that global value could change From other code that's executed before you again execute this function If we really wanted to have access to that method we would go ahead and pass it in as a method argument There to say hello, so then we can actually use it as expected this other This has to do with Trying to use a variable that's defined inside of say hello So this dollar sign name is not accessible outside of the function Rather, it's just again like an undefined variable at that point There is this concept called a closure and the closure is a type of anonymous function that has context After it's defined so the context that we have here is this method variable at the very top when we go ahead and define that function We kind of pass in method And it's kind of stored along with the with the anonymous function inside of the class So then later when we invoke it like with John down here. It's still already knows about method We don't have to pass it in again and again So that's a little overview of functions and why we want to depend solely on what's inputted input into our functions and Make sure that that returns the same output no matter what so if you were asleep now is the time to wake back up I know it's kind of weird in the afternoon. Everybody's tired from a long conference So we're gonna go back to some more high-level code now So here's I want to talk a little bit about the different callables that you can pass into these array functions because people say I don't want to pass in anonymous functions because maybe I need to reuse them Maybe I need to put them as static methods on a class somewhere and then test them through my test suite I don't want to define them as anonymous functions there. That just looks weird to me So let's walk through an example of how to do that So what I'm going to end up doing is taking this collection of rows that are at the very bottom from our database and transform them Into these user objects. So this is a static function called from array. That's on a class called to user It's pretty simple it's going to take in each one of these rows and pass it as an argument up there as data Basically unpack that data store it a state on the user and then we'll have a new user object so Using it with an anonymous function would look something like this So we have our build function, which is just an anonymous function it delegates to from array And we pass it right in and you might be thinking those of you that are experienced with this Why not just use user from array as a callable because it's only taking that same argument and passing it directly to our callback And we can in fact do that There's several different ways that we can define these callbacks instead of an anonymous function We can use this syntax here Whereas a string we can give it the class name and the static method name and PHP will go ahead and invoke it Same thing with if we have an if we have a tuple just user and then from array Or if we have the instance of the object itself We can also make that call So we all sat through a nice keynote this morning basically about being nice to your brain And I think a lot of this code that I'm trying to show You might think at the outset this is really confusing. Why do I need to do this? This feels like more mental tricks to go through stuff But as we get into this pipelining technique I think that you'll see that it gives us ways of isolating these little blocks of code into functions We don't need to worry about other variables that are defined and the rest of our code so When we're being nice to our brain There's often code that looks like this. I'm gonna switch to this microphone real quick while I'm at the keyboard Can you guys still hear okay? Sweet, so This is an example of a long for loop that I pulled from the smarty library Which is a kind of like twig. It's a predecessor to twig. So it's responsibilities for rendering html And this is kind of hard code to read those of you that are in the back If you kind of squint your eyes at it You can kind of see the shape that this code starts to take and I don't know about you guys, but it's kind of Disjointed it uses a little bit of different naming syntaxes and ways of representing the code and here I'll just help you guys out So you kind of get a shape of this code You can step back from your code and apply what's called the squint test now Does this code look uniform does it look like it's easy to maintain just from squinting at it like this? And I would say the answer is no and that we can maybe Go towards structuring our code in a way that does look more uniform to make it so that we can kind of put our brains on Autopilot when looking at some of this extra syntax that's there and That this gets back to working memory and working memory. I think I can go back to this guy so working memory is Basically like the RAM of your brain. It's this really fastly processing part of your brain that can make decisions quickly, but it can also hold values or hold context from time to time so you might be Walking outside and there's a lot of things going on things like maybe there's a jackhammer from construction that's going on There might be some birds flying overhead. There might be people walking around you Maybe you're on a college campus and you're trying to figure out exactly what's going on And if there's anything coming at you that might be a threat So your brain is kind of on autopilot because these things you see are very very familiar And this kind of starts to happen with code when we get a lot of variables that are in our function and What this does is it makes it hard for our brains to remember The values of all these different functions the longer those variables have to live So if we can reduce the number of variables that are in our code We can make our code easier to reason about and we don't have to think and hold in our brain like seven different variables That take up space in our mind So it it decreases our ability to cognitively process and think through the code that's in front of us So I have an example of this of how it would apply if we were to just look at some pros If we were just look at like a list of facts here and then derive some conclusions from it And then maybe I'll show how we can clean that up So imagine if you will that we have three dogs and they run into your living room Gina who Maybe your sister She feeds the dogs each a strip of bacon Except for your dog's back because he pooped on the floor and bad dogs don't get bacon Spotwags her tail and then rolls over You're definitely hungry and you eat two strips of the bacon from an oven that's set at 400 degrees Gina hands you fresh bacon and you drop it because it's too hot Five pieces of fall to the ground and all of a sudden there's no more bacon So how many bacon strips were prepared today? How many bacon strips were actually eaten today? Now there's a lot of Information here and we could certainly spend a little bit of time and read back through it to figure that out But if this were maybe written or communicated in a way In a different way, we could discern that a little bit easier. So let's try this again We have three dogs and they run into your living room And we know that Gina gives each dog a strip of bacon except for spackle. Well, we can kind of reduce that down to two When she only gives two dogs a strip of bacon So we kind of know there's two bacon strips that have at least been prepared Spotwags her tail. Well, that's not really relevant to us.  We just care that you have the two pieces of bacon Gina hands you more bacon and you drop it, but we don't care that it was too hot We only care that the five pieces fell to the ground So all of a sudden we've kind of removed some of this context that we don't care about For the sake of answering the questions that we do care about and I think we can do these same things with code So there's a cartoon that's kind of been making the rounds over the last couple months And I think it resembles this idea very well So imagine that you're sitting at your desk and you're working really hard on kind of wrapping your mind around this code problem And you know you're digging into it. You're figuring out what all the different classes do Let's pretend that maybe it's Drupal 8 and it's the first time you've ever looked at it And you've got this big object graph in your head. You're trying to figure out Okay, this piece goes to here the config system loads stuff from the files.  You're right back stuck at step one So These concepts we want to try and keep as little as we can in our head at any given time This has to do with small functions and simply small programs Jessica care is a host on the ruby rogues podcast And if you don't listen to this yet because it has ruby in the title You should definitely ignore that because it's a fantastic podcast rather whether you do ruby or not so she says a program can only change if it's alive in a programmers head and the code that we write is Not constantly changing but bits of it are changing and to be useful to the people we work for it needs to be able to change easily So one of the coding terms that I've kind of come up with and I haven't heard this described elsewhere Actually, oh, that's my next slide. So this concept here of nested control structures This is what I was talking about with where loops grow in their complexity so much We often throw these different if statements in there We often have nested loops like more and more for each is what we can really see if we look closely Is that each one of these control statements is actually its own little program? It could actually be isolated into its own little function. So instead of by the time we get down to this echo statement There's a lot more context that we've already processed through and I don't know about you guys But when I get that deep into a function, I kind of get a little fuzzy-brained and don't know what's going on I kind of like to have more assertive boundaries in the code that I'm looking at So for me it actually gives me a little bit of anxiety when I get down and I see that kind of stuff And I call this control structure anxiety If we look at the shape of that code that we just had where it's for each if for each if else Blah blah blah.  What is my developer doing or what was I doing when I wrote this code? It's really hard for us to remember that context with so much code on that same block You know are these new rules that we need to consider at each control structure? Are they new variables that we're introducing and when can we forget about the variables that were introduced before that? Are these just minor details or are these brand new contexts that we need to consider with each if statement? The readability of the code is also another issue. So like in this case you might think well these look like pretty well-named variables Custom field values. We always hear about not using X not using I but when we use the same variable so many times Like custom appears like ten times in this code block Field the same thing Value the same thing. There's so much naming redundancy here. It's hard to really see what's going on So just because we have these longer names doesn't necessarily mean that it's more descriptive and One of the things is that local variables are just noisy In my mind they they kind of take up They take up mental cycles as I'm reading through code So this is maybe something that you would see in like a common controller in an MVC application So, you know, we have to unpack some data from the request. We need to throw some data at the database do something with our students extract some data from those students and then return a response by the time we get to the end of that function There's seven variables that we have to keep in our head of how they've been defined How they've changed and things like that now seven isn't that much But it's just a little bit of mental weight and juggling that we need to do to even make sense of this code I would say that we should ruthlessly eliminate local variables If there's a variable that you use only once Just in line it. There's no reason to have it standing around in the rest of your code taking up mental space for your reader when we can just in line it and We know that it's not used after it's actually used in that if statement if your Objects have what's called a fluent interface where you can chain method calls together. You should definitely do that because each of these Instance variables this DB this connection and then the roster Each of those again is just local variables. They take up space We don't know where when they're being used if they're being used again and we can when we can forget about them So this idea of chaining Let's get back to map filter and reduce because I think this is where the real power lies Let's imagine that we have an array of numbers and we need to multiply that by two We need to remove any results that are over the number nine and then we need to sum them together So if we were to use the concepts that I just said earlier Obviously, this is more readable right and you're thinking John that's not more readable You're crazy and you're right and really the the reason for this comes from the argument Mismatch here between map filter and reduce and you might be thinking. Oh, this is just another dumb PHP haystack needle thing It's actually not map is actually very attic meaning it can take multiple arrays So that when that callback is invoked you don't have just one value You have two arguments or three arguments if you're passing a multiple arrays So there's a good reason that these arguments are flipped But it doesn't make for very good and easy to read code now does it? so thankfully I Have a solution for that which we will get to here shortly So you might be thinking well, what if we just put our code into these little Well-named functions, maybe that will solve everything and then we get back to this problem where we're reading From the inside out at first. We're calling keep under length of six which its value is passed to add Greeting which is then all passed to join We could introduce instance variables to hold these values But then we're right back to that other part of using instance variables when we really don't want to do that so this is Douglas McElroy he worked at Bell Labs and Bell Labs is where they invented Unix in the 60s and early 70s And in fact Douglas McElroy was the inventor of Unix pipes We owe a lot to this Mr. McElroy for piecing things together For taking collections of things and passing them on to each other So if you're not familiar with Unix pipes, let's look at an example of that So Unix pipes work on the command line. They take it where we can take small little programs That are written and based in the Unix operating system and we can pass to the output from the previous program To the as the input of the next program So here we're using the program cat to output the list of friends that we have We can take the output and each one of those lines and we can pass it to AUK and AUK can allow us to filter out all names that are less than six We can take the output of that call and pass it to XRs where we can then prepend the name or the word hello So what's really great about Unix and I think a lot of people have heard of this is that has small little programs that you can piece together and rearrange for different Different functionality and that's the power of it is that you don't need this one big program that does exactly what you need You have small pieces that can be rearranged and tweaked with options to then make larger bigger programs So if we can think about that from our code perspective What if we could create little pipelines in our code? And we could pass data through them and then maybe pass it on to another pipeline and then another one We could have aren't like an entire web app here We could have this on the screen where our input is Maybe jason from like our front-end client or it could be a rest call an API call into our system We can process that data unpack it throw it through some pipelines and then we can we can output jason xml Whatever our response format is So if we can build these small programs like think you know We've heard microservices are a thing these small little appliances and processes that run on our network and That same idea of unix pipes and building small programs Exists at the network level This is a slide from a talk called building real-time metric pipelines And this was delivered by Samantha Kenyonis who now works at aol and she was describing their ad feedback system where they They run metrics on all their ads and impressions and click-throughs and conversions and all that stuff So they had like a nice pipeline of data of how data gets from Like feedback from users all the way through to being stored in elastic search. So this isn't just a Pattern that's in unix. It's it like all levels of our stack So let's look at how this kind of could be in code At the very top of the very first line. You'll see haystack H-array This is a library that a co-worker and I have been working on if you're in the php community His name is Eric Poe you so you may have heard or know Eric But Eric was a co-worker with me at a previous job And he's also a member and co-organizer of the Kansas City PHP group So I get to work really closely with Eric and I've seen him kind of grow as a programmer So it's been great to see him kind of come up with this idea of Haystack is basically using an array and a string and Not having to worry about the infamous haystack needle arguments for all the different functions So instead array and string can be thought of as objects So I was looking at this library for him and I thought hmm I see that this is actually pretty nice for doing pipelining. I wonder if I could make that happen So I worked with him to make it even better. So let's see kind of what this would look like this is hra or basically the code that powers hra It's essentially just an object wrapper around our different array operations Pretty simple, but when we get into Actually chaining these calls together like it shows on line, too. We get some nice fluent interface stuff So what's really great about pipelines and the way that they can be formatted here is that it kind of resembles the English language We read left to right top to bottom Code can read a little bit like English and not in the way that Like Ruby tries to say that their code is English. That's not kind of what I'm going for here It's just more of being able to reason about it in the same way that you do English And what's nice, too, is that we can plug in then our return statements We kind of can read across we can see what operation We're doing what our function argument is and know that the previous output from map here is Eventually passed as the input for reduce I think what's really great about this whole thing is what's called path to completion and this idea is something I learned from Luke Rob lusky and Luke is previously he previously worked at eBay and By proxy PayPal went on to Yahoo and is now like a product director at Google So Luke did some research on web forms and conversion rates that PayPal had back in the day So if you remember this age-old interface This is like a checkout screen where somebody needs to finally confirm that they're sending money to somebody This is a super important action in the PayPal UI But if you have to read through this page It's very disjointed in where the eye needs to track to observe and confirm exactly what you need to do so instead If you have labels aligned to the right and then their descriptions aligned to the left you get this nice pretty line That goes from the top all the way to the call to action And I think that pipelining in the way that I just showed It resembles the same thing it makes the code easy to read its uniform Things and keywords are where we expect them to be So there's the example that I showed before of where we needed to take that collection multiply by two Remove anything over nine and then add everything together A little more easy to read than that nice big nested thing we showed earlier, huh? So let's refactor to pipelines really quickly. I have another example here. So this is this is something That's maybe something you would find in like a normal PHP code base So this is actually a recorded video that I did within my editor So it's not like I'm coding this live or anything So let's start pulling some code out of this for each and see what we can do with it So we have this state that we need to keep only users that live in Kansas So we can actually instead of using it as a temp variable We can just inline it And actually we can do the same thing with the age as well So maybe for this case, we're just taking users that are 30 and living in Kansas Next we can also inline these getters for the student. So instead of breaking them out into Instance variables, we can just use the result of the function call that they have We can do that with state and then of course we can do that with age and And already that for each loop is starting to look a little bit cleaner Now we can kind of better see what the developers original intentions were They're actually just accumulating found users based on this predicate based on this if condition here So before we can actually start doing pipelining. We need to introduce our h array object up there So we're going to use Roster and we're going to now use it as this object oriented h array So now that we have roster we've recognized that this is definitely a filter pattern So we want to definitely just call filter and we're going to pass it a callback So for each item in this roster, we want to execute this callback We will receive a student object as you can see online seven or six seven eight So each one of those guys will be passed into that function and then the result Of this filter callback will then determine which Students make the cut into the into the next iteration of our callback So we can extract that if statement throw it in as a condition for our filter and then We can actually get rid of this noisy for each statement down here And we certainly don't need this found variable this accumulator anymore because we've just Pulled it out from the result of the filter Same thing with the name the name is actually just converting our student objects And extracting the name out of it. So this is a one to one mapping That resembles our map operation from before so we can map over each found student And simply return their name Of course, then we no longer need this for each statement And we can clean up the accumulator variable from names And then we need to since this is an h array Implode doesn't work with an h array by default So we can call this other method just to array where it returns the native data type array outside of h array So this is good when you need to pass it back to a function that absolutely needs one So this next operation is a little bit weird We just removed this temp variable for names and we're basically chaining this map call onto the result of the filter call I think that's the last Nope So we can instead of using roster We can actually immediately invoke our h array object immediately after it is constructed Where we no longer need this roster temp variable We can just say that the names are eventually what this pipeline is going to return So we have the collection we filter it We map it and the result are just a list of names of the students that fit that criteria And then we can pass them down to implode and use them just like we would a normal array So i'm running a little bit short on time. I think so i'm going to kind of skip through this example If you want to check slides later, they will be posted But basically there was an operation where I needed to Look through a list of directories and find all php classes that could be instantiated I'm just going to skip over it because time This is what it would have looked like if we had it broken down into The different array functions and then we can take this and put it into a pipeline So we have our list of files that are in Scander The list there we see dot in dot dot Which are actually just the current directory and then dot dot is the previous or parent directory We can map over that to return the full file name for all the files that are there Because we don't just need the file name. We need the actual full path And then we need to remove all instances that are not That are not directories. We only want the files out of this And we have an interface there at the very last part and an interface cannot be instantiated on its own So we don't want to try and Create that because it would just cause php to die out So we can actually check using reflection if that interface could be Instantiated or not and then we can return that array from there So the good news is that haystack as a standalone php library is available today You can go out to github and install it from there Or you can download the source code and include it in your project If you're using laravel You actually already have access to some really similar functions. In fact laravel has a collection object that's returned from its illuminate ORM or its eloquent or i'm sorry You can call filter map reduce and all kinds of different stuff on on their returned objects Same thing with doctrine if you're using that in a symphony application The even better news is that this week we went ahead and merged in php 559 support So instead of using php 56 which would have precluded drupal from using this I was I got here and I was like, oh wait. Yeah, drupal 8 559. Let's make that a thing So the next major version of this will have this fix in there And but you could install it today if you wanted to depend on our 2.0 branch There's so many other collection libraries out there, but they all kind of do things a little bit differently a couple of these are Ones that you might find interesting I think particularly interesting is this php ds extension if you're using php 7 This is basically a replacement for spl and the Some of the original authors of spl and some of the more performance minded people in the community have Rewritten those to be much more memory efficient or cpu efficient, but they won't ever get into php core So you can actually install them as a php extension for php 7 So what does the future of this look like? What's awesome is within the last two weeks Sarah goldman who previously worked at facebook and helped work on hhvm and their language hack It just proposed this rfc to the php community and rfcs are basically requests for comment on brand new features for the language She proposed this pipe operator, which essentially does kind of what we just showed today Where you can pipe the result from different functions to the next stage here so this is This is the actual pipe operator And then this is what's called a pseudo variable And this is the main stick point for this really right now people are very very confused and saying What other place do we actually use variable or dollar sign dollar sign? You know that you could actually use dollar sign Dollar sign name and then it's called variable variable and that would expand into dollar sign john for example This is like some crazy php stuff there, but um, so that's kind of one of the main stick points If we were to actually use this in an example that we had earlier it would kind of look like this I don't know that that reads as well as the h-array stuff that I was showing earlier because we still are stuck with variable and the pseudo variable here By basically the output From the previous stage as input to here. So we're still stuck with this Back and forth syntax argument order and I think it's not so cool I don't know if it'll get into core yet or not. People are still discussing There's also an rfc out there for arrow functions Basically what arrow functions allow us to do is to implicitly return a result from a function callback So you'll see the main difference is this guy here We no longer have a brace or a return statement. So it makes our function a little bit shorter If we were to use that it would look kind of like this Again, not a major change, but what it's trying to do is put those function callbacks onto one line Is really the goal of it so Again, I don't know if that's going to get in or not If you're thinking well john, this is all great. Um, I use this other big Legacy project or whatever. How do I actually just start playing with this? I created a composer based project where you can download it It'll have haystack already installed along with a couple other libraries And there's a test suite that's in there where I I wrote the canonical example using just array map filter and reduce And then I want you to use these different libraries to make the test suite pass So it's a good little place to play around with some of these concepts Uh, if you want some more feedback on like mental things to think about or like how I kind of started to think about these ideas There's a bunch of different stuff here as well specifically the this idea of pipelining has been talked about um by Martin Fowler the second article there. That's kind of what got me started on thinking that this was a real thing And showing it in a bunch of different languages. So that article was really influential and then um Michael Feathers is another Programmer I really respect and he's doing a talk recently called collection pipeline design techniques Kind of more like the refactoring angle that I kind of showed today So writing functional code doesn't have to be like this We don't have to write lisp enclosure to get all the benefits or some of the benefits Uh, if you wanted to go whole hog and write your entire application response In a big long function call you could do what adam wavin did and you could basically write it just like this This is the like the main code for this ci server that he has um If you had to dig into it, it would probably be making more sense, but I kind of find a little bit hard to read as is so in conclusion The next time you guys are seeing loops Maybe think of using map or filter or reduce think about your other developers And maybe that you can communicate better what you're doing Because at the end of the day Bugs can't exist in code that doesn't exist If we can push all of these variables out all these other function calls out and we can isolate it down Into small little functions that their variables can't escape the scope That we've defined It makes it easier to reason about it's easier on your brain. It's easier on you as a reader And simply just be expressive Thanks So if there are any questions Oh, man that jumped to the end of my extra slides. So if there's any questions Oh, I need to uh Join us for sprints if you're sticking around on friday They're I think most of the speakers have been talking about them so far Sprints are awesome ways to contribute back to the drupal community And there's certainly rooms for if you're a first time sprinter or a more seasoned sprinter I have a list of sources since this is a recorded talk where people can find the sources And I'll take questions. Yes, sir. Yeah, hi On the front end in drupal. We have the underscore library which does seemingly the same thing as the hra right I've seen there's a php version. Do you recommend for or against using that? I remember looking at underscore for php And I don't remember if it fit my paradigm or not I've had like 20 different array or filter libraries Kind of thrown at me over the course of giving this talk and underscore dot php is certainly one of them So I would encourage everyone to check out that list that I had or ones that you find and just find one that fits your style Find one that either fits your requirements for Your version for your php version for your personal affinity for a certain author You know just kind of go about it that route I don't know that I have one specific one Even though I've helped contribute to one that I would recommend or say use or don't use One more question How does my idea work with multi-dimensional arrays? You if you think about multi-dimensional arrays, sometimes you need to Loop over them multiple times or at different iterations. It's like a loop within a loop within a loop I would say that you would probably want to break those out into independent pipelines. So whatever you're trying to do Whatever level you're trying to do it extract an array that fits that level and then process it through And then if you have additional steps you need to do to it I guess write another pipeline for it after that Because it's about breaking those apart. We don't want those multi-dimensional arrays Like processed inside of each other for the reasons we showed before there's too many variables. It's kind of hard to read and I don't know things like that. It's always kind of hard to recommend advice for where to and how to use them So every case is different So like I said before um You should definitely benchmark your code before and after using these Operations because you will see a cpu or memory issue Blackfire io has been fantastic for me to figure out what the performance of my system has been They're not paying me or anything to say this just like I really really like it It gives you a really great gooey interface into Looking at the performance of your system. So you can kind of drill down and see what your expensive method calls are What your max memory usage was what your response time was and all that good stuff. So super useful. They have a free plan You'll probably find a really memory inefficient or cpu inefficient spot and increase the performance of your application Cool. One last question Using iterators. So If I know correctly Iterators don't work with the core array map functionality So our library within hra I don't think currently supports iterators But if you really need to get into like cpu efficient and memory efficient ways I wouldn't say the iterators are necessarily the example. They definitely can help But there's a new concept in php 5 6 called generators Which basically are just like lazy evaluation of a list So you could get to the middle of that list Let's say it's a range from 1 to 100 and you end up only needing 10 of those elements There's no reason to generate a 100 element array if you only need 10 of them So generators can help you lazily evaluate Those lists. So I haven't fully wrapped my head around how that's best useful And I know a lot of other people have including some of the libraries that I showed so Again, it's all like Performance benchmarky stuff and things like that. So yeah, unfortunately iterators don't work in core array map filter and reduce But some of the libraries do accommodate them Awesome. Thanks guys so much. See you later


Salamu alaikum. Are you guys ready to start? Mashallah you guys have been very patient. Thank you guys for being so patient So we're gonna start on our hedge adventure. Do you guys all see the map? This is our hedge adventure map I'm gonna take you on a journey the journey of a haji We're gonna use this map to kind of guide us from which area to which area we go to during hedge So today, we are gonna go on a journey of hedge It's an amazing journey that people usually only get to take once in a lifetime First before we get to hedge. We must enter into a state of ehram. Who knows what is ehram? Raise your hand if you know what ehram is Mashallah, we have a few hands To be in ehram we have to follow strict rules for clothing For an actions like no cutting our hair or our nails. Oh also no stitch clothing for men It's also very important that we make sure that there is no fighting Do you have your hedge adventure? Now it's time for us to take our journey to the camp called Mina Mina camp is also called the tent city. Can you guys find the tent city on your map? Just point to it Just point to that point to it. Do you guys see it? Do you see the minicamps the tents? That's the called the tent city. That's where we start our hedge Here we will spend the day and night remembering Allah and praying at dawn We set out for Arafah Do you guys can you see Arafah find the dotted map? You guys follow the dotted lines to Arafah. Can you follow the dotted lines? Do you see where it's taking you? Follow it. There it is. Do you see Mount Arafah right there? You guys see it? Do you see Mount Arafah? You can take one of these, but you can take this. That's the key The map key. It has all the important places on it too I'm sorry. There's no more maps. We have to share. Can you find someone who has one so we can share? Masha'Allah All right, so now we're out Mount Arafah Arafah is a very important day considered the most important day of Hajj The Mount Mercy Arafah was the scene of the Prophet Muhammad sallallahu alaihi wasallam's final sermon We pray here. We remember Allah and we make a lot of Who knows what we make a lot of? I'll give you a hint. Hajj when they're there They're making lots of da'a. They're remembering Allah. But what are the people back home doing? What are we doing on the Mount Arafah or should be doing? Praying what else? We should be fasting So even though the people in Hajj are working hard over here. We're also remembering Allah So we're fasting. We're making lots of da'a and Even though it's a very long day We have to be patient because we know the reward is great After sunset we get ready for the next part of our journey. Do you know where they're going in the next part of their Journey? Follow it. Follow the dotted lines on the map Where do we end up? What does that look like? Do you guys know what that is? If you have the key It's called Muzdalifah Can you say Muzdalifah? I need to hear that again. You see what they're doing at Muzdalifah What do you think they're doing from the picture? You guys see the picture. What do you think they're doing at Muzdalifah? They're collecting rocks good Collecting pebbles and sleeping good in Muzdalifah. We spend the night under the stars Many of us will collect pebbles here for tomorrow when we go to the Jamarat We leave just before sunrise Who knows what the Jamarat are? Can you follow the map? Throw the pebbles at the shaitan at the Jamarat Excellent. You were gonna say the same thing. Masha'Allah. Well, you both would have been right So in Muzdalifah So now that we have the stones We are ready to perform the first Rami So what he explained throwing the stones at the Jamarat or the shaitan is called the Rami Can you guys say Rami? Rami, good.  One. One pebble? Pebbles do we throw. Did you say seven? Yes, Masha'Allah. You always give good answers Seven pebbles. We throw seven pebbles at the largest of the three Jamarat The three columns This act is a symbolic stoning of the shaitan. Is the shaitan really there? Not enough, but it's symbolic that means that we're doing it because it is believed at this spot in the At this spot in Mina the shaitan appeared and tried to dissuade or convince Prophet Ibrahim From listening to the command of Allah So what did Ibrahim do? He picked some stones and threw it at him. Exactly. So during Hajj we do this too. So now today Did you guys know when I when I say one two three? What do you say? So I'm gonna try it one two three Excellent sometimes we have a lot of energy So we get kind of loud when I do that and you say Bismillah I want everyone to quiet down and start looking again, okay? Let's try one more time one two three So now we're on the next day of Hajj and did you know that the Muslims back home on this day of Hajj? This is the day after Arafah. Do you know what they're doing the day after Arafah? They're celebrating Eid Go ahead. What is it? What are they doing? They're celebrating Eid So all of our friends and family back home are celebrating usually with a big feast For us though, it's time to perform a sacrifice This is what we need to do to complete the story. Do you remember the part of the story? We're Prophet Ibrahim alaihi salam Was about to sacrifice his son, but loss went to Allah gave him a ram instead So he slaughtered that Well in Hajj we do that too.  Going around the Ka'ba and who knows what Sa'i is What Sa'i? Who knows what Sa'i is? Going back and forth between Safa and Marwa. Do you know how many times that is? So I hear ten. What else? Seven so which one raise your hand if you think it's ten Raise your hand if you think it's seven Seven is right. You guys are right. Good job. Masha'Allah you go back and forth seven times When all is finally done we return to the campsite in Minna on each of these final days We will again go to the Gemarat and throw the stones This time throwing seven pebbles at each of the three pillars And now the hardest part is behind us We will spend the next two or three days in Minna now that we have done our Hajj or we'll return to Mecca to perform the final circulation of Hajj Which is called the farewell Tawaf or Tawaf-e-Wadah Masha'Allah. Do you guys see you completed it? You go from the Zalifah to the Jamarat to the Kaaba to do the seven Tawafs Drink might Zem Zem the Sa'i and back to Minna camp Masha'Allah. You guys just completed a journey of Hajj. Thank you So now I'm gonna test you guys out because you guys said you didn't learn something Learn anything new and I don't believe that I think you guys learned a lot of new things today So I'm gonna ask you guys some questions and you guys are gonna see if you remembered anything, okay? Are you guys ready? I want to see hands. I'm only gonna answer or call on someone who has their hand raised Okay Only if you know the answer This was built by Ibrahim and his elder son Ismail as the first house of worship All right. The first hand I saw up was right here The Kaaba Excellent All right Let's see. Let's see if I can find one. That's a little bit harder.  Masha'Allah This is also known as the tent city And I'm calling out camp. Excellent Masha'Allah Well on Mount Arafah This is also considered one of the best things to do during When you're on Mount Arafah Da you perform sigh here, which in Arabic Which is an Arabic word that means to walk or strive to pursue we do this seven times You perform sigh here, but this is sigh We perform sigh here, which means to walk or strive or to pursue seven times, but that's a good guess Back in fourth Don't answer walk forwards and backwards. Where do we do it? What is it called? Where is it called? Excellent from Mount Safa to Mount Marwa Safa and Marwa good All right Where do we scare the shaitan away by throwing stones at him? The Jamarat? Excellent Masha'Allah This was the place of the Prophet Muhammad Sallallahu alayhi wasallam's Final speech Masha'Allah Beneath the stars and collect stones for tomorrow's exciting adventure. We leave just before dawn Minna can't oh, sorry. You're key for that one too. Muzdalifah. Muzdalifah All right. Thank you guys answered them all. Let me see. Oh one more We sacrifice this to remind us of Prophet Ibrahim alayhi salam's Obedience to Allah It could be any of the things I mentioned Ashif good Who knows another option? It's so good.  You know your stuff Masha'Allah The key the key to the answer So yeah Sorry come on everybody So in two weeks insha'Allah Osala Shamir will be holding a blessed Birthing workshop here about the spirituality and ficca of pregnancy. This is for all women 16 years old or pregnant not pregnant So today she's doing a primer session in classroom nine. So if you're here, maybe your husband is here if you want to Join that it's in classroom nine right by the kitchen and It's it's for from 12 o'clock till 1 30 They just asked me to make an announcement that if any sisters would like to join that you're most welcome to join that It's a classroom nine for those parents that came for the puppet show But didn't register yet for the craft session the story time you can attend But the craft session if you want to attend You'll have to do an rsvp real quick you can do that on your phone And the way to do that is to go to mccesb.org for its slash rsvp hyphen crafts Sister shaz is there in the lobby she can help you with that as well. Sorry to interrupt All right insha'Allah you guys have been great. That was an excellent hedge adventure now We're going to start our story time. Do you guys want to start our story time? No story time You guys just want to skip and go straight to the craft You guys have learned so much about hedge that after hedge what happens It's a read so our story time because we won't be together next week Is all about reed Who knows what this read is called adha.  It's called raising their hand Answer because it's the the reed that we slaughter an animal to remind us about the story of prophet ibrahim aleyhi salam. Good So today i'm gonna read a book. I'm gonna read two books. Insha'Allah. This is the first book It's called peg and cat the eid al adha adventure So what I do for anybody who's new here is I will read the book But then I will make sure to show the page to everyone So if you're sitting kind of far, I'll try and do a little bit high But everyone should get a turn to see the page So if you can't see it when i'm reading it, don't worry insha'Allah I will make sure to share it with you all So the first book peg and cat the eid al adha adventure By jennifer oxley and billy erin sun Can I put it on the floor? Bismillah Peg and cat were visiting their friends. Yesmina and amir during a very special holiday Adha a holiday. Yesmina and amir celebrated every year Peg and cat had never even heard of eid al adha Until yesmina and amir invited them to the celebration to check it out We're gonna make your first eid al adha the best ever said yesmina Let's rock out said amir. They said they saying amir here and yesmina the machina Rocking the house just like rocking the arena Got my new tie and jacket saying amir Got my best his jab said yesmina Got my suit cat said has a scarf on saying peg. I'm no slob Saying cat actually a cartoon show too. You can watch the episode It's on pdskids. Yeah Eid al adha is really fun said yesmina. There are presents and lots of food But mostly said amir. It's about giving to those with less I like the presents and food said cat, but giving stuff away. How is that fun? You'll see said amir Peg drew pictures of plates with food on them to remind cat why eid al adha is really about This sign means less. She said this one means more than I like the more sign better said cat Amir played his stringed instrument called an aude. Yesmina played her electric guitar Peg and cat played ukulele and drums as their hosts sang about the holiday Eid Mubarak means happy holiday. So we say eid Mubarak as we celebrate On eid al adha even tat is going to see how awesome giving can be We'll see if I see said cat Time to go to the celebration Every year we bring this silver tray. Yesmina explained filled with almonds olives apricots and I love apricots and peg Then let's add more said yesmina Are those honey cakes cat asked Should we yesmina added more said cat more more. Do you think cat likes the honey cakes? Yeah, I think so too An important tradition said amir is dividing the meat into three equal parts When you have three equal parts of something each part is a third said peg We keep one third We give one third to our neighbors and we give one third to share to with someone with less Less what asked cat Well food or clothes the basic stuff that everyone needs said peg We have divided the meatballs into three parts Um The three bowls all have different amounts of meat amir said peg But I put the same number of meatballs in each bowl said amir But the meatballs are different sizes though If we don't divide the meat into three equals parts, this won't be the best read ever We've got a big problem Peg noticed cat playing with a pair of small swinging pans That's it. She said the pan balance. Do you guys think you could help them with their problem? It's not a problem. Why why is it not a problem? There's two two and two so isn't that fair No, why is that not fair? Because this one has tiny meatballs and this one has humongous meatballs But it's the same amount But they don't have the same amount of meat in each okay Let's see what they do Peg put one pair of bowls on the pan balance This pan goes down because the bowl on it has more meat. It's heavier. She said But we can take from more and give to less said amir until The pans are the same levels said yasmina The meat in the bowls weigh the same. How do we know they weigh the same? What's it showing us? An equal sign The Peg replaced one bowl on the balance with the third bowl Those weighs the same too. They all weigh the same Problem solved a mubotic said cat Not not the end the group headed out for the party But first they had to drop off a third of the meat to someone with less We've come to the soup kitchen Because the people who eat here have less said yasmina At the soup kitchen they can each get a good free meal As the door to the soup kitchen opened amir said it's run by Ramon Said peg Cat took the bowl from peg and handed it to ramon. We hate to run and eat But we have a party to go to he said I almost didn't show you guys the picture Said ramon, I really need your help with There's a man who lives in that building across the yard He's always comes here for meals, but today he hasn't come I wonder if he's sick or if those crates of canned food That were just delivered are blocking his way Really big problem See what they do in order take out ask cat No said peg today's about giving we're going to give We'll cross the yard with the meatballs the crates were piled so high Cat wondered how they would ever get past them Let's count the crates To find the piles with less said yasmina. They'll be easier to step over So what is their solution? What are they going to try and do? Yeah, so they're going to count the crates to see which ones have less to see if those would be easier to step over They stepped across a pile that had only one crate and another pile of two crates One is less than six said peg and ten is more than two said cat But there were even more crates to get past yasmina and amir were Totally freaking out Cat held up his paws cat's right said peg you should count backwards till you calm down We'll count from seven said yasmina. We like seven seven days of the week seven colors of the rainbow What else has seven? What did we learn today? We do seven times Seven stones for jamarad Seven times to offer on the Kaaba It's seven times a seven So let's all count down from seven. Can you guys count down with me guys? As they counted cat gazed at those juicy meatballs He was about to take a bite when peg shouted That's it. That's it. That's it. You meatball loving cat. We'll divide the crates into thirds Just like we did with the meatballs. That'll be easier to move Problem solved They're gonna make the big crates smaller When peg knocked on the door she heard a familiar voice invite them in Mac s pig i've had some bad luck mac explained I usually go to ramon soup kitchen for food last night. I stubbed my toe and this morning I stubbed another toe. I'm not going any place You don't have to said yasmina. We brought you meatballs Mac was so hungry That he ate the meatballs quickly and then for dessert a mirin peg offered him olives and apricots Cat wanted to keep the honey cakes for himself But he remembered that either the adha is about giving to those with less So he took the tray over to mac Would you like a honey cake asked cat ass? I love honey cakes Said mac cat gasped Hey, giving does feel good You're all so nice said mac. I don't know what to say I do said peg Eid mu bara Eid mu bara That was very nice lesson for peg and cat to learn about eid al adha. What do you guys think? So what did we teach? What did they teach? Uh Peg and cat. What did they teach them? What should we do with our meat on eid al adha? How should we do it? How should we divide our meat on eid al adha? So we talk? Hold it, okay One two three So we learned in hedge that we slaughter a sheep or a goat or a camel right one of those animals So now what do we do with the meat? What do we learn from peg and cat that we do with the meat? We divide it into three parts. Do we keep all three parts? We keep it all I don't know about that That would be greedy What should we do with the three parts that we that we do? We have one third to our neighbors One third to those who have left and then we keep one third for ourselves Alhamdulillah All right, masha'Allah. Do you guys want to do one more book? Honestly, no Yeah, let's do it Let's do one more book One more book masha'Allah, and then we'll go to the craft I think you guys can handle it.  Okay, and get some shaking out Everyone shake shake shake some of that Trust me after sitting all this excited to go and eat some of those cupcakes It's called the best and this is by esmat mubin udin. Are you guys ready? Before I start a book. All right. Anise sat in her bed looking out the window Her parents were away at the Hajj pilgrimage and she missed them Saudi Arabia was so far from her home in America She thought about last Eid's holiday when she had worn her shawar kamis with flowery orange hinnah designs on her hands Daddy had said she looked just like a princess Mommy had left her eat let her eat candy for breakfast They all went to Eid prayers together and then visited friends all day But today the house was quiet Just then anise's grandmother bustled into the room So it sounds like her aid this year is going to be very different than last year We'll see maybe it'll be worse. Maybe it'll be better. We'll see Anise happy Eid Nani sat on in the bed and greeted her granddaughter with her granddaughter with a big hug and kiss Time to get ready for prayers Anise returned the hug and then slumped back onto bed Why the sad face my dear nani gently brushed the hair out of anise's eyes. Do you miss mama and baba? Anise nodded. She felt like she might cry I know it's hard without your parents here. Nani said, but please don't be sad today of all days We'll have fun together. Just you and me. Okay Anise tried to smile. She didn't want her grandmother to feel bad Okay, she said as nani stood up and walked over to the closet Now I have a surprise for you Nani lifted up a blanket on the closet shelf and pulled out a gift wrapped box That had been hidden underneath Do you guys see the gift box that was hidden underneath? What color is it? It kind of looks red to me. It looks like pink Right We'll say reddish pink with a purple ribbon Anise pulled the ribbon off the box and opened it her eyes lit up As she saw the beautiful Eid clothes from pakistan Pulling out the kurta on top She ran her fingers over the soft shimmering fabric and its gold embroidery and shiny sequins Purple and gold vangals clinked together as nani unwrapped them Hand made pakistani shoes Tucked in tissue paper still lay in the box Nani, I love my new Eid clothes. How did you know that purple was my favorite color? Thank you Anisa hugged her grandmother. I can't wait to get dressed There's still more nani said smiling as she pulled a bright red Shalu al kameez and a silky yellow Gharaha out of the box Each outfit had matching bangles and shoes There are three sets of eid clothes one for each day of the three days of eid Which one do you want to wear for prayers this morning? Which one do you think she's gonna pick the purple one? Yes, because purple is her favorite color The purple one nani smiled. It will look beautiful on you I'll iron it while you're getting ready. But first I have to sir the lamb kurma That sounds yummy Lamb kurma Anisa jumped out of bed and ran to the kitchen The aroma of her favorite dinner cooking on the stove made her mouth water Please can I taste some nani scooped out a spoonful of bubbling lamb curry Blue on it made sure it wasn't too hot And then gave Anisa a taste Anisa's savor the salty spicy curry in her mouth. Yum. It's good I'm glad you like it. Now. Let's hurry and get ready. So we're not late for the prayers That sounds good. I'm kind of hungry, but you guys So that sound good. You didn't like it Sometimes we like something when we try it. Sometimes we don't it's very important. We always try something, right? So you never know At the prayer hall the imam gave a sermon about the hedge pilgrimage And nisa had a hard time paying attention because she kept thinking about her parents and wishing they were there After the sermon ended the women and children in the women's section of the prayer hall Folded their prayer rugs and greeted each other and nisa hugged so many people The donuts on the back tables were quickly finished Is there usually donuts when you guys go to the message at all night? No When we we came from Tampa, Florida and every eat we go that's covered in donuts everywhere So it's something that we remember Outside the prayer hall because we don't want to make a mess in the prayer hall, right? Anisa noticed two young girls standing alone watching the excitement around them the older girls hijab Do you guys know what the hijab is? The scarf we were in our head. Yeah, the older girls hijab was torn The younger girls dress fell almost to the floor and she kept her arms bent So her sleeves wouldn't slip down over her hands Anisa walked over to them Why didn't you wear your eat clothes today? She asked the older girl stared shyly at the floor Seeing that her sister was not going to answer the younger girl blurted out We don't have no clothes to say we have to leave all our stuff and run away because our fire burned down The older girl turned towards her sister medium. We have to be thankful. The war can't get us now We are safe and we are together Papa says a law will give us whatever we need I wish bobo was here with us now But ever since we came to america. He always has to work medium told anisa. He even had to work on her eat But later he's going to bring zanab and me candy and we're going to go to the message together for the afternoon prayers Before anisa could say anything auntie salma pulled her into a big bear hug Anisa beti eid mubarath. My dear happy eid. You look so pretty.  Okay Anisa was swept up by other aunties and friends and hugs and kisses and greetings while hugging auntie barak Anisa saw medium pick up a piece of doughnut off the floor The girl looked around quickly and then she put the doughnut piece into her mouth and licked the sweet glaze from her fingers Why do you think she took it off the floor? Maybe she was really hungry and there wasn't any more That's a good reason that we shouldn't take too much, right Even when we have a lot of something we should only take one or two so that we can make sure everyone gets on right As people were leaving the prayer hall anisa kept looking back at the girls Finally, she let go of nanny's hand and went back over to them. She didn't know what to say But she couldn't leave them without talking to them again Hesitantly she asked them. Maybe we could play some time together Instantly medium's face lit up. Sure. She said Uh with a flashing bright smile Xenob continued to look at the floor Where um, where do you live now? Anisa asked In the apartments by the mosque medium answered Xenob lifted her head to look at anisa a small shy smile Crossed her face in number 63 A motherly woman ushered her three children and Xenob and medium out of the prayer hall that afternoon While nanny was heating up the food for dinner anisa told her about the girl she had met nanny listened quietly Sometimes when family leave their home leave when families leave their home because of war or other bad problems They have to leave everything they have behind nanny told her Many families have come to america as refugees Looking for a safe good place for their children to live and grow up Does Allah help these families? Of course my dear Allah helps everyone nanny was stirring the curry, but sometimes not in the way you might think He might send good people to help them through bad times Meanwhile, the families have to work hard and trust that Allah help Allah's help is always near Nanny opened the open the oven door to check on the roti Do you remember the story of prophet ibrahim his wife hajir and their baby ismaeem? Anisa nodded Mommy and daddy had told her that many of the lessons of hajj pilgrimage were based on this story Prophet ibrahim's family trusted in Allah Even in very difficult times and Allah always took care of them Nanny and anisa said a prayer for xenob and medium's family Then anisa told nanny about a plan she had made So anisa made a plan Do you guys want to see what anisa's plan is? Afternoon as shadows lengthened across the city Muslim families were leaving them as soon after the prayer of aah said prayer Anisa sit quietly anisa sit quietly someone will hear you Nanny whispered to her granddaughter as they crouched behind the bushes outside the apartment building next to the mosque Here they come duck down Through the leaves they saw the two girls and a man stop In front of the decorated baskets near neatly arranged on the cracks tube in front of their door What's this? In surprise the man read the attached card happy eid to medium xenob and their papa Anisa felt as if she must might burst with excitement Would they like the presence xenob and medium opened the basket Wow Beautiful beautiful clothes. Look at the sparkles on this yellow shirt I can't believe this the man said softly lamb and chicken rice and vegetables Even desserts and candy Who could have left all this? Papa help us carry the baskets inside medium was trying to drag a basket across the sidewalk Put them down girls. They're the father commanded. We don't take charity. Let's see what happens their father paused Then medium asked softly But can I keep the yellow clothes? I love yellow And and what about the sparkly bangles? No, my dears. The father spoke again. You know that a muslim does not beg from others But but papa we didn't ask for them zana pointed out papa didn't budge I will provide for my family. There are other people who need this food and these clothes more than we do now. Let's go Can I just eat this cookie right now? Anisa could hardly breathe. What if they didn't take the gifts as she leaned forward to see better a twig snapped And she fell down And she ducked down What's what was that noise the father asked as he turned around to face the bushes Anisa and nani ducked as his heavy footsteps approached their hiding space Are they going to be found through the leaves anisa could see the man's Stern features and firmly set chin coming towards them Hidden behind thick eyebrows were soft gentle eyes In these eyes anisa recognized the same look of tenderness.  He knelt on one knee and opened his arms The girls wrapped their arms around him and medium climbed onto his knee Papa, there's more food here than we need. She said small fingers gently touching his cheek Why don't we share it with the neighbors and please can we keep their clothes? Please as zana Anisa saw the man's face soften as he drew his daughters close to him as he hugged them He nodded and he smiled at anisa and nani through anisa and nani returned home Nani picked up the phone and dialed. Hello. I'd like a medium vegetable pizza.  I have never had her eat like this one Me either anisa said I can't wait to tell mommy and daddy all about it Later in the evening as anisa and nani snuggled up on the couch and ate pizza for dinner They both agreed this has been the best feed ever I am very very very impressed with all of you guys You made it through a puppet show through a hedge adventure and two stories You guys give yourself a round of applause Now are you guys ready and excited to do the cake decorating? Yes, let me show you what it looks like again Bismillah I have the cupcake boxes with all the on the table and me and the volunteers will help you If you guys need any help, but parents there's a video tutorial that gives step by step There's a video youtube Tutorial You can watch step by step and then we'll have the sample over there for you guys to see But the video shows step by step. It's very simple and i'm going to be there to help you as well So i'm going to meet you guys all in the back. You can get set up at the tables