Related:
- http://meta.codereview.stackexchange.com/questions/1709/why-is-hypothetical-example-code-off-topic-for-code-review
- http://meta.codereview.stackexchange.com/questions/594/is-pseudo-code-alright-when-asking-about-performance
- http://meta.codereview.stackexchange.com/questions/1981/the-gray-areas-of-code-review-hypothetical-example-code
My concrete examples usually contain some proprietary things. Even a variable name or package name can convey meaning of something that is not public.
From StackOverflow career I've learnt to simplify, minimize, isolate the problem. (ask specific questions)
Examples of question one may want to ask:
What is the recommended way of passing arguments to the function in JavaScript?
var f1 = function(firstname, lastname) { ... };
var f2 = function(options) { ... };
f1("Michal", "Stefanow");
f2({firstname: "Michal", "lastname": "Stefanow"});
It is a hypothetical code, yet in my opinion it is perfectly valid question about best practices in terms of code structure and readability.
Another one I would like to ask personally but I cannot post it to http://codereview.stackexchange.com/ as it is hypothetical. And I cannot include the actual code because variable names convey some meaning and I want to avoid paying hefty compensation.
What would be the best way to ask the question about following code?
Option 1:
var iammicrowave = /(microwave)/.test(navigator.userAgent);
if (iammicrowave) {
var settings = { blah : 42 };
magicFunction(settings);
} else {
magicFunction();
}
Option 2:
var iammicrowave = /(microwave)/.test(navigator.userAgent);
var settings;
if (iammicrowave) {
settings = { blah : 42 };
}
magicFunction(settings);
Option 3:
var iammicrowave = /(microwave)/.test(navigator.userAgent);
var settings = imamicrowave ? { blah : 42 } : undefined; // or maybe {} here?
magicFunction(settings);
Shall I:
- post on CodeReview anyway?
- post on StackOverflow?
- read more books?
- make friends with developers who are better than me?