Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. 1,2,3,4...lots of...what exactly?

1,2,3,4...lots of...what exactly?

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpjavaphpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrei Straut
    wrote on last edited by
    #1

    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.

    B S 2 Replies Last reply
    0
    • A Andrei Straut

      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.

      B Offline
      B Offline
      BillW33
      wrote on last edited by
      #2

      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.

      A L 2 Replies Last reply
      0
      • B BillW33

        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.

        A Offline
        A Offline
        Andrei Straut
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Andrei Straut

          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.

          S Offline
          S Offline
          S Houghtelin
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • B BillW33

            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.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            CIDev wrote:

            defensive offensive coding

            FTFY :-)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups