Problem solving Strategies for Software Programmers

Programming is a problem solving activity. When you write a program, you are actually writing an instruction for a computer to solve some problem. Overtime,  there are several strategies that have been developed and applied to solve problems. Problem solving is the processing of transforming problem from initial state to a desired  state. Some techniques are more effective while others are less. Here I outline some of the common strategies

Trial and Error – This is also known as solving problems using guess and check or generate and test. While it is certainly true that we don’t want to simply guess random answers as a means of solving problems, there are instances when educated guesses are important, valid and useful. For instance estimating the time an activity will end is an example of an informed guess. This techniques works like this:

  • Form an educated guess
  • Check your solution to see if it works and solves the problem
  • If not, revise your guess based on whether it is too high or too low
  •  

Root Cause analysis – a sequence of cause and effect is investigated until the origin of the problem is identified. Root Cause Analysis (RCA) is a systematic concept that involves a set of problem-solving approaches used to determine the underlying cause of an issue. In most cases, when a problem occurs, it creates other problems and resulting problems create others. For instance, in one of the software systems we discovered that some parts of the system were becoming very slow. On further analysis, the page was loading too much data. On further analysis the users where not closing the visiting, leaving many data points to be queried. So a possible solution was to close the visits programmatically after some time. The alternative solution could have been to add more RAM and processing power to the computers. Tools that can help in carrying out effective root cause analysis include the 5 WHY and the Fish Bone Diagram.

Algorithms – in this approach one defines set of step-by-step procedures that provides the correct answer to a particular problem. By following the instructions correctly, you are guaranteed to arrive at the right answer. An algorithm provides specific rules that guarantee a solution.

Brain Storming – Here the methods works by collecting a large number of ideas until one works. Some of these ideas can be crafted into original, creative solutions to a problem, while others can spark even more ideas.

Analogies – Here we compare parallels and make analogies to some other fields where the problem can easily be understood. An analogy is an abstract parallel between two quite different things. For example, you might analogize driving to project management. In both cases it helps to have a map (i.e., a plan) for where you’re going. An analog is a comparison between two objects, or systems of objects that highlights aspects in which they are thought to be similar. Analogical reasoning is any type of thinking that relies upon an analogy. Note that analogy is a cognitive process in which the problem solvers reason through the relationship between the prior experience and the current problem. There are three steps to

  • Mapping step
  • Application Step (Inference Step)
  • Learning Step

Challenges with this approach include ability to find relevant analogies and ability to resist false counter-suggestions that would destroy the analogy.

Working backwards – Working backwards is to start with the final solution and work back one step at a time to get to the beginning. This process will include the following

  • Work back through the logic of what is causing the problem, using the 5WHY’s process or any information that may be relevant, to the ‘resources’ that are driving it.
  • Look at the history of the events that have brought the situation to its current level.
  • Sketch out how you think a solution for the future might work, by changing the input flows and working through what could happen to input and output levels.

This technique works well when

  • The final result is clear and the initial portion of a problem is obscure.
  • A problem proceeds from being complex initially to being simple at the end.
  • A direct approach involves a complicated equation.
  • A problem involves a sequence of reversible actions.

Means End analysis – In this technique aims to apply sequence of transformations that directly target the end state. As described, a problem exists in a current state (initial state) that must be transformed to arrive at given final state. So one might look at the current state, identify the differences between the current state and final state and then keep on providing solutions to the differences. For instance, start at initial state and then create every possible permutation from my initial state. The next step is to calculate the difference in the states just made and end state. In summary:-

  • Identify your current state,
  • Identify where you want to be (your goal state),
  • Identify the means that will get you there.

Brute force – Here we systematically try all possible solutions until one of them works. For instance if I know that pin number to unlock a phone is 4 digits, then I can try all the possible 4 digit combinations because the pin is one of them. This approach works where the solution space is well known and can be traversed in reasonable amount of time. The approach also requires checking each of the possible solution whether it is correct or not.

Hill Climbing – This technique involving choosing any available option that moves you closer to the solution. One challenge with this approach is that the chosen move may appear to move closer to the solution but is incapable of progressing to final solution. We call this getting stuck at local maxima. Local maxima are states that are closer to a goal than any neighboring state but they are not a goal state.

In conclusion, the different strategies outlined above, fall under two broad categories of Algorithmic approaches and Heuristic approaches. Hill climbing, brute force, trial and error, means ends analysis, working backwards all belong to the heuristic strategies because they lack systematic step by step procedures that guarantee a solution all the time. Algorithmic problem solving is more common in computer programming and several algorithms such as bubble sort and binary search among others that solve specific problems.

 1,009 total views

Problem solving for computer programmers – Well and Ill-defined problems

In practice, a problem occurs when a problem solver has a goal but initially does not know how to reach the goal. So, the problem begins in a given state (current state) and the problem solver wants the problem in another state (goal state). Problem solving is required to transform the current state to the goal state. Therefore problem solving is application of ideas, skills, or actual information to achieve the solution to a problem or reach a desired outcome.

In light of the above, a well-defined problem provides clear description of the initial state, allowed operations and the goal. Well-defined problems  have clear goals or solution and its problem solving strategies are easily developed. On the other hand, ill-defined problems do provide specific guidance in terms of what is expected.

As an example, most of you might be familiar with the wolf, goat and cabbage farmer river-crossing problem. It is usually told that once upon a time, a farmer went to a market and purchased a wolf, goat and cabbage. On his way home, the farmer came to the bank of a river and rented a boat. But crossing the river by boat, the farmer could carry only himself and a single one of his purchases: the wolf, the goat, or the cabbage. If left unattended together, the wolf would eat the goat, or the goat would eat the cabbage. The farmer’s challenge was to carry himself and his purchases to the far bank of the river, leaving each purchase intact. How can this be achieved?

The above, is a well-stated problem with a clear initial state, allowed operations and final state. In dealing, with programming, which is largely a problem-solving job, because the role of the programmer is to give solutions to the computer for it to execute. Remember that computers just follow the programmed solutions.

“Write a computer program for music” is an example of an ill-defined problem. It neither states the initial state nor the final goal. Generally, ill-defined problems come out as ambiguous, provoke several interpretations and it is not obvious when a solution has been reached.  In addition, ill-defined problems are are unclear, abstract, or confusing and do not have clear problem solving strategies. One strategy to solved ill-defined problems is to add constraints for which the solution will be valid. Such constraints are called operational constraints. In the music playing example, one may add that the program should play, pause, and stop play songs format mp3.

In conclusion, as a way of understanding a problem, problem solvers and particularly programmers should identify the three aspects of the problem for any meaningful and acceptable solution to be accepted.

 394 total views,  1 views today

Don’t compete with anybody – set your standards

As I was talking to a former a student, he asked me what kind of advice I can give him to advance his software engineering career. I quickly told him, do not compete with anybody set your standards!

Many times, students tend to compare themselves with their friends in terms of what they are able to achieve including scores. Little do they factor in their own desires and what exactly they want to do with their skills.

The bottom line is to  identify your strengths and weaknesses, and act upon them to full potential. This attitude of competing with others especially in terms of scores can lead to a case of “an eyed man in a sea of blind men”, you might appear better, but in relative terms against a very weak point of reference.

The next question, is what are the most appropriate standards. In the case of software engineering, i would advise to look at some of the current software projects and aspire to produce better projects. There are standards also available from computing associations that can be a good point of reference. Also look at the job or business you want to perfect, and aim for it.

 1,252 total views,  3 views today

Generating alternative Solutions to Problems

In the article about problem solving in software engineering, i highlighted the major problem solving steps as:-

  • Define the problem
  • Analyse the problem
  • List/Identify  alternative solutions
  • Select the best solution
  • List instructions that lead to the solution using the selected solution
  • Evaluate the solution

In this post, i will focus on how to generate alternative solutions.The first solution you are arrive at may not be best of all possible options. It is important that we generate as many alternatives as possible. This will allow us to choose the most effective solution to the problem.

To generate alternative solutions, you can look at the problem in different ways. You are argued to find a new perspective that you have not yet thought about. One technique is to quickly list different solutions including those that do not look viable and then try to eliminate one by one and see where they fail. Try combinations of different parts of solutions.

You can also engage stakeholders. Usually stakeholders see problems from completely different perspectives. If you are a developer, involve users, involve sales people and other stakeholders.

Within the same group, brainstorming sessions tend to generate different solutions.  In general, the  more alternative solutions at hand, the final solution will be cheaper, elegant and easy to implement

 

 13,865 total views,  10 views today

Inspiring quotes on computing

“It is not only the violin that shapes the violinist, we are all shaped by the tools we train ourselves to use, and in this respect programming languages have a devious influence: they shape our thinking habits.”
Edsger W. Dijkstra
“Program testing can be used to show the presence of bugs, but never to show their absence!”
Edsger W. Dijkstra

 2,002 total views

Streamlining Software Development Projects

In most developing countries the software development discipline is emerging. Several private and government entities are in the process of automating different business activities. Just like the software discipline itself, the information technology professional are still gaining expertise in specification and verification of software solutions.Where the clients know what they want, they are not in position to explain it to the developers. And equally less experienced developers find it a challenge to understand the needs of the client.

To overcome this problem, some entities hire a consultant to help manage and supervise the implementation process. That is, there are two different consulting firms involved in the project – one to do the actual implementation and the other to supervise the implementation. They all work for the client, but the supervising firm ensures quality is delivered.
crb

This approach of a supervisor and the contractor is well tested in civil engineering works. Where you will find, the main contractor, the supervisor as independent contractors.

For this work, the discipline has to be mature such that the approaches and documentation are well understood by the different parties in the project. In some projects, this has improved the quality of the project because each contractor has a specific responsibility.

I have seen this approach work in software development with amazing results. Usually the supervising contractor requires domain knowledge to ensure that the engineering product serves the desired purpose. The presence of supervising contractor implies the need for proper specification, documentation and reports because these are part of the main inputs for the supervising contractor. The mandatory need for these documents guarantees a level of a streamlined the software development process.

 3,772 total views,  2 views today

Learning is hard but unlearning is harder

During the week of  27 June – 29 June 2016 i attended the Summer School on Machine Learning and Data Science at the school at Makereree University dubbed “Data Science Africa 2016”. I happen to sit with a colleague who is an experienced and certified Java Programmer. As we paced through the examples on data cleaning using anaconda package, we relied both on new new knowledge and also tried to apply what we have learnt over past years in our professional programming experience.

We aimed at cleaning our dataset to get rid of rows without a value for one of the rows on multiple columns. Our data had a column for Gender and another for TesCondition. Now some of the rows had empty values for Gender, while others had empty values for TestCondition. We learnt that once you have a data frame, then you can apply a condition of the form,

 q1= Dataset[‘gender’!=’’]

And then use it query the data as dataset[q1] and this faithfully returned only rows with a value in the gender column. Our next task was to remove the rows with empty values in the ‘TestCondition’ column. Of course we easily figured out that we can construction another query

 q2=Dataset[‘TestCondition’!=’’]

And apply it to the result after q1.

But then our instincts dictated that we could achieve the same result by using Dataset[q1 or q2] – that is return columns where gender is not empty or testCondition is not empty. However the compiler severely rejected this. For sure we have learn’t and know that logical operation on two Boolean expression should yield another another Boolean. Then our unlearning process hard to begin! We checked the syntax, double-checked the indenting, double checked the expression one by one. Meanwhile we found ourselves a couple of tasks behind the rest of the class. Reason – we could not easily unlearn what we have learnt and believed to be correct overtime.

For a while we kept on trying related syntactical expressions from Java, C, C# and standard Python that were not successful. It quickly became obvious that because we were so convinced about the common usage of logical expression, it took us a lot of time to adjust and enjoy the syntax of the new data science platform. Learning the new syntax was much faster as opposed to the time we spent trying to ‘unlearn’ from the past language.

The time taken to unlearn can vary from individual to individual. And a famously put by E.W.Dijkstra (1995) that ‘The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense” .Dijkstra further “the teaching of BASIC should be rated as a criminal offense: it mutilates the mind beyond recovery

Indeed I have had comments from programmers as they attempt to cross from one language to another.

From C, C++, Java, PHP to Ruby
Any body who has done programming in this languages understands the importance of terminating statements with semi-colon (;) and strict naming of variables. One programmer could not come to terms with the fact that variable names of the form is_avaialable? Are perfectly acceptable in Ruby.

From C , C++, PHP to JavaScript

The notion of functional prototyping in javascript coupled with variable scoping in javascript has proved to be profoundly different from the typical static scoping most developers with expertise in C, C++ and Java are familiar with. In C, C++, Java the following code will terminate and producing twenty outputs

for(int i =0; i<10;i++){
  for(int i=0; i < 2 ; i++){
    System.out.println( i);
  }
}

while in javascript,

for(var i =0; i<10;i++){
  for(var i=0; i < 2 ; i++){
   console.log( i);
  }
}

will create a an infinite loop.

Have you had a challenge unlearning something?

 2,232 total views,  1 views today

Google knows more about you than what you might want them to know, only VPN can save You.

As tried to keep connected to the social media platforms in light of the Ugandan government shutdown possibly based on basic filters, I also accessed google search engine through the same approach. Interestingly after returning the search results, google was so confused because it kept asking me to refill the CAPTCHA (an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”). Indeed google failed miserably to tell that I was a human being so they refused to load any link to the search results.

Then I tried gmail to access the emails, they also presented the CAPTCHA. Still google was not very sure, so they asked me to unlock my Techno F6 Phone! And I did before I could access the mail. So how did they know that I own a Techno F6 Smart phone? How did they confirm that I had unlocked it? And how much else do they know?

As an IT professional and expert at that, I am aware of some of the answers. I access gmail through my Techno Phone, so google took the liberty to keep all this information. Each time, I unlock the phone, google get to know, because the gmail application contacts them.

I don’t want to suspect that because Techno F6 is an android phone and google are the developers of android, then google might have extra tricks built in the android operating system it self.

If you think this is a simple subject, then follow the links for extra information
1. http://www.businessinsider.com/stop-what-youre-doing-and-go-see-what-google-thinks-it-knows-about-you-2012-1
2. https://www.intego.com/mac-security-blog/google-search-archive/
3. http://www.wsj.com/articles/apple-and-google-know-what-you-want-before-you-do-1438625660

 3,026 total views,  1 views today

Microservices is not more than a specialized case of SOA

Over the last couple of years, there has been renewed energy in the subject of service oriented architectures. The invention of term ‘micro services’ has warranted a immense interest in the subject of service oriented architectures.

Despite the initial contention on the difference between SOA and the already mature Component Based Software Engineering (CBSE), there is consensus that SOA improves the key attributes of software such as agility, cost to market, flexibility, inter-operability and many others. A service in SOA is now understood as an autonomous software unit that can be used programmatically across the network. Services can interact regardless of the underlying technologies for as long they expose their interfaces for use by other entities.

The size of a service — how much functionality can be bundled into a single service unit is a issue of design left to programmers and software architects. Of course services are compositional – i.e. two or more services may be combined into a new service in its own right. Practice and programmatic recommendations suggest that a service should bundle a business functionality. And SOA in is traditional form has been largely conceived to be applicable at the business level.

Microservice advocate a new way of building systems with more fine grained service units. Simple low-level core functionality can now be exposed as services for use in building high-level systems. A micro service may be as large as a function in a functional language or method in Object oriented Language. Microservices should not be equated to functions or methods because a service is an architectural unit.

Whereas micro services raise the level of flexibility, they increase the number of ‘moving’ parts – each service is autonomous, deployeable in an independent process. This comes with well known challenges of distributed computing. Obviously we have come to learn that in software architecture there is need for trade-offs. It may be very hard to optimize both flexibility and reliability.

The level of granuality and new usage scenarios for microservices, require new support tools for designing, monitoring, provisioning, management of microservice based systems.

 4,690 total views,  1 views today

Why Steal Software When There is Free Software?

Recently, one of the leading commercial software companies in the world has hired one of the leading advocates in town to crackdown individuals and organisations that are using software which is not licensed. That is people engaged in theft of software products — an act that is often called software piracy. In the past, there has been a feeling that most of the software companies are not local and therefore do not have local presence to detect and followup individuals using their products illegally. However, as of today, perhaps with the help of the credit crunch, even the largest companies are determined not to loose any revenue on products that represent their livelihood. Considering the price of these products and current economic downturn,   it may not be possible to pay for them and yet it is not possible to do without.

Actually, there is a better and smarter workaround. There are free software alternatives for all your needs ranging from simple document editing to advanced professional systems. Besides when you pay for the commercial products, you do not really own it, for instance it would be illegal to lend it to your friend or wife. Commercial software products are like buying a car that you cannot even give a driver to drive you or your spouse to pick your daughter from school.

Free software precisely means free of charge, that is software you can get at zero price. Moreover, free software gives the user freedom to use, to study and change it, and to redistribute it with or without changes. That is, you have the liberty to copy and redistribute in modified or unmodified form either without restriction, or with minimal restrictions to ensure that further recipients can also do similar things. Therefore those interested and with the technical know how can modify the software, add value or remove those unwanted features. Think about how often, you wanted to do something with a system, but it could not.

Let me first answer the question that might be developing in your mind – who owns the software if any, and how do they benefit? Precisely, a group of software engineers come together to build systems of interest. The answer is simple, the users do not directly pay for the software, but advertisers pay. In fact, to most commercial products there is a corresponding free software product. If your software needs are typing documents, spreadsheets, then OpenOffice is the answer to your needs. OpenOffice is free, powerful and provides an exceptional user experience. Of course you need an Operating System to start with. An Operating System controls and coordinates the activities of your hardware and other software on it. For free excellent Operating Systems, there are many choices from Linux based variants. My favorite is Ubuntu — “linux for humans”, spearheaded from South Africa. With Ubuntu, you do not worry about computer virus and comes with a collection of other software for all common activities. Be it music players, games, Internet software, e-mail software, they are all available on Ubuntu free of charge.

There is this old adage that free things are usually expensive. Free software is perhaps the first product am aware of to defy this adage, it is given completely free of change and performs better than the counterpart commercial software products. Take a case of Ubuntu, no virus is yet known to attack it. Indeed, the open source community has shown the way for many years: open peer review has proved to be an extremely effective way to detect design flaws, inefficiencies, and security holes.

Today, there are tens of millions of people around the world that use free software. Some free software products such as Apache Web Server command up to seventy five percent of the market. The question I have posed today, is then, why steal software when there is free software? Perhaps, one of the answers is that you are not aware of these free and excellent products. Maybe the one who exposed you to computing literacy had the same problem. There is always the first time, moreover, the free products provide similar or sometime better user experience because they are reviewed by many people. You have the freedom to lend or duplicate and use in anyway. Most important, if you have the competence, it is possible to personalise the software by removing or adding functionality to fit any taste.

 2,838 total views,  2 views today