Related:
- Why is hypothetical example code off-topic for Code Review?
- Is pseudo-code alright when asking about performance?
- 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 something that is not meant to be public.
From Stack Overflow I've learnt to simplify, minimize, and isolate the problem.
(ask specific questions, MCVE, ...)
Examples of question one may want to ask:
What is the recommended way of passing arguments to a function in JavaScript?
var f1 = function(firstname, lastname) { ... };
var f2 = function(options) { ... };
f1("Michal", "Stefanow");
f2({firstname: "Michal", "lastname": "Stefanow"});
It is hypothetical code, yet in my opinion it is a 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 Code Review 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);
Should I:
- Post on Code Review anyway?
- Post on Stack Overflow?
- Read more books?
- Make friends with developers who are better than me?