1,2,3,4...lots of...what exactly?
-
While debugging a legacy stored proc from one of our systems, I've come across this:
CREATE PROCEDURE p_create_po_serial (
IN param_reception_ids VARCHAR(255),
IN param_serial_nos VARCHAR(1023),
OUT serial_no_ids VARCHAR(1023))
BEGIN
/*Current reception id to parse*/
DECLARE id_to_parse VARCHAR(255);
/*Left reception ids to parse*/
DECLARE temp_reception_ids VARCHAR(255);
/*Counter to count something, I'll figure out later what I need it for*/
DECLARE cunt INT;
SET temp_reception_ids = param_reception_ids;
SET serial_no_ids = '';
SET cunt = 0;WHILE (length(temp_reception_ids) > 0) DO
SET id_to_parse = SUBSTRING_INDEX(temp_reception_ids, ';', 1);
SET serial_no_ids = concat(serial_no_ids, '-', id_to_parse);SET temp\_reception\_ids = SUBSTRING(temp\_reception\_ids, length(id\_to\_parse) + 2, length(temp\_reception\_ids)); SELECT id\_to\_parse, temp\_reception\_ids; SET cunt = cunt + 1;
END WHILE;
END;
No variable or method names have been replaced. That would've taken away all the beauty of it. Now, what I've actually been amused exactly, is that besides the funny (intended or not) misspelling of 'count' - and yes, I know CP will replace the variable name with '*', is that absolutely no-one knows what the counter was supposed to be used for. Counting the while steps maybe? However, on the grander scheme of things, this proc is actually quite ok, and it even has comments :omg: (and yes, they were useful)!! And what it was supposed to do was this: - Take a string parameter that contained some IDs separated by ';' - Take each id from that string and do some selects using that id as parameter - Extract data from those selects and do some inserts / updates with it, depending on some other conditions But again, that count, and its associated comment, just made my day!
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
While debugging a legacy stored proc from one of our systems, I've come across this:
CREATE PROCEDURE p_create_po_serial (
IN param_reception_ids VARCHAR(255),
IN param_serial_nos VARCHAR(1023),
OUT serial_no_ids VARCHAR(1023))
BEGIN
/*Current reception id to parse*/
DECLARE id_to_parse VARCHAR(255);
/*Left reception ids to parse*/
DECLARE temp_reception_ids VARCHAR(255);
/*Counter to count something, I'll figure out later what I need it for*/
DECLARE cunt INT;
SET temp_reception_ids = param_reception_ids;
SET serial_no_ids = '';
SET cunt = 0;WHILE (length(temp_reception_ids) > 0) DO
SET id_to_parse = SUBSTRING_INDEX(temp_reception_ids, ';', 1);
SET serial_no_ids = concat(serial_no_ids, '-', id_to_parse);SET temp\_reception\_ids = SUBSTRING(temp\_reception\_ids, length(id\_to\_parse) + 2, length(temp\_reception\_ids)); SELECT id\_to\_parse, temp\_reception\_ids; SET cunt = cunt + 1;
END WHILE;
END;
No variable or method names have been replaced. That would've taken away all the beauty of it. Now, what I've actually been amused exactly, is that besides the funny (intended or not) misspelling of 'count' - and yes, I know CP will replace the variable name with '*', is that absolutely no-one knows what the counter was supposed to be used for. Counting the while steps maybe? However, on the grander scheme of things, this proc is actually quite ok, and it even has comments :omg: (and yes, they were useful)!! And what it was supposed to do was this: - Take a string parameter that contained some IDs separated by ';' - Take each id from that string and do some selects using that id as parameter - Extract data from those selects and do some inserts / updates with it, depending on some other conditions But again, that count, and its associated comment, just made my day!
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
That is defensive coding; adding a "just in case you need it" counter. ;)
Just because the code works, it doesn't mean that it is good code.
CIDev wrote:
That is defensive coding; adding a "just in case you need it" counter.
In case you need it and what, you can't create it? :laugh: :laugh: It looks to me more like 'Well, I've just forgotten about it', which is actually ok :-D :thumbsup:
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
-
While debugging a legacy stored proc from one of our systems, I've come across this:
CREATE PROCEDURE p_create_po_serial (
IN param_reception_ids VARCHAR(255),
IN param_serial_nos VARCHAR(1023),
OUT serial_no_ids VARCHAR(1023))
BEGIN
/*Current reception id to parse*/
DECLARE id_to_parse VARCHAR(255);
/*Left reception ids to parse*/
DECLARE temp_reception_ids VARCHAR(255);
/*Counter to count something, I'll figure out later what I need it for*/
DECLARE cunt INT;
SET temp_reception_ids = param_reception_ids;
SET serial_no_ids = '';
SET cunt = 0;WHILE (length(temp_reception_ids) > 0) DO
SET id_to_parse = SUBSTRING_INDEX(temp_reception_ids, ';', 1);
SET serial_no_ids = concat(serial_no_ids, '-', id_to_parse);SET temp\_reception\_ids = SUBSTRING(temp\_reception\_ids, length(id\_to\_parse) + 2, length(temp\_reception\_ids)); SELECT id\_to\_parse, temp\_reception\_ids; SET cunt = cunt + 1;
END WHILE;
END;
No variable or method names have been replaced. That would've taken away all the beauty of it. Now, what I've actually been amused exactly, is that besides the funny (intended or not) misspelling of 'count' - and yes, I know CP will replace the variable name with '*', is that absolutely no-one knows what the counter was supposed to be used for. Counting the while steps maybe? However, on the grander scheme of things, this proc is actually quite ok, and it even has comments :omg: (and yes, they were useful)!! And what it was supposed to do was this: - Take a string parameter that contained some IDs separated by ';' - Take each id from that string and do some selects using that id as parameter - Extract data from those selects and do some inserts / updates with it, depending on some other conditions But again, that count, and its associated comment, just made my day!
Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.
Andrei Straut wrote:
Counting the while steps maybe
That would be my guess. I have used counters when debugging code to count the number of times I went through a loop and append that number to a string so I could track the progress. It made it easier to find the offending record. The only thing I can think of is that it was suggested to this particular developer to use a counter for this reason but the developer didn't understand why they were being told to do this.
It was broke, so I fixed it.
-
That is defensive coding; adding a "just in case you need it" counter. ;)
Just because the code works, it doesn't mean that it is good code.