'Share Your Comment'.replace('{token that\'s obviously not present in the previous string literal}', count);



  • Found inside a loop for a commenting system:

    				if(count > 1) { links[i].innerHTML = '{num} Comments'.replace('{num}', count); }
    				else if(!count) { links[i].innerHTML = 'Share Your Comment'.replace('{num}', count); }
    				else { links[i].innerHTML = '1 Comment'.replace('{num}', count); }
    

    How many WTFs can you find?


  • Discourse touched me in a no-no place

    @steamer25 said:

    How many WTFs can you find?

    The fact that when this bollocks reached my inbox that neither the subject, not the body made it intact/readable? (CS bug, known.)

    The fact upon bothering to follow the link to the OP found not a lot different to what I saw in my mail box? (not a CS bug.)

     How many tabs do you need to make a code snippet unreadable? If you're trying to indicate how deep it is in a for() or if() chain, include them, otherwise don't bother.

    How much information do you feel the need to cram into the subject of your post? (not a CS bug.)



  •  I've seen this pretty regularly. It's called copy and paste because the idle bastard who wrote this couldn't be bothered to write 'links[i].innerHTML =' on each line when he/she finds it much easier to press CTRL+V and just change whats needed. Sure, they could have deleted the '.replace' too, but often that gets left as it doesn't really stop it from working.

    When under a deadline, these kinds of things are normal - just write whatever crap comes out of the fingers and leave it like that until you have the time to tidy it up (usually some 92nd version or so). 



  •  @steamer25 said:

    Found inside a loop for a commenting system:

    				if(count > 1) { links[i].innerHTML = '{num} Comments'.replace('{num}', count); }
    				else if(!count) { links[i].innerHTML = 'Share Your Comment'.replace('{num}', count); }
    				else { links[i].innerHTML = '1 Comment'.replace('{num}', count); }
    

    How many WTFs can you find?

     

    Five.

    1. The code would be more obvious in this order: "if(count == 0) {...} else if(count == 1) {...} else {...}"
    2. The first line, '{num} Comments'.replace('{num}', count) could be replaced by count+' Comments'
    3. The second line's useless replace()
    4. The third line's useless replace()
    5. It should really be "One Comment", not "1 Comment"


  • @immibis said:

    It should really be "One Comment", not "1 Comment"
    I disagree. Using '1' makes it consistent with the general case, where you use digits instead of words.



  • @immibis said:

    5. It should really be "One Comment", not "1 Comment"

     

    6. It should really be "No Comment!" for count == 0.


  • :belt_onion:

    @Ilya Ehrenburg said:

    @immibis said:

    5. It should really be "One Comment", not "1 Comment"

     

    6. It should really be "No Comment!" for count == 0.

    Still missing the logic to exclude "Frist" comments from the count. Maybe something like count = count - 3?

     



  •  Together with an attempt to prevent frists:

    if (count < 8) { count = 10; }

    else if (count > 15) { count -= 3; // there's always three that post frist anyway }


  • Discourse touched me in a no-no place

    @Zecc said:

    @immibis said:

    It should really be "One Comment", not "1 Comment"
    I disagree. Using '1' makes it consistent with the general case, where you use digits instead of words.

    http://www.grammarbook.com/numbers/numbers.asp


  • @PJH said:

    http://www.grammarbook.com/numbers/numbers.asp
    I see. The system should spell out all numbers because it's at the beginning of a sentence.



  • @Zecc said:

    @PJH said:

    http://www.grammarbook.com/numbers/numbers.asp
    I see. The system should spell out all numbers because it's at the beginning of a sentence.

    But there's no verb.  It is not a sentence.  It is, instead, an inventory item.  I will laugh at any and all grammar books which state one should spell out numbers that occur at the beginning of an inventory item.  If Strunk and White said such a ludicrous thing, I'd laugh even at them.


Log in to reply