Creativity. Reflection 2 - Refactoring CAS Manager
Table of Contents
DISCLAIMER⌗
The version of the program I talk about in this blog post concern GitHub history up to this commit. Later, I discovered that I couldn’t improve anything with the code that was there. Therefore, I dicided to abandon it and write the program from scratch. Considering the effort I have put into this, I have made it my Computer Science Internal Assessment. As a result, it is no longer part of my CAS. I have started other projects that replace this one.
Decisions made so far⌗
Before going further
let me introduce some concepts for a better understanding. In computer science, there’s a notion of cognitive complexity
. It basically refers to the complexity of a code in terms of its readability. In other words, it’s a measure of how threatening your code is for the sanity of another party, maintaining this code.
But what does maintenance refer to? Well, low cognitive complexity yields improvements in areas such as debugging, optimization, future development, team work efficiency and many others, equally important. For me, however, low cognitive complexity proves crucial because of its two major aspects. First, it makes the process of extending the app easier and, second, it will help me to go global as I intended to. (see “Plans for the future section”).
Progress so far
import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Having described the background, I shall discuss the progress made so far.
First of all, I started refactorization by splitting up my program into different files to at least reduce the size of the original file. However, this quickly turned out to be almost impossible. I succeeded only with moving some functions. The good thing though was I eventually realized why this was impossible. Namely, my initial approach required very high dependency between parts of my code, so they couldn’t be easily separated.
To tackle the issue I began removing the responsibilities from functions and making them more generic. As I was gradually applying the above principles to my code, the benefits started showing up. As of this moment, it’s become easy to put, the now-distinct, pieces of the program into their own files. I didn’t go for that after all (i.e. creating separate files) because I had found out that the then methods were too simple, too “newbie” - even though now they were more generic.
My focus has switched therefore to the way I insert students and classes into the database. What I gave a go in this context were classes
. Class is a concept derived from so-called object-oriented programming. It is a template for creating an object. Moreover, a class (and objects it creates) has attributes (that store data, e.g. student’s first_name, surname, URL and class_name in my program) and methods (that provide behaviours, like “insert_student”). The advantage of a class is its preciseness. For instance, NewStudent class deals with everything that is connected with managing a student. Isn’t it as plain as day?
To summarize this part, I am putting my effort into removing the responsibilities from functions and into making them more generic as well as into replacing current methods/approaches with better ones.
Plans for the future⌗
Apart from improving the way how I develop the program, I also have plans what is going to develop. As mentioned in the previous section, I aim to make the process of extending the app easier and to make this app global.
In the first place, I want to shift focus toward extending the program. New features will include changing a theme
and choosing a sorting option
. The former is less important and addresses individual preferences of the user. This is because the default look of widgets is unarguably boring. I’ve learned, however, that I can incorporate ready-to-use themes into my software. Furthermore, these themes are usually available in two color versions - white or black. I can take advantage of that and enable the user to choose in accordance with his/her preferences. The latter is crucial as it not only provides greater convenience, but also changes significantly the overall appearance of the app. I plan to give the user opportunity to select the order in which classes and students are displayed. However, it affects the deep design of my program so it has to be cleverly planned.
Another aspect is serving the global audience of IBDP. After talking to my CAS coordinator about the program, I thought about sharing my work with a broader audience. If one CAS coordinator has a certain problem, so does another, right? Based upon this reasoning, I made attempts to give the software to others. Before sharing however, I wanted to invite other people to develop this program. To do so, I needed improvements described previously. I’m working hard to eventually post my program here: the unofficial subreddit for all things concerning the International Baccalaureate.
That’s all I’m planning now.
The complaint of a coder⌗
This is the moment to share my thoughts about the process.
As times goes by, I do see improvements being made. Applying the above-mentioned techniques comes with a great benefit
as the program gets less complicated. Admittedly, these are small things
, however, it’s undoable to have all things done in two evenings. Nonetheless, no matter how wise a man is, sometimes his own ambition overcomes him and the process is damaged by such mishaps. This has happened to me several time.
A case in point could be the missing letter “i” in the initializer of a class (initializer is a method that lets you set some initial values for a class). My IDE (place for writing software) gave me the following hint: __int__
. However, an initializer is indicated with __init__
. You don’t see a difference? Pay close attention to the spelling and you’ll see a “minor” mistake. This flaw made me furius and caused the whole program to crush. After its discovery, I felt a mix of relief (everything suddenly worked) and madness (I believed it was a problem with the design!).
All things considered, I should be less outcome-dependent for my own mental health, I suppose. All in all, I have chosen a path and prepared a plan, therefore, I am confident that I’ll achieve my goals.
Learning outcomes:⌗
- LO 1 Strength and Growth
- LO 2 Challenge and Skills
- LO 3 Initiative and Planning
- LO 4 Commitment and Perseverance
- LO 5 Collaborative Skills
- LO 6 Global Engagement
- LO 7 Ethics of Choices and Actions