39

I have found that some users like to contribute by answering questions in (programming) languages other than the one the OP was working in. These answers are usually accompanied by some commentary such as, "I know you were working in C, but here's a Java implementation just in case!"

An answer in any language (or pseudo-code) is entirely appropriate for algorithmic questions ("Let me demonstrate a solution in C# for you..."), but it seems like noise and is borderline "Not An Answer" when the OP is working with a specific language, especially when the languages have very disparate constructs that would make converting the answer to the OP's chosen language difficult. I come across them the most when working through the Late Answers queue.

What is the community's opinion on these kinds of answers?

6
  • 6
    If the OP, in no way, seemed to have any interest in having the answer for a different language (can be indicated by the body and tags of the post) then downvote and/or comment are acceptable actions and all you really should do. Don't flag as NaA because it certainly is an answer.
    – codeMagic
    Commented Sep 11, 2014 at 23:20
  • 3
    This kind of "eek, wrong flavor" response is a bit silly for a question that asks for an algorithm. Its not like it is a Haskell answer to a curly brace question. But sure, it gets lots of underwear in a bundle so such answers typically get very little love. Wikipedia does it in interesting ways, but as long as language tags are the major selectors here there's very little chance we'll ever get there. Commented Sep 11, 2014 at 23:56
  • @HansPassant I completely agree that just about any language is appropriate in an answer to an algorithm question. I have edited the question to clarify that.
    – skrrgwasme
    Commented Sep 12, 2014 at 0:04
  • 1
    I wouldn't consider these cases to qualify as "Not an Answer". Depending on the question and answer, it might just be a bad answer. The same criteria apply as for any other answer. If it's not helpful for somebody who is looking for an answer to the posted question, it should be downvoted. Commented Sep 12, 2014 at 5:23
  • 2
    "especially when the languages have very disparate constructs" I think the worst would actually be if the languages have a similar syntax but are totally different (like C++ and Javascript) because then someone who only reads the code and doesn't pay attention to the rest of the answer might just copy-paste C++ code into a Javascript program without noticing that it's a completely different programming language and waste time figuring out why it doesn't work. Commented Jul 16, 2017 at 19:45
  • 1
    @DonaldDuck Meh... I don't feel bad for someone who copy/pastes code directly from a website without even trying to understand it.
    – skrrgwasme
    Commented Jul 17, 2017 at 23:44

3 Answers 3

23

It depends on the nature of the question.

Besides the algorithmic questions, sometimes the OP and the community that uses the technology that the OP is using are quite fine with getting answers in a language different from the language used in the question.

For instance, some questions have code written in CoffeeScript but are not specifically about CoffeeScript but about a specialized technology that the user happens to be using with CoffeeScript. Most users of CoffeeScript can read JavaScript. I've provided answers in JavaScript to such questions. The OP was fine with this, and the community of people reading the answer appeared fine with it too.

Another example are questions about Selenium, which exists for Java, JavaScript, Python, C#, Ruby, and other languages. The API is regular enough that it is possible for someone using Ruby to understand an answer written in Python. Again, the community of people using Selenium is okay with this. I've never seen anybody get on their high horse when an answer was given in a language different from the question.

Of course a question which is "how do I do this in Python" should not get answers in C#.

4
  • 3
    @Cody: There are a handful of differences that are decidedly not superficial. There is absolutely no way to implement an exception filter in pure C#, for example.
    – Ben Voigt
    Commented Sep 12, 2014 at 5:24
  • "Of course a question which is "how do I do this in Python" should not get answers in C#." So, what should I do if I find such an answer (example)? Flag it as NAA?
    – Georgy
    Commented Oct 11, 2019 at 7:47
  • 1
    Of course a question which is "how do I do this in Python" should not get answers in C#. So, should such an answer be flagged as Not an answer?
    – Sabito
    Commented Jul 20, 2020 at 12:01
  • 1
    @Yatin Probably not. You can do it and some will remove the Answer, while other will not with the explanation that an attempt to Answer is still an Answer, even if the Answer is really only an attempt to Answer another Question.
    – Scratte
    Commented Jul 20, 2020 at 12:06
13

This question:

Find duplicate in List(Of T) using LINQ VB .NET not working

makes a good case study. It was answered in C#, and I defended the answer, even though the OP specified VB.NET, because VB.NET runs on the same platform, and there are conversion utilities available that translate between the two languages. What I didn't know was that:

  1. The OP didn't actually know and understand VB.NET syntax, and was looking for exact code that he could paste into his program, and

  2. Lambda variables cannot be duplicated in VB.NET linq expressions, which breaks an exact translation of his code from C# to VB.NET.

Check out the comment thread here.

In the end, it worked out. But it is illustrative of the problems that can arise, even if the fundamental differences between the languages (if not the actual syntax) are relatively small.

When someone asks a question that involves code, I generally expect them to know the language that they're specifying in their question tags. If they're asking an algorithmic question, I expect them to understand simple pseudo-code examples, even if I write them in my language of choice.

Ultimately, the OP didn't even bother with Linq, preferring to loop through his data using a foreach loop instead. (Oh, excuse me... a For Each loop)

2
  • 15
    Anything that drives away people who draw a paycheck for cutting+pasting verbatim from SO is a good thing, IMO.
    – Ben Voigt
    Commented Sep 12, 2014 at 5:28
  • @pnuts: Sure it does. But it does require a bit of thinking effort on your part.
    – Robert Harvey Mod
    Commented Dec 10, 2015 at 6:50
5

The scope of the question must be clear in the question. This is done in two ways (ideally in the first of the list below).

  1. Add the language specific tag to the question. If this is done, no additional indication is necessary.

  2. State in the question body which language you need.

I am not in favor of adding the language distinction in the title of the question because it will cause unnecessary title bloat.

If distinguishing the language using #2, then it makes good, good sense to also do so in #1.

Questions that are merely asking for a general use algorithm should have NO language-specific tag. It would be more appropriate to use the tag since that is exactly what is being asked for.

Want an example? I can show you a good one, but being able to see deleted posts will be valuable because @CodyGray has done a nice, big clean up on the page to the benefit of researchers.
How to reduce consecutive integers in an array to hyphenated range expressions?


So why is posting answers in a different / unassociated language bad?

  1. Stack Overflow's search functionality has special syntax whereby researchers can filter results based on tags. When a researcher is looking for a [javascript] page, they will not benefit from seeing a whole slew of non-javascript answers. This leads to researchers having to scroll and sift through answers that are completely useless to them.

  2. Answerers who gain upvotes / answer acceptance will be earning tag points. These tag points are used by the system to indicate whether a user can be "trusted" to appropriately use additional tools/features within the scope of that tag. It makes absolutely no sense to credit a user with tag-specific points when they never posted an answer in the nominated language!

  3. Worst of all, imagine what a garbage dump Stack Overflow would be if there was no language limitation on any page?!? You would have every Tom, Dick, and Harriet flooding pages with obscure language solutions and researchers would be scrolling for days and days. Ever seen a busy question on CodeGolf SE?


So what can be done if the language is clearly specified in the question, but 1 or more answers exist in a different language?

  1. First determine if the language in the answer is a child language of the language nominated. Is it a framework that is built on the language? If the answer is arguably related to the scope of the language in the question, let it be.
  2. If the answer has no association with the language asked for, then leave a comment to the poster to inform them that the question asks for a different language.
    • The poster can then take one of the following actions:
      1. Translate their snippet into the correct language. After doing so, any new tag points earned will be properly earned.
      2. Delete their answer, then decide if it can be re-crafted and posted into the same type of question with the appropriate language distinction OR if no question yet exists, they can ask a new question and answer it themselves.
    • As a very last resort, if the poster is long gone or the poster wants to get argumentative and tells you that they posted the answer a decade ago and that old pages don't need fixing, then you can flag a moderator to come and perform the clean up.

We don't need to harsh the community by downvoting these potentially "correct answers to different questions". (This can be completely ineffective on old answers with a high vote tally anyhow.) Just comment to the poster and appeal to their sensibilities. Just tell them that you wish for SO to be an optimal researching resource and having appropriate answers on each page works toward that.

You must log in to answer this question.

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