Sunday, February 17, 2013

Nuts And Bolts - A Guide to Software Engineering

Hi All,

Here is a draft copy of a book I'm working on. This is my view of the software engineering process. I hope you like it.

Book: Nuts And Bolts

It focuses on the three principle areas of software development – namely  Project Management, Feature Management (Testing),  and Product Development.

It’s a work in progress, so please excuse the spelling mistakes.

I welcome any suggestions or comments you have.

Thank-you in advance for your input.
Trevy

Thursday, February 14, 2013

Software Analysis

Software Analysis is the art of gaining knowledge of an object, in terms of itself, as well as in terms of how it interacts with other objects in the world and the world at large. We must view these interactions in the infinite contexts that these interactions take place, as well as through all possible life cycles of its product-world interactions. Keep in mind that an object will behave differently in different settings. It will also behave differently when interacting with different types of objects. Then there is the history of the object to take into consideration.

Needless to say, complete knowledge is not just difficult but theoretically impossible. The reason is because of unspoken assumptions and hidden variables. Given this, the best thing we can do is start with the intended functionality of an object and work from there.

Functional Analysis - Intended use

The intended use is the official use of the product. It is absolutely essential that the product work correctly for the proper use of the product. Before any testing can begin, you need to know the intended use of the product or service, who the end-users are, and in what context people will use it.
Let’s use a pencil as an example:

Function

The intended use of a pencil is to write.

Context

We normally use pencils to write on paper. Should we expect the pencil to behave the same for all types of paper? The answer is, No. The pencil will behave differently on different surfaces.
 
What sort of surfaces is possible for writing? We have the standard notebook, wax paper, cardboard, sand paper, wallpaper, the hard cover of a textbook, etc. The more types of paper surfaces we can think of, the better our testing can be.

However, paper is only one category of surface on which people write. To think of other surfaces, we need to think of who will use pencils in their daily lives.

Users

Secretaries, construction workers, astronauts, and deep-sea divers are a few people who would use pencils. We have already explored the surfaces on which a secretary might write. They include notebooks, books, envelopes, loose paper, and self-sticking notes.
 
Construction workers write on wood, particleboards, and fabricated surfaces. They do this in order to mark where to cut and drill.

Deep-sea divers write under water. A deep-sea diver needs a waterproof surface on which to write. To best serve the diver’s needs, we need to design not just a pencil but surface on which to write on, since they both work in concert. The same reasoning applies to astronauts. We normally don’t think of standard paper and pencil as being a single design unit, but that’s because we are so used to it.

Astronauts need to write in space. Astronauts have unique requirements. They wear bulky gloves. This means that the pencil needs to be equally bulky. They are in the vacuum of space. This places unique requirements on pencils and writing surfaces. Then there is the issue of no gravity and wild swings in temperature.

Construction

The construction of an object has a profound effect on its function. It affects performance, security and maintainability, to name a few things.
 
Pencils are usually made of graphite, but other materials are used. For instance, colored pencils in an arts store are made of a waxy substance. This, together with a pencil’s hardness determines how well a particular type of pencil will behave when writing on a specific surface. (The artist is a user we didn’t think of before.)

In terms of hardness, the most common writing pencil is #2HB. This is popular for writing tests, because automated test scanners see them best.

Life Cycle (Use Cases)

Many companies try to steal the best people from other companies. In my opinion, this is a lose-lose situation.
 
What is a pencil’s life cycle?

The pencil is manufactured, used and then disposed of.

A pencil gets used, gets worn down and gets sharpened for further use. Is the pencil easy to sharpen or does the tip break easily? Does the pencil hold a sharp point or does it need to be sharpened often?
Then there is the issue of erasing pencil marks. This is where we test pencils and erasers on different surfaces. On some surfaces, pencil marks cannot be erased. Is that important?

There are many uses for pencils other than writing, but those are beyond the scope of this type of testing. If a customer finds a use for a pencil that doesn’t involve writing, then that’s free functionality. The manufacturer could optimize the pencil for this use if there is marketing incentive.

Safety-Security-Sustainability

Let’s look again at the pencil’s life cycle.
The pencil is manufactured:
We need to look at the manufacturing process. This includes how the materials were obtained, assembled and shipped to the end user. This is becoming important from an environmental and sustainability point of view. Also, the safety of workers is paramount.
The pencil is used:
Is it safe to be used by children and adults? People chew on pencils. Is the pencil covered with lead-based paint? Are the shavings dangerous? Does the shaving require special disposal? The graphite tip sometimes breaks off. Will that cause problems if swallowed?
The pencil is discarded:
Does the manufacturing process take recycling into consideration?

Summery

  1. Function - What are the intended functions of the object?
  2. User - Who are the intended users?
  3. Context - What are the contexts in which each user will use it?
  4. Life Cycle - What is the product life cycle?
  5. Safety, Security, Sustainability – Helping the world become a better place.

Functional Analysis - Unintended use

For various reasons people will use items in unintended ways. Sometimes the user wants to innovate. Other times the user misunderstands the correct function of the item and so uses the product in an inappropriate way. Often the user just makes a mistake. Ideally, the product should handle these scenarios in a safe manner.
 
There is a saying: “Fool-proof implies a finite number of fools”. From a cost point of view, it’s not possible to protect all fools. It’s not even to possible to predict how a fool will behave because even they don’t know. The only thing we can do is use the past as a guide to logically analyze the situation.

Functional Analysis - Malicious use

When it comes to physical objects, it’s difficult to prevent people from using items in a destructive manner. No one can prevent a person from stabbing someone with a pencil. There’s nothing a manufacturer can do to prevent this scenario, other than placing a warning label.
 
However, there are many things we can do to keep people and the world safe.

(This is an excerpt from a book I'm writing on Software development.)

Conducting Technical Interviews - Part 1

I just came from an interview with a high-tech company. They were looking for programmers with several years of programming experience. I was expecting them to ask questions about my programming experience.
Instead, they asked questions that resembled a 1st year computer class exam:
  • What is an interface?
  • What is a class?
  • What is polymorphism?
These questions don’t reveal anything about a person’s experience or abilities. In fact, these questions are worse than useless.
These questions penalize experienced developers. After years of industry experience, the answers to these questions are forgotten. I may not be able to formally define an interface, but I’ve used interfaces in countless situations. Ask me a question regarding a real-world problem and I will be able to answer it with ease.
The same thing is true with some of the greatest minds in history. They can produce incredible work. However - they can't explain how the do what they do. If you ask them, they typically say, "Just do it." or "I don't know. Needless to say they will fail all technical interviews.
On the other hand, a newbie will be able to tell you what an interface is, but may not know how to use it in real-world situations.

1. The 30 Second Interview

Countless studies have shown that we decide whether we like a person in the first 30 seconds. The rest of the interview is used to justify our feelings.

An interview is an unnatural situation to many people. It causes them to shut down and not act normally. This means that we are not looking at people at their best. Countless excellent candidates are passed over because of this. On the other hand, some people act confidently even though their abilities don’t justify it. A good interviewer needs to take this into consideration.

2. So how do we select someone to hire?

Past competence is a good indication of future worth. If a person does well in the past, it’s a good indication that they will do well in the future. The above company should have asked what programming challenges I faced and overcame. This would allow me to relate my experiences in terms of their needs.

3. So how do we select the best candidate?

In my opinion, the only way to know the qualifications of a person is to work with them for at least a month. You put a new hire on probation without obligations on both sides. After the probation period ends, you have the choice of letting the contract end, or offering the person a permanent position in the organization.

4. So how do we select someone for this probation period?

For candidates, the best companies turn to their network. Word of mouth is the No 1 method of finding people. Companies look to their network to find out about prospects.
In the Brave New World we have entered, there is a new way of finding about candidates. This is the Internet. This is especially true of the social networking sites such as LinkedIn, FaceBook, and Twitter, to name but three.
Of course, this won't replace face-2-face interviews. I think the interview is like a date. Each is trying to decide if they can live with the other person. The technical interview is just a means to that end.

5. Microsoft Technical Interview Questions

Microsoft likes giving programming questions in their technical interviews. These questions are useful in finding out how people think. As a result, it doesn’t matter if the candidate gets it right. The important thing is that the candidate explains their logic.

It’s fundamentally important that the interviewer knows how to solve the programming question before they give it to the candidate. There is nothing worse than questioning a candidate and then having the candidate correct your mistakes. It’s embarrassing for both you and your company. It’s also bad for the candidate because now the interviewer resents them.
I was in this situation myself. I felt that the interviewer was incompetent and wondered why he got hired. Needless to say I didn’t get the job.

6. Suggested Questions

Here are some technical questions I have collected over the years. It’s best you work out the answers to these questions yourself. If you cheat, you will only hurt your company and yourself. I’m only including questions I myself have solved. I will NOT give out any answers because I think that's a disservice to the community. Technical Interview Questions.

7. Home Grown Diamonds

Many companies try to steal the best people from other companies. In my opinion, this is a lose-lose situation.

We all know that it harms the company that is losing talent. However it doesn't stop there.
It also harms the company that is stealing the talent. They have to pay a premium for this talent. Also, what's to stop someone else from stealing this person? In my opinion, this is why executives get overpaid.
The best solution is to take a good worker and turn them into a Star.
A good candidate has these qualities:
  1. Easy to work with.
  2. Intelligent.
  3. Dedicated to self-improvement.
  4. Experienced in the specific technologies your business depends on.
Find a candidate with these qualities, and then help them to be a Star at work. To this end, I would like to suggest to you my favorite book on the subject of productivity. It’s called, “How to Be a Star at Work: 9 Breakthrough Strategies You Need to Succeed
I'll talk more about productivity in a future blog.

8. Some Further Reading

Technical Interview Questions

Hi all. I would like to share with you some technical interview questions I’ve collected over the years. It’s best you work out the answers to these questions yourself. If you cheat, you will only hurt your company and yourself. I’m only including questions I myself have solved. I will NOT give out any answers because I think that's a disservice to the community.
In each category, the questions are arranged from simple to advanced

Arrays 1-D

  • Reverse an array of integers.
  • Shuffle Cards.
  • Bubble Sort an array of integers.
  • Find element in an array of integers using binary search.
  • Remove duplicates from sorted array of integers. Pad remaining cells with zeros
  • Remove duplicates from unsorted array of integers. Pad remaining cells with zeros
  • Find first element in array that is duplicated/not duplicated.
  • Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it.
  • Given an array t[100] which contains numbers between 1..99. Return the duplicated value. Use only one iteration, one int to store intermediate results.
  • Given an array containing both positive and negative integers, find the sub-array with the largest sum. What if you don’t want negative numbers in the returned sub-array?
  • Implement the following function, FindSortedArrayRotation(int [] arr). arr is an array of unique integers that has been sorted in ascending order, then rotated by an unknown amount X, where 0 <= X <= (arrayLength - 1). An array rotation by amount X moves every element array[i] to array[(i + X) % arrayLength]. Can it be done in less than linear time?

Arrays 2-D (Matrix)

  • Transpose a square matrix. I.e. interchange the rows and columns.
  • Given an int array, zero out the vertical and horizontal column containing a zero.
  • Find saddle point. A matrix is said to have a saddle point if entry arr[r, c] is the smallest value in the ith row and the largest value in the jth column. A matrix may have more than one saddle point.
  • Find plateau. A matrix is said to have a plateau point if entry arr[r, c] is the largest value in both the rth row and the cth column. A matrix may have more than one saddle point.
  • Write a routine that prints out a 2-D array in spiral order!

Binary Search Tree

  • Insert node into binary search tree.
  • Delete node from binary search tree.
  • Write a function to find the depth of a binary tree.
  • Find Lowest Common Ancestor, given: Node LCA(Node root, int left, int right);
  • Print elements in-order (L, C, R).
  • Convert BST into a linked list.

Linked Lists

  • Insert element into linked list.
  • Delete element from linked list.
  • Delete alternate nodes in doubly linked list.
  • Find middle element.
  • Merge two sorted lists.
  • Remove duplicates in sorted list.
  • Find if list is circular. (No begining or end node
  • Find Mth to last element in linked list.
  • Reverse linked list.
  • Delete the nth node, given a link to that node. You have no access to the previous node for the exercise.

Queues & Stacks

  • Implement a queue only with stacks.

Text Strings

  • Given a string s, find character c and return its position.
  • Write a function to check if a given string is a palindrome. Ignore white spaces. Ex. “Able was I ere I saw Elba”
  • Given an arbitrary string, return a string with no duplicate characters. String RemDup(String s)
  • Given two strings S1 and S2, remove characters in S2 that appear in S1.
  • Given two strings, write a function that would print characters in the first string that are not in the second string and also print characters in the second string that are not in the first string.
  • Reverse words in String. (I am Sam) => (Sam am I)

Bit Operations

  • Multiply num by 7 without using multiplication (*) operator.
  • Find number of set bits in an integer.
  • There are two integers, ‘a’ and ‘b’. Swap the contents without using a temp variable.
  • Print integer in base 2.General
  • Find nth factorial. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Find nth Fibonacci number. (1, 2, 3, 4, 5, 6) => (1, 1, 2, 3, 5, 8)
  • Print integer one digit at a time, without storing any intermediate results.
  • Given the time in hours an minutes, find the angle between the hour hand and the minute hand.
  • Write a function that takes as its arguments 3 integers > 0. If the product of the integers is even, then return the one with the lowest value, else show 0.
  • Parse integer from string.

Recursion

  • Print numbers from 1 to 100 and then 100 to 1 without any for or while loops.
  • Print linked list in reverse order.
  • Reverse a singly linked list recursively.
  • Find nth factorial. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Find nth Fibonacci number. (0, 1, 2, 3) => (1, 1, 2, 6)
  • Sum the digits in a number. int sumOfDigits(int x); (If x is 2345, return 9 [2 + 3 + 4 + 5])
  • Count the number of set bits in an array of integers without loops.
  • Print all permutations in a string.
  • Count square clusters in grid.
  • Find way out of maze.
I hope you have fun with these problems.