Marco Dorantes' WebLog

"Computer science is no more about computers than astronomy is about telescopes" -Edsger W. Dijkstra

Do you amass nasty feelings about your designs?

Do you amass nasty feelings about your designs?

  • Comments 4

I remember the time when structured programming lessons first came into my attention. Control flow constructs like sequence, choice, loops, etc.

In particular, the condition-controlled loop that places the condition test after the loop body, for example do-while loop of C/C++ or C#, or Repeat-Until loop of Pascal. I have not seen this type of loop very often in programs, in my experience, from the group of condition-controlled loops, the most frequently used is the loop that places the condition test before the loop body.

For example, the operation of reading string lines from a text file, I have seen it many times expressed as the following loop in C# code:

void showfile(string filename)
{
	using(StreamReader reader=File.OpenText(filename))
	{
		string textline=reader.ReadLine();
		while(textline != null)
		{
			Console.WriteLine(textline);
			textline=reader.ReadLine();
		}
	}
}
It works but, I don´t like the nasty feeling left by invoking ReadLine method in two different places.

Using the do-while loop in C# –as in the following code– then that nasty feeling disappears and instead a somewhat emotional pleasure is left (see "Miroyokutaki hinshitsu").

void showfile(string filename)
{
	using(StreamReader reader=File.OpenText(filename))
	{
		do
		{
			string textline=reader.ReadLine();
			if(textline == null) break;
			Console.WriteLine(textline);
		}while(true);
	}
}
Many software designers –I have seen– tend to disregard their own nasty feelings of this kind and their detailed design (source code) is less, much less of what it could be.

Fortunately, professional software designers do not ignore such nasty feelings about their designs.

For example, Andrew Koenig and Barbara E. Moo write very good insights about design in the following work:

Accelerated C++ Practical Programming by Example
by Andrew Koenig and Barbara E. Moo
Addison-Wesley, 2000
ISBN 0-201-70353-X
http://www.acceleratedcpp.com/


  • I have trouble reading the second construct, and instead prefer:

    string line;

    while ((line = reader.ReadLine()) != null)

    {

    }

  • Nice alternative David. Thank you.

  • And yet the first one worked. It could work for 1, 5, 10 years and nobody would ever know but you.

    I understand the point but cannot appreciate the gain to the general audiance.

    I liken it to some old houses I have worked on.  For a hundred years they sheltered those that lived in them. Kept those in them alive in many cases. Then one day somebody wants to make it 'better'. And the ones making it better complain of the poor craft of the builders.

    At times I think we forget the actual intent and purpose of what we build.

  • I have had the chance to see and help with many software applications and systems in trouble due their difficulty to perform as expected or their costs to adapt to new expectations. The most of those applications support some business process that serve a general audience of end-users.

    By the time the problems were evident, there were a colossal amount of insignificant little things the designers let pass for not listening to those nasty feelings in what they did (assuming the feelings were present, if not, then we are talking about an entirely different thing and perhaps those designers should not design software systems for a general audience).

    The gain for a more general audience is fewer excuses like "We can’t serve you because our system is down"

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post