12
\$\begingroup\$

Say someone writes a question about some JavaScript code that does not use jQuery. Then, someone comes along to write a review.

In their review, the first thing they write is that the OP should use jQuery. Maybe they include a specific reason, or maybe they just say it will help overall.

Then, the code samples in the rest of their answer are all in jQuery.

Is this sort of thing allowed? I think it might be allowed because...

  • The answerer is expressing their solution and explaining why it is better.

However, I think this might not be allowed because...

  • The OP of the question may not know jQuery, or may want a review in JavaScript.
\$\endgroup\$
  • 6
    \$\begingroup\$ Food for thought: How should it be handled if it would not be "allowed"? \$\endgroup\$ – Simon Forsberg Jul 14 '15 at 23:12
  • 3
    \$\begingroup\$ @SimonAndréForsberg With downvotes. \$\endgroup\$ – nhgrif Jul 14 '15 at 23:19
  • \$\begingroup\$ @nhgrif Agreed. That's what I was hoping to hear. \$\endgroup\$ – Simon Forsberg Jul 14 '15 at 23:39
15
\$\begingroup\$

If OP wants vanilla JS, they will most probably mention it in their post, along with the reason(s) why jQuery wouldn't be usable (or, be prepared to reply to comments asking Y U NO jQuery).

If an answerer feels like pointing out how jQuery would make better code, I see no reason not to allow it, especially if the answer includes code that shows how much better life is with jQuery.

\$\endgroup\$
8
\$\begingroup\$

I see you're trying to determine when to use jQuery by analyzing the problem at hand and applying logic and reason to make an informed decision about its possible implementation. You should totally drop that and try jQuery. – snicker Apr 1 '10 at 21:28

Okay, all jokes aside, recommending different languages and/or frameworks seems completely acceptable to me, albeit with a few caveats. You mentioned the biggest one already.

The answerer is expressing their solution and explaining why it is better.

That's big. That's what makes it a review instead of just an alternative implementation. In other words,

You should totally drop that and use jQuery.

is not a valid answer and should rightfully be downvoted into oblivion.

The second part of your question is more interesting.

The OP of the question may not know jQuery, or may want a review in JavaScript.

The only time that should hold you back from making a recommendation is if OP explicitly says that using a framework is not an option and (in my opinion) has given valid reasons for it. Even then, a well laid out argument/example may give OP the ammo they need to change minds about the (often arbitrary) reasons for not using an available tool.

\$\endgroup\$
5
\$\begingroup\$

Answers that are simply wrong aren't supposed to be deleted. Answers that are supposed to be deleted are not answers at all.

What you've outlined in your question isn't a non-answer. Worst case scenario, it's a bad answer.

So, you're really asking:

What should we do with bad answers?

And the answer is simple, even if we don't do enough of it on Code Review: downvote it.

With that said, a jQuery answer to a JavaScript question may not automatically imply a bad answer. I'm not a domain expert, so I'm not passing judgment on that aspect. But you have to take things into consideration.

So, from a language-agnostic approach, here's a set of points to consider when you're thinking about posting an answer in a language other than what the question asked it in (or when you're in a position to up/down vote such an answer):

  • Does using the other language mean rewriting the entire project in the new language or can the languages be mixed in the same project?
  • If the answer to the previous question is "they can be mixed", does mixing the languages mean a lot of overhead (importing some big library or framework that may not otherwise be imported)?
  • How comfortable is the OP with the alternative language? What impact will this answer have on maintainability from the OP's perspective?
  • Is the alternative language's approach actually really that much better than the original language posted in?
  • Does the alternative language actually work well for the constraints the OP is working in (ex. recommending C# for an OS X project)?
\$\endgroup\$
3
\$\begingroup\$

You may try to answer a pure JavaScript question using jQuery, but there's a considerable risk it will not be received well, so brace yourself for possible downvotes.

Keep in mind that code review should be mainly about the posted code. Answering with an alternative implementation using jQuery is hardly a review of the posted code, even if done really well. If the alternative implementation is all you have to say, then your answer might be too weak, and possibly just not good enough.

If you can provide useful comments about the posted JavaScript, and also provide an alternative using jQuery, now that would make an excellent code review!

\$\endgroup\$
  • \$\begingroup\$ There's nothing with wrong suggestion "You should redo this entirely using this library" as long as your answer takes all of the OPs constraints into consideration and makes the effort to explain why the alternate implementation is better. \$\endgroup\$ – nhgrif Jul 18 '15 at 22:21
1
\$\begingroup\$

In my opinion, as far as code reviews are concerned, I think the latter point trumps the former; i.e., if the code I present to be reviewed is in X language using X library, I want that code reviewed, and not my code rewritten using Y library or whatever.

I think it would be wrong for an answerer to assume that there is not a good reason why the OP is not using Y library. Now, I don't think there's anything wrong with "mentioning" that Y library could make things easier, but I feel it should be done in passing, and not be the point of focus of the "review" (or "rewrite", as it may be).

\$\endgroup\$
  • 2
    \$\begingroup\$ X language here is JavaScript and Y Library is written in X Language. it's like someone suggesting usage of a C# library or someone saying hey why don't you use LINQ? I disagree. jQuery is JavaScript. unless OP specifically says "I don't want to use any JS libraries" I think it is fair game. \$\endgroup\$ – Malachi Jul 17 '15 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .