They said:

Questions must involve real code that you own or maintain. Pseudocode, hypothetical code, or stub code should be replaced by a concrete implementation. Questions seeking an explanation of someone else's code are also off-topic.

My approach (which someone edited to "one approach") is the REAL CODE that what we currently have in PRODUCTION.

Link to the question: Check if a variable is one of a set of valid strings

I do not want my question to be "reopened". I just want to point out what happened and see if I'm wrong.

| | | | | |
  • \$\begingroup\$ Have you copy-pasted the code directly from your code-base to Code Review Stack Exchange without any modifications at all? \$\endgroup\$ – Simon Forsberg Nov 21 '17 at 16:06
  • \$\begingroup\$ Yes, the first one was a simple copy-paste. @SimonForsberg \$\endgroup\$ – Gabriel Nov 21 '17 at 16:08
  • \$\begingroup\$ Ops, the error message is different. I changed it because the original is in pt-br. But the code itself is the same. \$\endgroup\$ – Gabriel Nov 21 '17 at 16:10
  • \$\begingroup\$ And the variable name is x also in your actual code base? \$\endgroup\$ – Simon Forsberg Nov 21 '17 at 16:11
  • \$\begingroup\$ It is x, yes, although that's not a good name at all. \$\endgroup\$ – Gabriel Nov 21 '17 at 16:12
  • \$\begingroup\$ Any thoughts? @SimonForsberg \$\endgroup\$ – Gabriel Nov 21 '17 at 17:05

The problem is that the snippet has so little context that it can't be true that you're interested in feedback on any/all aspects of the code; the snippet is basically a one-liner.

I would downvote (didn't), because I personally don't like that kind of A vs B questions with so little context there's not really anything else to say other than:

  • hmm yeah yours looks good because XYZ
  • hmm yeah the bottom snippet is better because XYZ
  • hmm how about this little one-liner snippet instead, see how XYZ makes it better

Which in my own personal opinion isn't quite in the "spirit" of what this site is about.

See How to get the best value out of Code Review for a comprehensive description of what's objectively better suited for this site.

That said, you have this:

throw new Error('OhGodWhy')

In real production code? Really? I don't blame the close-voters for deeming it "hypothetical" - the post raises most of the typical flags for that close reason, regardless of my own personal preference against A vs B questions.

Your post says:

We need to check if a given variable is either "get" or "post". If it's neither then I should throw an error.

But we don't know why you need to do that - might be you deem it "irrelevant", but if we could see at least the whole function, or at least a bigger part of the bigger picture, then reviewers could possibly suggest ways to restructure things and perhaps completely avoid throwing that error - I don't know, but that's what reviewers like to do: look at how you're solving a problem, improve your implementation, and point out things that are wrong with the current one.

IMO the "relevant note" at the bottom of the post likely makes reviewers raise an eyebrow and spawns more questions than answers: if that code handles HTTP-GET and HTTP-POST, then what do CRUD operations UPDATE and DELETE have to do with it? What's that variable doing? What's its scope? Who's using it? Why?

If you don't want reviewers to question all the things and raise every flag they can, then you're not looking for a code review - you have a specific programming question (likely opinion-based), but you're not asking for a peer review.

And that's why I'm not going to single-handedly reopen your question: I agree with its closure.

| | | | | |
  • 1
    \$\begingroup\$ 1 - My question wasn't only about A vs B, it was open to new suggestions as well (the two answers at the time present new ways of doing what I want to do). Anyway I agree there is little context and I should improve this. \$\endgroup\$ – Gabriel Nov 21 '17 at 17:45
  • \$\begingroup\$ 2 - the "OhGodWhy"is not in production. I used this in my question because the original message is in pt-br and I dont see why the error message is so relevant. \$\endgroup\$ – Gabriel Nov 21 '17 at 17:46
  • \$\begingroup\$ 3 - Same as 1... \$\endgroup\$ – Gabriel Nov 21 '17 at 17:47
  • 4
    \$\begingroup\$ The main problem that I see with the question is that it lacks sufficient context for us to give your proper advice. Code doesn't exist in a vacuum — it's used for something. I downvoted, having left the comment "Please show the code in context: what happens after the validation succeeds or fails? Are you writing a webserver or what? Are these HTTP methods?" I could have closed the question as "Unclear what you are asking", but refrained. Now that five community members have closed it, though, I'm also not going to override their votes unless the necessary context is added. \$\endgroup\$ – 200_success Nov 21 '17 at 17:56
  • \$\begingroup\$ I won't add anything to my question because I disagree on your edit. Your edit made me want to delete my question, but there was one answer there so I didn't delete it. @200_success \$\endgroup\$ – Gabriel Nov 21 '17 at 18:01
  • 2
    \$\begingroup\$ @Gabriel I don't see what's wrong with 200's edit, and FWIW you don't seem to be coming here with an open-minded attitude / genuinely wanting to improve your question. If you're looking for confrontation, you're in the wrong place. If all you wanted was to rant about your question being closed, you've done that, now move on: we told you what was wrong with your question, so either you fix your post and we'll reopen it, or you go on & everyone has a nice day. Holding a childish grudge over an edit (legit or not) isn't going to get you anywhere. \$\endgroup\$ – Mathieu Guindon Nov 21 '17 at 18:09
  • \$\begingroup\$ From this question: "I just want to point out what happened and see if I'm wrong.". And don't be rude. @Mat'sMug \$\endgroup\$ – Gabriel Nov 21 '17 at 18:12
  • 1
    \$\begingroup\$ Also I already understood why my question got closed and I kind of agree. That's all. \$\endgroup\$ – Gabriel Nov 21 '17 at 18:14

the type of question that you are asking is not something that we really like to answer, because it involves your co-workers code, for which we don't know if you have permission to post his code. you are posing his code versus your code and this causes conflicts with the purpose of the site.

This actually falls under the last statement in the close reason that was given

Questions seeking an explanation of someone else's code are also off-topic.

"Questions must involve real code that you own or maintain. Pseudocode, hypothetical code, or stub code should be replaced by a concrete implementation. Questions seeking an explanation of someone else's code are also off-topic." – Mast, Toby Speight, Marc-Andre

I suggest looking at the link

| | | | | |
  • \$\begingroup\$ 1) it does not matter at all for you; 2) that's not the reason they left on the question. \$\endgroup\$ – Gabriel Nov 21 '17 at 16:15
  • \$\begingroup\$ it does, and it is. \$\endgroup\$ – Malachi Nov 21 '17 at 16:15
  • \$\begingroup\$ About your edit: it is MY CODE. I showed my co-worker's suggestion just for the sake of completeness. It doesnt really matter. \$\endgroup\$ – Gabriel Nov 21 '17 at 16:16
  • \$\begingroup\$ When I click on your link, Chrome says "Attackers might be trying to steal your information". \$\endgroup\$ – Gabriel Nov 21 '17 at 16:21
  • 1
    \$\begingroup\$ the site must not be set up for https....I thought all the stack sites were set up for https \$\endgroup\$ – Malachi Nov 21 '17 at 16:25
  • 2
    \$\begingroup\$ I disagree with this answer, I don't think that's the problem here at all. \$\endgroup\$ – Simon Forsberg Nov 21 '17 at 16:26
  • 3
    \$\begingroup\$ Even if it is the code of a coworker, it is still code that the OP "maintains", so the potential legal issues is not a problem here. \$\endgroup\$ – Simon Forsberg Nov 21 '17 at 16:27
  • 2
    \$\begingroup\$ "or code that you maintain." I do. \$\endgroup\$ – Gabriel Nov 21 '17 at 16:27
  • \$\begingroup\$ @SimonForsberg I don't think the employee owns the company. If they don't, then it's the companies IP, and not the employees to give away. \$\endgroup\$ – Peilonrayz Nov 21 '17 at 16:30
  • 3
    \$\begingroup\$ @Peilonrayz I still don't think the legal issues are the problem here. We've had plenty of work-code posted here before. \$\endgroup\$ – Simon Forsberg Nov 21 '17 at 16:34
  • 3
    \$\begingroup\$ Even if it was the problem, there is nothing in the message to let me understand it. "Hey, you posted your co-worker's code and it can get us all in trouble, please remove it" \$\endgroup\$ – Gabriel Nov 21 '17 at 16:36

You must log in to answer this question.

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