Page 393 -
P. 393

localize functionality





              Functions inside of functions inside
              of functions inside of functions...
              now, that‛s what I call complexity. Of   Frank: A function inside a function? Surely that’s not legal?
              course, everything‛s local, you know.
                                                     Jim: Well... it depends on the programming language.
                                                     Joe: Don’t tell me this is something that only works with Python?!?

                                                     Jim: No... there are lots of programming languages that allow you
                                                     to put a function inside another function.
                                                     Frank: Name one (other than Python)!

                                                     Jim: Pascal.
                                                     Frank: Pasc... what?!?
                                                     Jim: Look, it really doesn’t matter which programming language
                                                     supports this feature. What is important is that we can do it.
                                                     Frank: And by “we” you mean “Python.”
                                                     Jim: OK, yes. Python can do it.
                                                     Frank: That’s all I was trying to say...

                                                     Joe: So, this is cool how?
                                                     Jim: Because it lets you localize functionality and handle complexity.
                                                     Joe: What?!?
                                                     Jim: Look: if a function gets big and complex, it can help to break
                                                     the function down into a collection of smaller functions, just like we
                                                     do when programs get big. We can keep the functionality local to the
                              Frank                  code that needs it inside the function. That way, we keep things as
                                                     simple as we can
                                          Joe        Joe: Even if the code itself is complex?
            Jim
                                                     Frank: Like the GUI-building code we are working on now?
                                                     Jim: Yes.
                                                     Frank: OK. A function of functions it is, then. I’m all for keeping it
                                                     simple, stupid. ;-)
                                                     Joe: Yes, I like KISS, too.
                                                     Jim: Yeah... their last album was really something special, wasn’t it?

                                                     Frank & Joe: Eh?!?





           358    Chapter 10
   388   389   390   391   392   393   394   395   396   397   398