3

The question is marked as .

I wrote a simple answer which uses regular expressions. Do I really need to say that I'm using regular expressions when there is a regexp literal in a single line of code?

It's part of the language, not a special library. I assume the reader is aware of language syntax.


Asked because of comments to this answer:

may be you need to mention that this solution requires regex – Reddy 1 hour ago

@Reddy, isn't it clear from regex literal in the code? – Qwertiy 1 hour ago

@Qwertiy its only because the OP doesn't have a regex tag added to it. Also we cant be sure that beginners can even identify that literal as a `regex'. – Reddy 11 mins ago

3
  • You don't need to, no, but does it hurt to be as descriptive as possible?
    – CubeJockey
    Apr 5, 2016 at 13:56
  • You've linked to low quality question with extremely low quality code-only answers. "Try this" should be plain banned on SO... And it is duplicate too... really bad example to link to on meta. Apr 6, 2016 at 6:19
  • @AlexeiLevenkov, almost always single line of code doen't need any explanation - it's to short for it.
    – Qwertiy
    Apr 6, 2016 at 7:25

2 Answers 2

9

Do I really need to say that I'm using regular expressions when there is a regexp literal in sinle line of code?

No.

It's certainly important to explicitly mention any dependencies that a typical setup in that language might not have (say, jQuery in a question tagged only javascript, some other library or plugin, or a specific browser's non-standard JavaScript API).

Regular expressions are a core part of the engine here, though, and are a tool like any other. It doesn't seem necessary to mention them by name.

1
  • While this perfectly answers the question (should I name basic language feature used in the answer), for regex in particular one should provide explanation what that regex means (providing textual explanation for code is good idea in general, but regex and other similar super dense coding notations are especially hard for non-experts to read). Apr 6, 2016 at 6:27
4

If the question doesn't add a specific tag (in your case, regex), I strongly suggest adding a line that goes like you can use regex with methodX() to do this).

Why?

I've seen and answered similar questions in Java and the OP usually reverts back saying I am not familiar with this syntax / regex / method. Some people have no clue about regular expressions (and some don't know that they are actually using them) and how they work, so it would be nice if you add a little description about your code (how and why does it work?)

Note : The above suggestions are to improve your answer. IMHO, a block of code without minimal explanation is usually not helpful (remember that there could be thousands of people looking at your answer, some of them might have just started programming). Now, if the OP has actually posted a regex and says that it doesn't work, then it's completely acceptable to skip the you can use regex part.

3
  • 1
    This is what I exactly feel. Apr 5, 2016 at 10:34
  • I don't think this post answers question, but rather provides very good recommendation about regex in general. While I agree with the post I cant vote it up because of that... I believe one would not put "this code uses plus and minus provided by XXXX language's expressions" in the answer, so why would you single out regular expressions in JavaScript where they are integral part of language (unlike Java/C# and many other where regex are provided by standard or even third-party libraries). Apr 6, 2016 at 6:34
  • @AlexeiLevenkov - I am saying that if you are not answering the OPs question based on what he has tried (or what he expects), it is always better to tell why some other approach is better (and possibly add some description of what you are doing). This doesn't apply to just regex questions. It applies to all questions where you have multiple ways of getting the solution :) Apr 6, 2016 at 6:39

You must log in to answer this question.

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