Software Development: On A Need to Know Basis

A good clear principle for any software engineer and developer is that any class, method or function that you create and use should only have the bare minimum number of necessary arguments passed into it to correctly operate and not know more about the system than it should. Recently I have been doing some merge reviews and too many times I have seen the below case from both junior and (surprisingly) senior engineers:

...
Object object = getObject();
Date objectDate = getObjectDate(object);
...
private Date getObjectDate(Object object) {
    ObjectReader objectReader = new ObjectReader(object.getId());
    return objectReader.getDate();
}
...

As soon as I see the above I leave a comment on the merge request, something along the lines of “Why does the getObjectDate(Object) method need to take the entire object instance?“. This then forces the one who submitted the merge request to stop and think what is being done, and should it be refactored in someway.

In this case, the method only uses the object’s id to build a reader and get the date from the object. The actual object is not being used at all. Instead of passing the entire object into the method the id should only be passed in. There is less overhead. We should be seeing something like below:

...
Object object = getObject();
Date objectDate = getObjectDate(object.getId());
...
private Date getObjectDate(String objectId) {
    ObjectReader objectReader = new ObjectReader(objectId);
    return objectReader.getDate();
}
...

By only passing the bare minimum to the methods or classes then you are ensuring that your system does not know more than it needs to. By enforcing this rule, IMO you are ensuring that the system is:

  1. Cleaner – you know exactly what is being used and for what purpose.
  2. Safer – you are ensuring that only what you want to be manipulated can be manipulated and where.
  3. Modular – there are clearer separations between what needs to be done with what and where.

So when you are creating new classes or methods then consider what you are using as your arguments, what the method needs to do, and what exactly you need to pass in. Taking the time to logically structure your code and think through what is necessary for the method to do its job will save you massive headaches in the future. Short term pain, for long term gain 🙂

Artificial Neural Network: The Neuron

I am by no means an expert in machine learning or artificial intelligence, but just an avid learner and curious individual. Please use the information provided here as a supplement to further your knowledge and research.

I am currently building an artificial neural network from scratch (more specifically a multi-layer perceptron neural network. To help clear my head and make sure I understand everything correctly (or still remember from my machine learning subjects at university) I will be writing several blog posts about machine learning and artificial neural networks. To start the list of blog posts off I am going to write about one of the fundamental building blocks of the neural network, the neuron.

I will be skipping the background about the neuron and how it relates to the biological neuron. Instead I will cover how it is constructed and used in an artificial neural network.

Inputs

The neuron will process inputs from the previous artificial neural network layer. The previous layer could be:

  1. The input layer of the artificial neural network. In this case then the values are taken directly from the training data, test data, or user input when using the trained artificial neural network.
  2. A hidden layer of the artificial neural network. In this case the values would be outputs from other neurons.

Note: There is a special input which is called the “bias” which always has a value of +1. The role and purpose of the bias is so that there is a trainable constant and allows the activation function (will talk about that a little later) to give us the best possible chance of an optimal model. You can read some more about the bias purpose and use here and here.

Weights

For every input to the neuron there is an associated weight. Initially the weights are generally given a random value between the range 0.1 to 0.9. As the artificial neural network is trained the weights are adjusted as to better match the desired output.

Operations

Summation

The first operation to obtain the neuron output is to perform a summation of the multiplication of the associated weight and input. Mathematically this is represented as follows:

 

Artificial Neural Network Summation

 

where:

  • y is the output.
  • n is the number of inputs to the neuron.
  • i is the index of the input to the neuron.
  • w is a weight.
  • x is an input.

You may be asking, Chris why do we have the zero indexed weight and input outside the actual summation when you just add it anyway? Good question reader. Generally the zero indexed input is the bias which then makes the associate weight the zero indexed weight.

Activation

After the summation operation is performed there needs to be an activation function used. The use of the activation function allows for the enhancement or simplification of the neural network. Generally the activation function is non-linear and there are a variety of functions that can be used. Two of the most common activation functions are either sigmoid or rectifier functions. More information about the sigmoid function can be found here. More information about the rectifier function can be found here. The final value of the activation is the output of the neuron.

The next blog post would most likely be about the various layers of the neural network and how they are all interconnected. So stay tuned.

Git. Command Line or Graphical User Interface?

I was doing some reading today about Git and whether software engineers (or anyone else for that matter) should learn to do all their changes, etc for Git using command line or a graphical user interface. It was an interesting piece and some valid points were made for both using a command line and/or a graphical user interface. Me personally, I use a graphical user interface because it is extremely easy, hooks directly to the Git commands (under the hood) and can give you a nice visual tree of what the repository looks like. For your information Sourcetree is the client I use. However the more programming and development I do, the more I appreciate and want to learn what, how and why.

Some of the reasons why using the command line approach is valid and well worth it include but not limited to:

  1. Platform Independence:
    • No matter what operating system you are on, the commands are universal. So if you can use the Git commands in a Linux environment, then you will have absolutely no problem whatsoever doing it on a Windows or MacOS machine.
    • Git clients like Sourcetree for example are not available on every platform, and I imagine the other Git clients are also not available on every platform.
  2. Understanding:
    • This fundamentally for me is important and I think should be high on everybody’s list when using something.
    • By using the command line you get a level of understanding of what exactly you are doing, whereas using a graphical user interface this level of understanding (well to me) is abstracted and partially lost.
    • It also comes back down to point 1. If you understand what you are doing then you can take it to any platform.

Now using a graphical user interface is not the end of the world. Sometimes you just want to get something done and using a terminal if you are not comfortable with it can be extremely daunting. I personally would never be caught dead (well right now anyway) resolving merge conflicts and looking at diffs using a command line, and rebasing using a graphical user interface is so much easier.

I did some quick Googling and found what I feel are two really good resources that help and ease you into using the command line for Git. There is Try Git and Learn Git Branching. There are probably more out there but those are the two that I felt provide a good starting point. If there are others out there that you use or feel that there is a resource that is definitely worth reading then please add a comment below (sharing is caring) 🙂

Learning Patience From Teaching

I would consider myself a fairly calm, level headed and patient individual; never can I recall a time where I have gone off the deep end and blown a gasket. There is nothing beneficial in becoming angry, frustrated and furious at an individual or team, or questioning whether someone has really been paying attention in a demeaning fashion. I have seen first hand what happens when someone does blow up and starts angrily blaming and non-constructively criticize someone. As I worked with a variety of different individuals from a number different backgrounds, beliefs, understanding and competence, I have learnt to be patient and try to understand why and where they are coming from.

The reason why I am writing this blog post is because this weekend I was asked by my parents to construct an specific Microsoft Excel spreadsheet that can be easily modified aka “Idiot Proof” as they put it. I am not an Excel wizard or master, but I do know my way around a spreadsheet and I can do what was necessary in Excel for them. As I finished the spreadsheet and was showing them, they seemed fairly happy with the result which was good. But as I was showing them how to update and use it to meet their needs, that is when my patience was being tested. What I originally thought was going to be several minutes explaining how to use the spreadsheet turned into an hour worth of explaining.

My dad is an electrical engineer and as far back as I can remember he has used a computer. He knows how to build them and use a number of various software programs effectively. But his knowledge is limited when it comes to the Microsoft Office suite other than how to send an email in Outlook. My mum on the other hand is what you would call  unfortunately, computer illiterate. She knows the very (and I mean very) basic computer functions. Browsing the Internet (safely), and updating the computer is all she really knows how to do. Anything else would require me to either write it down in simple easy to understand steps or show her continuously until it becomes second nature. She has not used computers as much as my dad or me, so I don’t expect her computer literacy level to be as high as either of us, and that is perfectly fine. She is more than willing to learn which is fantastic.

Back to the Excel spreadsheet. It was constructed in a way that would auto-populate nearly all of the necessary cells with only a couple left to be filled in, and rows in a table would be used to auto-populate a number of other cells. I showed them once how to add a new row to a table in the spreadsheet which allowed the cells to be auto-populated. The actions and process was extremely simple. I laid it out to them in the following way:

  1. Left mouse click in the table cell to select the table.
  2. Right mouse click in the table cell to bring up the pop-up.
  3. Select Insert from the pop-up.
  4. Select Insert Row Below from the pop-up.

I really didn’t think it could get any simpler or easier. However it took them a number of times to understand that you cannot just enter values below the current row and have the necessary cells auto-populated. Knowing that for them this is fairly foreign, I needed to be patient and try to answer their questions as best as possible, in the most simplest way too. If I didn’t have the patience to explain something as simple as adding a new row to a table in Excel then it was a perfect time to learn to be more patient.

After showing them a couple of other necessary actions to perform some other tasks I asked them are there any other follow up questions they had. My parents wanted to see if they could do the whole process from start to finish by themselves with me watching to make sure the right actions were performed. The very first task was adding a new row to the table, and already like an old bad habit they just entered the values below the row and not in the table. I calmly explained to them again that they needed to add a new row to the table otherwise the value will not auto-populate. So I proceeded to show them again how to do that. Again, if I didn’t have patience or was hot headed then I most likely would have said something like “I just showed you how to add a new row to the table like 5 minutes ago, how did you forget? Or were you just not paying attention?”.

As a project technical lead and a software engineer who has been with my current company a number of years, I also provide support to any new software engineers that join our teams. Once again I get to interact with individuals ranging from software engineering interns who are still studying at university to software engineers who have been around the block. With the vast difference in experience that someone has, I need to be able to be more forgiving, understanding and patience with someone who has never rebased a Git branch or resolved merge conflicts before pushing to their origin. I get the opportunity to teach someone something new while also learn to be more patient, understanding and a better leader. It is a win win for everyone 🙂

Obsessively Learning For The Better

Ever since I could remember I always loved to learn and help others. Be it to learn how things work, why something was designed a specific way, and/or what made this thing function the way it did. All of those questions fuelled my curiosity and passion to learn, to understand, and to help others understand or solve their problem. There is something satisfying about knowing how things work, why they work, and being able to answer people’s questions with an appropriate answer. Plenty of people are not too concerned about the how and why, and are just happy that it works; this is absolutely fine as well. For me however, the more I understand something the more I can leverage it to my advantage getting the absolute most out of it. This is probably another reason why I became a Software Engineer and continued to study after my Bachelor degree to obtain a Master degree.

I encountered a small technical issue yesterday and was browsing Stack Overflow to see how others resolved their problem and what the exact root cause was. There was a perfect answer to the issue with a equally perfect explanation as to why it was failing and how the fix solves the issue. Sometimes when I see the answers to questions on Stack Overflow there is just an answer with little to no explanation as to why it fixes the issue. These answers I feel are not that great because really you don’t learn and understand how to fix the problem, you just use a solution without understanding the problem properly. You don’t learn anything. If I do encounter just an answer to the problem I try to read up further as to why this solution works. In the long run being able to understand the problem completely and how the solution fixes it is far more beneficial.

On a daily basis I try to learn something new, be it a new functionality that I didn’t know in Java, C++ or C# had or how to use my body to ensure that I can easily incapacitate an attacker with minimal effort using BJJ. By me constantly learning something new every day I can better myself which in turn I can try and assist others to better themselves or provide a solution to a problem they have encountered. This desire to learn has helped me in my career so far as a Software Engineer, as you need to constantly develop your skills and research new and upcoming technological trends to stay relevant. It is a challenge to try and better yourself day in and day out, but when you go to bed at night and you think about what you have learnt that day or how you have helped someone, it makes going to sleep that much easier.