'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?
-
@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.
- The code would be more obvious in this order: "if(count == 0) {...} else if(count == 1) {...} else {...}"
- The first line, '{num} Comments'.replace('{num}', count) could be replaced by count+' Comments'
- The second line's useless replace()
- The third line's useless replace()
- 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.
-
@Ilya Ehrenburg said:
Still missing the logic to exclude "Frist" comments from the count. Maybe something like count = count - 3?@immibis said:
5. It should really be "One Comment", not "1 Comment"
6. It should really be "No Comment!" for count == 0.
-
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 }
-
@Zecc said:
http://www.grammarbook.com/numbers/numbers.asp@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.
-
@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.