As mentioned in other posts I started following the 100 Days of Code Python Bootcamp course on Udemy to see if the beginner section was interesting for my teenager son to follow. The beginner level ended on day 14 of the course and covered all the basics of programming. Day 15 was a recap project to apply everything learned so far and days 16 and 17 gave an introduction to object oriented programming and using and defining classes in Python. This is quite a big switch in programatic thinking to go from functional programming to object oriented programming. On day 16 we rewrote the program created on day 15 using supplied custom classes. The main challenge was to apply the existing classes by reading the documentation and optionally browsing through the code. This is basically what you are doing all the time in Python, maybe without realizing it, when you are using one of the packages written by others. I of course made it difficult for myself by doing the opposite of instructed and reading the code and only glancing at the documentation. As the syntax to define classes had not yet been introduced this was not the best approach but I kind of figured it out none the less. There were some obvious benefits to the OOP style even for such a simple dummy project. Day 17 introduced the syntax to create your own classes and applied this to a quiz project: class definition and the dunder init constructor, self and so on. Again, the project was very simple and could have been done with functional programming as well. The project used a list of dictionaries with questions and True/False answers and at the end it got extended to using data imported from the Open Trivia Database. Here the power of OOP really became obvious as the structure from the Open Trivia Database was a JSON format that could be relatively easily converted again into a list of dictionaries. But dictionaries with more and differently named keys. Because the project used objects, it was a super easy change of 1 line in the code to use this new data format. Of course, a functional program could have been modified quite easily as well but with objects the details become in a way irrelevant, you simply need to know what the attributes and methods of the objects are and that is all that there is to it. The quiz project was very rudementary but a few ideas and pointers are probably useful to go into the Quizlet type of app I am considering to write for my son. I am not pretending my own app will beat Quizlet but it will come without a subscription fee and customisable where desired.
Leave a comment