SHARE:
Uncategorized

5 Metaphors for ‘Yield’ (My First Semi-Technical Post)

Flatiron School / 18 June 2013

The following is a guest post by Desmond Rawls and originally appeared on his blog. Desmond is currently a student at The Flatiron School. You can follow him on Twitter here.

Recording with a light-second delay from basecamp at Mt. Ruby where all the rocks are gems and all the gems are mountains aka the origami enchanted forrest aka the blank screen wrecking yard aka the wind sock between your ears aka the Grace Hopper appreciation society aka the Sandi Metz support group aka the solar-powered confidence summer jam aka The its-not-about-computers School aka the Flatiron School

‘yield’ is a keyword that appears in a method to turn over the reigns to a yet-to-be-determined block of code. You add the block when you call the function. It can be any block you like.

Trivial examples look like this:

image

image

image

-OR- With a method that takes an argument:

image

image

image

These are trivial examples because they could be re-written with no added key-strokes as:

image

image

-AND-

image

image

The interesting implementions of the ‘yield’ keyword involve methods with more logic. For example:

image

image

image

image

That’s ‘yield’ in action. ‘yield’ allows you to, on the fly, add a bit of custom logic to your methods. It might feel like a slippery concept because it is. For people that learn from metaphors I came up with 5 that might help:

1. ‘yield’ is the settings on your microwave. Like on mine i have “time defrost”, “auto defrost”, “reheat”, “cook”, “popcorn”, “pizza”, and “beverage.”

image

2. ‘yield’ is the attachments on your kitchenaid food processor.

image

3. ‘yield’ is AutoTune.

http://desmondrawls.github.io/audio/chipmunk.m4a

http://desmondrawls.github.io/audio/vader.m4a

4. ‘yield’ is tinted sunglasses.

5. ‘yield’ is that trick play from Little Giants.

5 Hacker Habits with Guest Speaker Emily Stolfo Previous Post Ruby Testing Next Post