End of June - Refactoring Continues

Big refactoring progress today. Now the project starts up following a huge refactoring effort, but I now need to fix run-time errors and review the code.

I simplified some Parts that had fancy features such as pressing a button shortly after it was dropped into the Graph to set up the number of IO pins. Now the pin width is fixed to 8 or 16 bits depending on the Part variant that is chosen.

Also, the code was simplified, stripping out things that were in hindsight, not needed such as types of pin e.g. high impedance, input or output. This is taken care of naturally by the way that connections are allowed.

A great improvement made was to create an inline class in the Part class to define the characteristics of a pin rather than having separate dictionaries of pin info. Before I was checking if the dictionary had the pin index and then setting or getting the data value. Now, at setup time of the Part, arrays of Input and Output pins are set up.

When refactoring code, we want to make it simpler, more modular, and easy to understand. We should clearly be able to understand what everything is for and how it works. Sounds kind of obvious, but it is easy to churn out code and later come back to it with no idea how it was meant to work without taking great care to name things well and keep things well organized.

I removed all the ENUMS that were used in match statements and if statements to modify behavior according to types of Parts. Now every Part extends from Part and other Parts. Of course, there are many more script files now, but that is not a problem since they are grouped in a directory and are well named.

My idea for using Composition to add the Bus functionality to objects was abandoned since I now have extended objects for every Part and the common Bus functionality consists of one custom function which I call set_value which sets an integer value of the Bus data value and emits a signal when this value changes. So there was no need for a separate scene node to instantiate for the purposes of adding a Bus to an object.

Hopefully by the weekend, I will have the software working as well as or better than before, but with lovely clean code.

Comments Forum

More Devlog entries

Most recent first