Page 225 -
P. 225

custom data objects


           Bundle your code and its data in a class


           Like the majority of other modern programming languages, Python lets you
           create and define an object-oriented class that can be used to associate code
           with the data that it operates on.




                                        Why would anyone
                                        want to do this?



                                        Using a class helps reduce complexity.
                                        By associating your code with the data it works on, you reduce
                                        complexity as your code base grows.




                                                                     So what’s the big
                                                                     deal with that?



                                        Reduced complexity means fewer bugs.
                                        Reducing complexity results in fewer bugs in your code.
                                        However, it’s a fact of life that your programs will have
                                         functionality added over time, which will result in additional
                                        complexity. Using classes to manage this complexity is a very
                                        good thing.





                                         Yeah? But...who really
                                         cares?



                                        Fewer bugs means more maintainable code.
                                        Using classes lets you keep your code and your data together in
                                        one place, and as your code base grows, this really can make
                                        quite a difference. Especially when it’s 4 AM and you’re under a
                                        deadline…





                                                                                      you are here 4    189
   220   221   222   223   224   225   226   227   228   229   230