Page 224 -
P. 224

associate custom code with custom data














                                              Wait a minute...you’re using a dictionary to
                                              keep your data all in one place, but now you’re
                                              proposing to write a bunch of custom functions
                                              that work on your data but aren’t associated with
                                              it. Does that really make sense?










                                            Keeping your code and its data together is good.
                                            It does indeed make sense to try and associate the functions with the
                                            data they are meant to work on, doesn’t it? After all, the functions
                                            are only going to make sense when related to the data—that is, the
                                            functions will be specific to the data, not general purpose. Because this
                                            is the case, it’s a great idea to try and bundle the code with its data.
                                            But how? Is there an easy way to associate custom code, in the form
                                            of functions, with your custom data?




























           188    Chapter 6
   219   220   221   222   223   224   225   226   227   228   229