For this episode of Spot The Bug, we have a tale of imperfect inputs, followed by even more imperfect handling.
![]() |
| Have a blessed bug-free day. |
Here's the context. I had a stream of feedback input from a database, and to be blunt, it was a terrible design. All it had were text strings, and there wasn't even a classification field. There were two types of feedback - compliments and criticism. Compliments were the default, unless the string contained the substring "_ctiticism_".
Here's a sample.
[
"_criticism_Loads really slowly.",
"_criticism_Font too small.",
"Great color scheme!",
"There was a lot of thought put into this, and it shows.",
"_criticism_The information could be better placed.",
"_criticism_The navigation is confusing.",
"I really like the overall layout.",
"_criticism_The buttons don't look clickable enough.",
"This is surprisingly easy to use.",
"_criticism_There is too much information on the screen at once.",
"_criticism_The search function could be improved.",
"The interface feels clean and modern.",
"_criticism_It takes too many clicks to get where I want to go.",
"_criticism_The headings don't stand out enough.",
"Everything seems to work exactly as expected.",
"_criticism_The mobile layout needs some work.",
"I like how the important information is easy to find.",
"_criticism_Some of the wording is unnecessarily complicated.",
"_criticism_The page feels a little cluttered.",
"The attention to detail is impressive.",
"_criticism_It isn't immediately obvious what I'm supposed to do next.",
"_criticism_The contrast between some elements is too low.",
"The overall experience is very intuitive.",
"_criticism_The help text isn't particularly helpful."
];
"_criticism_Loads really slowly.",
"_criticism_Font too small.",
"Great color scheme!",
"There was a lot of thought put into this, and it shows.",
"_criticism_The information could be better placed.",
"_criticism_The navigation is confusing.",
"I really like the overall layout.",
"_criticism_The buttons don't look clickable enough.",
"This is surprisingly easy to use.",
"_criticism_There is too much information on the screen at once.",
"_criticism_The search function could be improved.",
"The interface feels clean and modern.",
"_criticism_It takes too many clicks to get where I want to go.",
"_criticism_The headings don't stand out enough.",
"Everything seems to work exactly as expected.",
"_criticism_The mobile layout needs some work.",
"I like how the important information is easy to find.",
"_criticism_Some of the wording is unnecessarily complicated.",
"_criticism_The page feels a little cluttered.",
"The attention to detail is impressive.",
"_criticism_It isn't immediately obvious what I'm supposed to do next.",
"_criticism_The contrast between some elements is too low.",
"The overall experience is very intuitive.",
"_criticism_The help text isn't particularly helpful."
];
I know, I know, this was shit. But I made do with what I was given. If I had my way, this would at least be a properly-formatted JSON string. Oh well. The point of this was to have a page which would receive the array, and render compliments and criticisms differently.
Here was the CSS....
<style>
body
{
font-size: 16px;
font-family: georgia;
}
.feedback
{
width: 80%;
padding: 1em;
border-radius: 20px;
margin-bottom: 1em;
}
.compliment
{
border: 5px solid rgb(200, 200, 255);
}
.criticism
{
border: 5px solid rgb(255, 200, 200);
}
.feedback.compliment::before
{
content: "\2713";
color: rgb(200, 200, 255);
margin-right: 1em;
}
.feedback.criticism::before
{
content: "\2717";
color: rgb(255, 200, 200);
margin-right: 1em;
}
</style>
body
{
font-size: 16px;
font-family: georgia;
}
.feedback
{
width: 80%;
padding: 1em;
border-radius: 20px;
margin-bottom: 1em;
}
.compliment
{
border: 5px solid rgb(200, 200, 255);
}
.criticism
{
border: 5px solid rgb(255, 200, 200);
}
.feedback.compliment::before
{
content: "\2713";
color: rgb(200, 200, 255);
margin-right: 1em;
}
.feedback.criticism::before
{
content: "\2717";
color: rgb(255, 200, 200);
margin-right: 1em;
}
</style>
...and this was the JavaScript. Nothing fancy.
<script>
function isNotCompliment(text)
{
if (text.indexOf("_criticism_") != -1) return true;
return false;
}
function addFeedback(feedback)
{
for (var i = 0; i < feedback.length; i++)
{
var div = document.createElement("div");
div.className = "feedback " + (isNotCompliment(feedback[i]) ? "criticism" : "compliment");
div.innerHTML = feedback[i].replaceAll("_criticism_", "");
document.body.appendChild(div);
}
}
</script>
function isNotCompliment(text)
{
if (text.indexOf("_criticism_") != -1) return true;
return false;
}
function addFeedback(feedback)
{
for (var i = 0; i < feedback.length; i++)
{
var div = document.createElement("div");
div.className = "feedback " + (isNotCompliment(feedback[i]) ? "criticism" : "compliment");
div.innerHTML = feedback[i].replaceAll("_criticism_", "");
document.body.appendChild(div);
}
}
</script>
Looks OK so far.
Later on, though, I decided to refactor. Because isNotCompliment() was simply a stupid name. Making functions based on a negative clause just adds unnecessary complexity to things.
<script>
function isCompliment(text)
{
if (text.indexOf("_criticism_") >= -1) return true;
return false;
}
function addFeedback(feedback)
{
for (var i = 0; i < feedback.length; i++)
{
var div = document.createElement("div");
div.className = "feedback " + (isCompliment(feedback[i]) ? "compliment" : "criticism");
div.innerHTML = feedback[i].replaceAll("_criticism_", "");
document.body.appendChild(div);
}
}
</script>
function isCompliment(text)
{
if (text.indexOf("_criticism_") >= -1) return true;
return false;
}
function addFeedback(feedback)
{
for (var i = 0; i < feedback.length; i++)
{
var div = document.createElement("div");
div.className = "feedback " + (isCompliment(feedback[i]) ? "compliment" : "criticism");
div.innerHTML = feedback[i].replaceAll("_criticism_", "");
document.body.appendChild(div);
}
}
</script>
What Went Wrong
Everything registered as a compliment now! Which was really affirming, but wrong.Why It Went Wrong
For some fucked-up reason, I was trying to say, text is a compliment if "_criticism_" is not found. Whereas before, I was trying to say text is not a compliment if "_criticism_" is found.function isCompliment(text)
{
if (text.indexOf("_criticism_") >= -1) return true;
return false;
}
{
if (text.indexOf("_criticism_") >= -1) return true;
return false;
}
But instead, I ended up saying, text is a compliment whether or not "_criticism_" is found. Which was pretty dumb.
How I Fixed It
Replaced the ">" operator in the If block with another "=". Problem solved.function isCompliment(text)
{
if (text.indexOf("_criticism_") == -1) return true;
return false;
}
{
if (text.indexOf("_criticism_") == -1) return true;
return false;
}
A simple fix to a problem that should never have been. That was one helluva brain fart.
Moral of the Story
First lesson - avoid negative clauses if a positive clause can be used. This simplifies things. Second, well, don't be a moron and avoid being too permissive in your If blocks.My _compliments_,
T___T
T___T



















