3

Every time when I want ask here a question with a piece of code, I want to boil it down to possible minimum.

For example, a snippet from this question:

h = {'name' => 'sayuj', 
 'age' => 22, 
 'project' => {'project_name' => 'abc', 
               'duration' => 'prq'}}
d = h.dup # or d = h.clone
d['name'] = 'sayuj1'
d['project']['duration'] = 'xyz'

If I were to ask this question I would use this snippet:

original = {'a' => 1,'b' => {'c' => 1}}
dup = original.dup

dup['a'] = 100 # I changing dup, I don't touch original.
dup['b']['c'] = 100

p original['a'] # => 1 , didn't change
p original['b']['c'] # => 100 did change

Should I do this? On one hand I think that I should, because it's easier to understeand the code. But on the other hand I have to spend some time to boil it down to the minimum.

Should I edit questions in which code is not "minimized"?

Also, it helps avoid the XY problem, because it clarifies what actual problem is. I had several times when I was really sure about what the problem is and wanted to ask for help here, but just before I post the minimized code I realize that there is another problem.

2
  • 1
    Think of minimal in terms of minimal functionality, rather than minimum amount of characters.
    – Kevin B
    Commented Mar 7, 2016 at 14:51
  • 1
    shrnt txt s hrd t rd. pls tr t avd tht. Really - provide good and sensible variables/functions names that are related to problem (and don't just copy-paste wall of your code, or even worse minimized/obfuscated version of code) Commented Mar 7, 2016 at 21:11

1 Answer 1

6

You should certainly try to reduce the amount of code in your question; in fact, creating an MCVE - a Minimal, Complete, and Verifiable example, will often help you find the issue yourself.

However, be careful with renaming variables and string literals. This might throw away some of the context, which is often helpful to understand your problem. At the very least, it will make it easier for readers to identify themselves with your code. The only exception I can think of is where you need to protect sensitive data (passwords, customer information). In this particular question, I would not recommend to minimize your code.

You must log in to answer this question.

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