Showing posts with label popeye. Show all posts
Showing posts with label popeye. Show all posts

Tuesday, May 5, 2015

Delegation take Two

I have to blog this RIGHT NOW because I totally understand Delegation. It only took seven weeks, but it makes a ton of sense. (I wrote this a week ago and am just getting around now to posting/editing it)

Remember how I was saying that there are a billion metaphors about delegation? Supposedly it's because something different will click for each person, but I have a theory that it's because people are terrible at explaining things. But never fear readers! I will set you straight and tell the entire coding community the right way to explain things. (because ya know, I know everything <--- this is is tongue in cheek)

Remember my Popeye and spinach metaphor? That is still apt. But let me tell you why it wasn't complete and then explain the metaphor that made all the other metaphors make sense. In my personal explaining metaphor, Popeye gets 'superpowers' (more methods) that allow him to do all sorts of super cool things. This is essentially what happens, but it's also not what happens. Prepare to think real hard dudes.

There are two really confusing things about delegation.  And a couple things with the Popeye metaphor that were incomplete. Popeye doesn't just get superpowers from the spinach. He opens a connection to spinach world where he gets superpowers. Those powers are still in spinach world, but because of the connection Popeye can access them.

The first confusing thing about delegation is the word itself. Because in delegation there is something called a delegate, and there is something that has a delegate method. Now this second thing doesn't have a name, it just has a method in it. (I'll explain why later)

Now you're going to want to call the one with the delegate method in it the delegate, right? WRONG! The thing you have to keep in mind with delegation is that it is essentially a connection between two things.  The one that is the delegate is the one that gets the response/info. I bet that last thing I said made no sense (because it doesn't), so let me go into detail.

Remember when I was talking about segues? I probably mentioned (or should have mentioned) that we have to use segues and delegation because different views and different objects on a view don't talk. Now if you are familiar with iOS, you might say, "BUT JEN, BUTTONS KNOW WHEN THEY ARE PUSHED". which is true. when you touch a button, it sends a message, which means it's probably using delegation (Boom. mind blown).

Some things in iOS already have features built into them that utilize hard to get concepts. So you don't really have to think about why a button sends a message, you just know that you can utilize it to go to a new screen or have something happen.

But if you break it down, the reason you're able to do stuff with buttons is because they send a message. So now you realize that you need to send a message between two things. Like I said before, unfortunately things don't communicate with each other unless you tell them too.

(I also think this is the core part of computers that people don't get. Computers don't know how to do things until you tell them. We've developed tools to make them more person intuitive... but they still are just using numbers to do things. Remember, the computer is a baby and doesn't know anything until you teach it or give it tools/skills/person attributes).

Now I'm off topic. Ok. The delegate and the thing with the delegate method have a relationship. For example, say we have three things, a house with a fancy number pad door, an atm, and a calculator.  All of these things share something in common: a number pad thing. That number pad thing is NOT the delegate. It is the one getting the messages and the numbers and the fun. The house and atm and calculator just need to know what keys are pressed when they're pressed. The number pad has a method that says what key is pressed.

so if the number pad thing isn't the delegate, what is? In this example, the house, atm, and calculator can become the delegate. That's right people! something can have multiple delegates!

In the process of writing this, I've confused myself. So let me set myself straight. The thing with the delegate method in it doesn't have a name because it can be anything. It can be a dog, or a view controller, or a piano. The delegate is what needs to know the info that the dog or view controller or piano know. Because like I said before, nothing in the ios landscape communicates.

(maybe they should see a relationship counselor... har har har).

So recap. I know when my toe gets stepped on. whoever stepped on my toe needs to know when that happens. So when my toe gets stepped on, I punch the person who stepped on it. The person I punch is the delegate. They receive the message that my toe is hurt.

Yea, the language of it is so stupid. I mean when you delegate something, you give the work to someone else. Since there is no noun for delegate, they don't call the person who pawns off the work anything. We should change that.

This is long and a little bit circular.

Here are the points that you should remember.
1. The language of delegation is hard. This is because anything can have a delegate method and anything can be a delegate.
2. Delegation is a connection between these two things. The thing with the delegate method gets a message and then sends it to the delegate. This message can be as simple as BUTTON WAS PRESSED! or as complicated as a complicated thing.
3. Setting the delegate (another confusing word thing with delegation) is essentially just telling the connection what it's between. So you tell the starting point that they are the delegate and the ending point that they are the delegate.

The metaphor that made sense? Delegation is a tunnel. Setting the delegate is just telling different things where the tunnel entrance and exit are. Then they can send things through the tunnel.

I finished my shawl. More knitting content tomorrow!

Thursday, March 19, 2015

Delegates make me all philosophical. also shawls.

Even though I should be super frustrated, I am still super enamored with Mobile Makers. They've been giving us harder and harder projects and I'm still understanding. Which go me.

Anyways, remember how I was all like, "oh yea, segues are so easy, I am the best at them." I may have to amend that statement. I do get the general concept of them, but those paired with delegation make me a little iffy.

Delegation you ask? Yup. It's just like it sounds. It's when something makes something else do a task.... well sort of. It's actually super complicated and I'm just starting to wrap my head around. I'll probably post a clearer example once I start fully grasping it, but for now let me just give it my college try.

You have to use delegation when you are doing something in a different view  (or a different file) and want to know about it outside of that view (/file). I think it's a way to add more methods (making objects do things) that is cleaner and easier to break down. Some of the common objects we use all the time (view controller, table views, text fields) have delegates. These are already defined but generally I think of them as access to a level/power up. So with the objects 'built in' to objective c we can already do a  lot of stuff, but if we access their delegate we get to do ALL of their stuff.

Like Popeye. He is already a pretty good... sailor? Not really sure what he is. But then he eats spinach and he can do so much more stuff! Like knock people out... and other stuff. I'm not really up on my Popeye it would appear. But delegates are like spinach. We call them on a class and BOOM we can do way more.

From what I can tell, delegates are usually used when something is clicked or pushed and you want it to do something.

Phew. Right? That was all yesterday. We learned about delegates last week but yesterday we had to really learn them to build an app that basically just shows a different collection of tigers and lions when a corresponding button is clicked. WHICH IS SO MUCH HARDER THAN IT SOUNDS.

I think that's the main thing I've learned is that things that seem really easy are actually super complicated. I guess it makes sense because we think swiping to go to a new page makes sense, but we first had to learn how to see, how to make our finger move, and associate certain movements with certain results.

Think about being a baby. You didn't know anything as a baby (contrary to the movie Baby Geniuses). I was blown away a couple weeks ago when I learned that babies can't even recognize shapes until a couple months old. I mean that's why it takes so long to walk. Think about how complicated that is. But you don't even have to because your brain does it automatically.

Programming is making a brain. 

Ok.... you can tell I'm excited and into this right? So i'm going to be even nerdier right here. Because you know writing about knitting isn't nerdy enough.

I've always been fascinated by the brain. I've always been fascinated by philosophy and why things are how they are. And it turns out the programming is literally both of those.

Let me explain about the philosophy thing. (because the brain thing is explained up above sort of)

Philosophy takes abstract things and tries to make them concrete to be able to manipulate or solve problems. (I just blew my own brain writing that. I sound so deep and insightful)

Programming is wanting a computer or phone to do something. In order to do that, you have to conceptualize a lot of stuff. You have to break down the task into different actions and parts. You have to translate that into words (the programming language). And the programming language is telling the computer what ones and zeros and numbers to fire in order for it to accomplish things.

Why yes I am a little iffy on how programming languages and computers interact. However did you guess?

I realize there is no knitting here... but I am on the death marathon part of the shawl. For those of you unfamiliar with knitting, it's when you literally have a row that is 300 stitches and you have to add four stitches every other row in order to get to 400 stitches. You don't get a lot knit vertically and so your brain is like, "UGHHHH I just did one row and it took fifteen minutes and I have so many more of these".

Speaking of knitting... it might be time to switch to a sock as my portable project.