2010-01-07

Officially Old

With another birthday under my belt and the new year started, I am officially old. On the other hand, I've now been programming for more than 10 years! I dug up an old piece of my code, prime3b.java, which was last modified on July 14th, 1999. Technically, I've probably been programming for 12 or 13 years, but I don't think my self-taught, TI-86 programming should count as programming.

According to Wikipedia's Java Version Page, this program would have been created for Java 1.2. The program took a number, computed all the primes to that number, and could print out the calculated primes or number of primes.


import java.util.*;

public class prime3b
{
public static void main(String [] args)
{System.out.print("Would you like to print out all the primes?");
String cond = KeyBoard.readString();
boolean f = true;
boolean d = true;
if (cond == "no")
{f = !f;
}
System.out.print("Would you like to print out the number of primes?");
cond = KeyBoard.readString();
if (cond == "no")
{d = !d;
}
System.out.print("Enter a number:");
int x = KeyBoard.readInt();
int a = 0;
int b = 0;
int []m = new int [100000];
m[0] = 2;
int z = 0;
int e = 0;
int c = 3;
int y = 0;
long t1 = (new Date()).getTime();
for(; c <= x; c = c + 2)
{y = (int) Math.sqrt(c);
for(z = 0; m[z] <= y; z++)
{a = c % m[z];
if (a == 0)
{b = 1;
}
}
if (b == 0)
{e++;
m[e] = c;
}
else
{b = 0;
}
}
long t2 = (new Date()).getTime();
t2 = t2 - t1;
z = e;
if (f == true)
{for (; z != -1; z--)
{System.out.println(m[z]);
}
}
if (d == true)
{e++;
System.out.println("There were " + e + " primes at or below " + x);
}
System.out.println("Time is:" + t2);
}
}



PS In case you're wondering about my instructor's feedback, he said that one day I would be a superb programmer, after I had been crushed by the complexity of a few systems (I don't think he said "been crushed by", maybe "grappled with?"). This would teach me discipline, actions like encapsulating code into functions, thinking about testing, using standard formatting, using better variable naming, checking inputs, checking boundary conditions, and learning that code was also meant for people.

I'm still hoping his prediction comes true.

PPS I think most programmers fall into two categories: OCD programmers who need everything perfect, constantly re-visiting and re-working, or lazy efficient programmers who do the least amount of work even if it means more code. I think the above firmly puts a younger me into the efficient camp.

3 comments:

Dan Gagner said...

Happy Birthday Matt.

Jenn's Dad.

Jenn said...

Thinkin of you! Hope everything is well back in ze Nether lands. :)

Liz! said...

you are so not old!

Happy Birthday Pud-Butt!