|
LMAF
So, how did he fit a 132 character string on the 80 character screen? What if the string had leading or trailing blanks?
Reminds me of a challenge to print 9 lines. Wrote a routine to write up to 197 lines:
static void stringlist(int num)
{
if (num < 0) num = -num;
if (num < 2)
{
Console.WriteLine("1");
return;
}
if (num > 99)
{
Console.WriteLine("Passed number ({0}) exceeds 99, setting to 99", num);
num = 99;
}
List<string> forward = new List<string>();
StringBuilder left = new StringBuilder(), right = new StringBuilder(), pad = new StringBuilder();
int len = 0;
for (int i = 1; i <= num; i++)
{
pad.Append(" ");
left.Append(i);
string x = left.ToString() + right.ToString();
forward.Add(x);
len = x.Length;
right.Insert(0, i);
}
foreach (string x in forward)
if (x.Length == len) Console.WriteLine(x);
else Console.WriteLine("{0}{1}", pad.ToString(0, len - x.Length), x);
for (int i = forward.Count - 2; i > -1; i--)
Console.WriteLine("{0}{1}", pad.ToString(0, len - forward[i].Length), forward[i]);
}
So, how would you grade my coding?
OK, OK, so I put one ineffiecient line in that I decided to keep in. Anything else you would complain about it?
|
|
|
|
|
KP Lee wrote: So, how would you grade my coding? My number 1 rule for grading code is..."Does it work?"
After that, I normally don't care how many clock cycles you are chewing up unless it makes the code unusable.
Readability only becomes an issue when you have to go into the code to fix it or make changes.
But let me relate another story where I had instructed one of my minions to make a minor change to a program and he complained that it would require duplicating this entire screen of code to insert a space in the output. "Unless you know a better way." which is what he used to say to his previous manager. Unfortunately, I did. It took a few minutes of playing in immediate mode, but I wrote an equivalent subroutine in only three lines of code. (which ended up being more robust than his POS) He came around and while he'd still try using that line on me, this time around he was asking for help instead of trying to avoid work.
But a classic case of code collapsing (as I call it) was when I was taking a class in PL/1 and the assignment was to detect the number of words on an 80 column line of text. Having just come from a life of GOTO programming. I wanted to embrace structured code and had elaborate code to deal with the special cases of words beginning the line and words at the end of the line. All the rest would be bounded by spaces. As I rolled the listing into a wide carriage typewriter to add comments to the code (otherwise I'd have to repunch the deck of cards and submit the deck to operations and wait whatever was the prevailing turnaround time) I reexamined my logic to explain what the code was doing and in doing so realized that I could have made the code vastly simpler if I had moved the supplied 80 column card image into a buffer with 82 characters with a space in the front and a space in the back. I added comments at the end of the listing stating that and I believe as a consquence I got a very good grade for my solution.
Psychosis at 10
Film at 11
Those who do not remember the past, are doomed to repeat it.
Those who do not remember the past, cannot build upon it.
|
|
|
|
|
I am still not comfortable with Linq, so I hate seeing it written out.
Along with the original 9 line problem that I revised to a 1 to 197 line output
(That I tested and passed when sending 5 and 50 to the routine. IE not a complete test and I just thought of a failure mode -> int.MinValue. Maybe not, it would just print "1", let's just say a different result than maybe expected.) the challenge was modified(increased?) to create a one line command, so I hard-coded a string with all 9 lines separated by \n. Then realized the original problem said "In a loop" so I put "for(int i=0;i<1;i++)" in front of it. It was a joke that met the new challenge and let me not think about Linq.
Your co-worker reminds me of one of my former co-workers. I always groaned when he was assigned to my three man team because then we'd act like a 1.5 man team. I silently cheered when he transferred out of our group.
|
|
|
|
|
|
At least you were remembered by the comment
|
|
|
|
|
It wasn't me.
Signed The Murderer.
I may not last forever but the mess I leave behind certainly will.
|
|
|
|
|
I have done the same thing (many times...) my worst was sending out an exe to a client (that was built on a test version I wrote) that displayed a message box with an red X on it and the message "Destroy All Humans"... phone call later in the day to my line "Hi Glenn, software works great that new fix you came up with, great. Get rid of the message box and it can go", "What message box..." and on!
|
|
|
|
|
Of course it is funny as it has come to bite you back.
Sometimes an ugly hack is necessary.
Given time restraints etc.
We may laugh when an ugly hack is accomplished and it appears to work, but we never laugh when we have to revisit and fix or tidy it.... but then we laugh again when it is fixed.
We all do it.
If some poor other coder got the job you wouldn't have even known about it.
What if someone posted a rant about it on CP and you realised that it was your comment in your code.
I wouldn't laugh then either but at least the comment was honest and apologetic and I would have understood, but I wouldn't laugh.
I tell a lie, I would laugh. Just a quick little laugh and then I would be indignant and self righteous about it.
"Rock journalism is people who can't write interviewing people who can't talk for people who can't read." Frank Zappa 1980
|
|
|
|
|
Sometimes I laugh to hold away the tears.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
|
Judgment comes from experience. Experience comes from bad judgment.
You did the best you could at the time. Now you have better ideas. It's a sign of growth.
|
|
|
|
|
from an apparently honest guy
David
|
|
|
|
|
Actually, an honest gal. Well, maybe or maybe not honest... but definetly a gal.
|
|
|
|
|
oops, my bad
David
|
|
|
|
|
Well, the future wasn't as far you thought, wasn't it?
|
|
|
|
|
This is the voice of GOD speaking:
Have you grep'd your code for "ugly hack"?
|
|
|
|
|
I once took over maintenance of a 40,000 line, assembly language program which had only one comment:
"Be prepared with bottle in hand when working on this program."
Bottle didn't help, but I didn't care either.
|
|
|
|
|
Thanks for sharing this one, I had a really good laugh and he who has never used an ugly hack shall throw the first stone...
By the way it reminds me of the old programmer's joke where someone sifts through innumerable lines of very old, very badly written code and the only comment line he ever finds reads:"This is where the tricky part begins"
|
|
|
|
|
|
to schizophrenia.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Roses are red
Violets are blue
I'm schizophrenic
And so am I
Never moon a werewolf.
- Harvey
|
|
|
|
|
Roses are red
Violets are blue
I've got Rohypnol
And now I've got you
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Roses are red,
Violets are red,
Grass is red,
Sh*t! The garden's on fire!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Roses are red,
violets are red,
The bench is red,
The floor is red,
I seem to have cut myself badly,
Help!!
|
|
|
|