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.

 2,726 total views,  2 views today

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.

 1,324 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,982 total views,  1 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

 

 22,114 total views,  15 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,697 total views

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,908 total views

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.

 5,503 total views,  1 views today

Feed Yourself With News Anytime Anywhere via Internet Feeds

Let the news, latest music, videos and whatever you like follow you to your mobile phone, laptop, or to the desktop of your office/home computer. Gone are the days where you had to check the Internet for the latest updates about scholarships or scores of your favorite football club. Perhaps I should also point out that most Internet users settle for a set of favorite sites that they check regularly. Without the Feeds, typically you would regularly have to check the different sites for new content and news.

RSS, also known as Feeds, is a short form for Really Simple Syndication and provides a technology where you choose the news you want to receive. You can filter the news by category and the frequency to be updated. Some Feeds deliver the entire content to you while others deliver teaser text. A teaser text is a summary of the news to entice you to read the full article. Feeds not only provide you with a smart way of surfing the Internet, but also keep you updated while saving a lot of time. That is, instead of looking for the same information on a regular basis, the information actually looks for you.

Although not yet widely adopted, all modern sites support Feeds where you can subscribe. Take a simple example of news website such as BBC, CNN or SOCCERNET, whenever the news are updated, a summarized version of the news, called a teaser is sent to you. Similarly, when you subscribe to facebook, or Photo sharing site, the new photos are downloaded to you. Unlike other technologies, you have the news delivered to you.

But the greatest advantage of Feeds comes from the ability to choose and combine news from multiple sources. This capability is called aggregation and there are specialized tools called Aggregators. Aggregators allow users to combine and let content follow them anytime anywhere. This is opposed to checking 50 or 100 sites every day. Feeds provide an effective way to filter and organize the vast amount of information from the Internet. With Aggregators, you can set parameters such as how often they should be updated. Once you have aggregated your Feeds, you simply check the Aggregator or Reader for your customized news.

Feeds have rich applications in other areas such as distance education. Imagine a situation where students are notified on their phones whenever new content is posted. This form of interaction improves the e-learning experience. The Feed technology can also be extended to agriculture

The experience with Feeds is that you do not miss your favorite updates and are able to save time, generally keeping you informed anytime anywhere. Moreover, Feed technologies are cheaper compared to Short Messages Services, where you subscribe to a certain short code number and your are charged for each content.

*This article  first appeared in the newvision, the  Ugandan government owned newspaper  on may 26  2009 titled “Feed yourself with news anytime”*

 3,800 total views,  1 views today

Turning ‘software’ into a ‘software service’

This article looks at how to turn an  existing software that is not service oriented into a service that can be used in a service oriented architecture. We need to know  exactly-  what  is a service?  We are assuming the resulting service will provide  identical functionality. So the  only difference between a software service and other software components is at the interfaces. The interfaces define how the service can be used individually or as part of a larger system. In summary a service needs to achieve the following properties :-

  • is self contained, highly modular, and can be independently deployed. A service can do something useful in its own right.
  • is distributed component, accessible over the network or locator other than the absolute network address.
  • has a published interface, so users only need to see the interface and need not to know the internal details of the implementation.
  • is discoverable, meaning users can look it up in a special directory service where all the services are registered. Services designed for public use require to be discoverable, otherwise potential users may never learn about the service.
  • stresses inter-operability such that users and providers use different implementation languages and platforms. That is any software can be turned on a service for use with other services regardless of the languages in which they are implemented.
  • is dynamically bound, which signifies that the service is located and bound at runtime. Therefore service users do not need to have the service implementation at build time.

Therefore, turning  a software system into  a service consists of encapsulating the software such that it is  exposed  to the web via well defined and  flexible network accessible application programming interface (API).  This can only happen using a set of inter-related technologies. Currently web services provide a technology suite that can provide the above listed characteristics.

Our next article will relate the technologies in web service to   the properties of a service.

 5,936 total views,  2 views today

A short answer to a Bank Manager about Software as a Service and SOA

Recently, I met an executive of a top bank who was trying to roll his head around the notion of software as a service and service oriented architecture. He intimated to me that these two terms are the only things he hears from software development vendors and the internal Information Technology team. I offered an explanation that went as follows.

Software as a service represents a shift in the way software is developed and used. In traditional software development, the software executable or program  code is installed on the users computer. This requires a copy of the same software for each user creating challenges in updating, maintenance and licensing.

SaaS allows software to be installed and used over the Internet or Intranet. It allows a single copy of the same software to be used by different users from a single location through the network, which may be  intranet or internet. Even when multiple copies are deployed, they provide redundancy rather than a copy for each user. Under SaaS, access to the software is strictly through external Application Programming Interfaces (API). To encourage loose coupling, the mode of communication is usually message passing. Because the software is used through an external interface and most often owned by a different party,  this is sometimes referred to as consuming a service.

An architecture that is based on consumption of different capabilities of software programs by way of external interfaces is called a Service Oriented Architecture (SOA). With SOA, solutions can be built faster because we rely on existing SaaS functionality and add only what is missing. Incase of failure of one SaaS provider, it is possible to switch to other providers. Moreover,   most SaaS vendors allow consumers to pay for only what they consume.

He appeared to understand and promised to get back to me, and will give feedback as soon as I hear from the manager.

 5,226 total views,  1 views today