Software Programming Process
Archives > Software Programming Process
Part 2: Necessity of having a well defined process
Software Programming Process Part 2: Necessity of having a well defined process
This article was written by a software professional at Stylus Systems,
Bangalore India. We hope that you benefit from the information shared here and
that you consider our services. Please feel free to email us.?
So why in the name of all that's holy do we need a process for the thing after
all? We've all done it, and if something new comes up, there' always someone to
ask. After all, -it's all been done before-
So ok, tomorrow if I ask you to write a program to give me all possible
solutions for the eight queens (on a chessboard) problem, how many of you would
do it? Whom would you consult for the algorithm? Better yet, how many of you
would be able to give me a program that completes execution in less than an
hour? Even if you copied it from a book, would you know why you're typing what
you're typing?
Suppose I gave you something that you couldn't even copy from a book, like
calculating trajectories of 3 bodies moving in space and influenced by each
others gravitational pull. That's when some stars would be seen, right?
Here are four ways of writing the same loop. Those of you who've done the
program earlier would know that it's part of the program in 'C' for showing all
prime numbers from 1 to 1000000. (The program is of course not complete and the
syntax is in no way accurate, please don't try to run it. I'm just proving a
point in logic building)
for(i=1; i<1000000;i++)
{
????? for (j=2;j<i;j++)
????? {
????????????? if (i%j)==0
????????????? {
???????????????????? //printf("%d is a prime number
\n",i);
???????????????????? break;
????????????? }
?????? }
}
|
for(i=1; i<1000000;i++)
{
????? for (j=2;j<(i/2);j++)
????? {
????????????? if (i%j)==0
????????????? {
???????????????????? //printf("%d is a prime number
\n",i);
???????????????????? break;
????? ????????}
?????? }
}
|
for(i=1; i<1000000;i++)
{
????? k = sqrt(i);
????? for (j=2;j<k;j++)
????? {
????????????? if (i%j)==0
????????????? {
???????????????????? //printf("%d is a prime number
\n",i);
???????????????????? break;
????????????? }
?????? }
}
|
for(i=1; i<1000000;i++)
{
????? for (j=2;(j*j)<i;j++)
????? {
????????????? if (i%j)==0
????????????? {
???????????????????? //printf("%d is a prime number
\n",i);
???????????????????? break;
????????????? }
?????? }
}
|
I'm commenting out the output statements because we want only a comparison of
individual cycle times.
All these four methods will give perfectly valid results without the //'s, the
only difference being that the first program will take about 17 minutes to
execute (depending on system speed) and the last one about 8 seconds. Have a
closer look.
Part
1
|
Part 2
|
Part 3
Back to top
|