I understand it's not so obvious here. But according to the rest of the application, it was only enough to do this: if(answers.length != 0) totalAns++; . There's too much unnecessary code here.
But there must be a logic that the person who wrote the code did not want to count an empty response? I'm guessing if someone typed in a white space with a new line or something similar and it was returned in a trimmed manner (or maybe white spaces are automatically trimmed when storing it in your db)
Extra white space if often the result of generating this code with PHP / JSP / ASP and so on. Maybe the author decided to comment some part of the code in this way...
I mean, it could be that that is not possible, it's not like we're seeing the complete code. I think it's possible that the program is done in a way that the answers are initiated with that empty string and therefore that's all the if needs to check for.
Maybe there's never zero. Like if answers is the result of a .split(...), there will always be at least 1 element in the result even for a blank input.
Then for the empty block, maybe they initially intended to do something if an answer was blank, but decided it wasn't necessary to do it there, and didn't bother to negate the if() expression.
It's how they are checking if the question was answered I guess... its not great, but they got a default value of 1 space in the first answer slot. If there is still only one answer, and it's the space, then nothing.. do not increment the answer counter.. the question is not answered...
Extra white space. Also not great. Just not so bad.
18
u/maxbirkoff May 13 '22 edited May 13 '22
what's the issue here?
I could see wanting to rename answers to theseAnswers and totalANs to numNonBlankNonEmptyAnswers or numPopulatedAnswers...
the empty clause in the if it's a little troubling, but inverting the predicate with De Morgan's law would make it less clear imo.
I guess I am not understanding what's egregious about this code. what is it?
11
u/lunar_tardigrade May 13 '22
Seems ok?
129
u/S-worker May 13 '22
This just seems like bugs with extra steps
52
u/MurdoMaclachlan public boolean isInt(int i) { return true; } May 13 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
20
u/naptastic May 13 '22
This looks like an early draft, or a sketch. It's not ready to be shown around. It either needs:
...but if it's in someone's private branch with a commit message like "asdas" because it's just a sketch, well... that's part of the process.
If this made it into a pull request, a polite "what does this if block mean, and what should it do?" would be my response.
2
u/UV5TZ39015 May 13 '22 edited May 13 '22
If not error then totalans and answer increment? totalquestions would have to stay 0 otherwise, right?
1
u/zacsxe May 13 '22
This is awful. But I’m glad they are trying something complex and obviously beyond their current skill set.
1
u/dopefish86 May 13 '22
Does look a bit unfinished ... I would never name a variable allans.
1
u/Da-Blue-Guy May 14 '22
asdas
1
u/putin_vor May 14 '22
Here's how I'd code it:
Though that creates a temporary extra array.
1
u/Ricardomillos762 May 14 '22
That extra space is free real estate
1
u/[deleted] May 14 '22
More like “for(why?)”
1
u/rafpad May 14 '22
here's the if condition is only for an empty one-single-array element.
By flipping the if condition, we could remove the else.
Actually, we could
if (answers.length > 1) totalANs++;
OR
totalANs = (answers.length > 1) ? totalANs + 1 : totalANs;
1
u/itsFoxed May 17 '22
the huge space between the if statement and else in question
1
u/pekkalacd Jun 08 '22
The empty if was necessary because...