-2
\$\begingroup\$

When I have a short piece of code which doesn't contain any sensitive data and I strongly think that it could be published here I still often avoid unless it's a project of mine. (I'm not worried of being sued, but of being blamed or fired for doing something which everyone here is seeing as reasonable)

What scares me is that after years of working in many company I feel that often people are not reasonable. No one, in a company, is willing to take the responsibility of saying: "yes, you can publish the company's code". Even if it would be just one line of code. Even if after changing the name of vars it would be just a code like every other code in the net.

Users which post code are taking their responsibilities. But often what is allowed and what is reasonable is different. Who wants to blame them should ask if he is allowed to write here during the work time.. In most cases the answer is no. I suppose many members here could be blamed for the amount of time spent here during the the working time. But the risk is actually ridiculous, and everyone take that risk.

The problem with posting the code, instead, is that the code stays here forever.

Most of people are doing what is reasonable, most of people are reasonable. But when we incur under a very strict law judgement we may regret our choices

When I feel the code is anonymous enough, and that it could be possible to publish it. The problem still stays in the variable name which could make it possible to recognize it.

A tool for changing the code just a bit, I could help to meet:

  • user's will to publish
  • user's will to avoid (small) problems with company (I'm speaking of piece of code which are pretty universal)
  • community's needs (because just to exist the community need people to post their code)**
\$\endgroup\$
  • 4
    \$\begingroup\$ Why not just ask, whether you are allowed to post the source code? You know that material posted to any SE Site is licensed under CC-BY-SA 3.0, which allows others to reuse it. As the code is obviously not your own, you should ask your manager whether you may post the code and what requirements he has if he allows you to! \$\endgroup\$ – Vogel612 Dec 4 '14 at 15:08
  • \$\begingroup\$ @Vogel612: I strongly suspect the answer would be a NO! And also that no one here has ever asked. BTW, have you ever tried to do in your company? You are speaking like if people would be rational.. they will answer no just because it's easier. (ps: we got the metaphysical speaking) \$\endgroup\$ – Revious Dec 4 '14 at 15:46
  • \$\begingroup\$ What's the question here? \$\endgroup\$ – RubberDuck Apr 17 '15 at 14:39
  • \$\begingroup\$ @RubberDuck: how to automatically and partially obscure some source code before putting it on SE. \$\endgroup\$ – Revious Apr 17 '15 at 14:50
6
\$\begingroup\$

I'm not a lawyer, but based on the available information...

Anything posted on StackExchange sites will be licensed under CC-BY-SA 3.0 (click link for explanation).

Additionally, code you post must be real code that you own or maintain (for us to be able to provide you with good answers).

Thus, I don't think it would be smart to post code if you're worried others might use it, mangled or otherwise.

First, any source you post on here, other companies can use without having to pay your company. The only restriction placed towards them is that if they alter any of the code you provided, you and others may request that code and they may not deny your request (if they did, their use of your code become a breach of copyright law).

Second, with example variable names, your question will get closed. But reuse of posted code is STILL allowed.

\$\endgroup\$
  • \$\begingroup\$ Yes, but I'm speaking of publishing a few lines of code which every rational human being would understand is making no problem. But managers are not rational. Try to explain your manager that you like to write here during your work time.. \$\endgroup\$ – Revious Dec 4 '14 at 16:03
  • 1
    \$\begingroup\$ @Revious "I have a non-blocking technical issue that I have a workaround for, but I've submitted a question to see if others know how to fix the issue directly. This way I can fix the issue with it only taking 1 hour of my time instead of a full day." follow up with a progress update of whatever you're working on. If they're responsible for your project's prioritization, reconfirm that your current task has priority ("I'm working on the frobs now, that was the plan, right?"). If you get a yes, get back to work. \$\endgroup\$ – Pimgd Dec 4 '14 at 16:24
  • \$\begingroup\$ @Revious a few lines does not need obscuring, by the way. \$\endgroup\$ – Pimgd Dec 4 '14 at 16:26
  • \$\begingroup\$ this in the comment is a very good answer, which I will save for when I will eventually need. But you don't know my company... they are paranoic. \$\endgroup\$ – Revious Dec 4 '14 at 16:32
9
\$\begingroup\$

You should feel discouraged from posting code that should not be 'in the wild'. If you do not have the rights to post the code, then don't post it.

Code Review requires that the code is 'real code', and not example code. Many times it is possible to post the code you want reviewed 'as is', and it's fine. If your code has sensitive information in it (passwords, database names, etc.) then you should change those details 'to protect the information' before you post.

What about the actual code? In general, code practices recommend 'self documenting' code, where the variable names describe the type of information stored in the variable. Changing variable names, method names, etc. to 'obscure' the code, obscures the code.

Code that has been simplified too much loses its self-documenting properties, and it is no longer reasonable to expect a code review of it.

This is not an absolute, or black&white issue, there is a grey zone. It is possible to carefully alter the code to make it suitable for Code Review, while still keeping it 'real'. If you can walk that line, then feel free to do it. If you cross the line, then it's likely to get your question closed as 'not real code'.

If you can find a way to sanitize the code in a way that we can't notice, then that's great. If the sanitization ends up with names like methodA, or variableFoo then it's a problem. My experience though, is that it is very hard to sanitize like that, and still keep meaningful code. If you can do it, then no problem.

\$\endgroup\$
  • \$\begingroup\$ I'm not speaking of passwords and sensitive data but a company will never say you: "yes, you can do". Big american companies, for example, are really strict in every aspect of the HR life. However.. it would be possible to find a very good compromise (even risking a bit). I will also correct the question. \$\endgroup\$ – Revious Dec 4 '14 at 15:54
  • 3
    \$\begingroup\$ @Revious - if you can find a way to sanitize the code in a way that we can't notice, then that's great. If the sanitization ends up with names like methodA, or variableFoo then it's a problem. My experience though, is that it is very hard to sanitize like that, and still keep meaningful code. If you can do it, then no problem. \$\endgroup\$ – rolfl Dec 4 '14 at 15:59
  • \$\begingroup\$ that what was I was saying (+1).. it's like when people write here for hours. If the company would know they would not be happy. But the published code stays here for years.. How can we manage this problem? ps: can you add the last comment to the question so I can accept it? \$\endgroup\$ – Revious Dec 4 '14 at 16:00
  • \$\begingroup\$ @Revious - note that the decision of whether your company will 'allow' you to post code to Code Review is different to whether you can sanitize your code effectively. We, at Code Review, do not 'police' Copyright and other things. If there's a copyright problem, we have support for processing DMCA 'takedown' notices. If your company will not allow you to post their code here, then 'sanitizing' it to post it anyway is a decision you have to make and live with the consequences if you are caught. \$\endgroup\$ – rolfl Dec 4 '14 at 16:03
  • \$\begingroup\$ I am taking my responsibilities. I was just saying that often what is allowed and what is reasonable is different. You are smart, you know the difference. Almost everyone on earth is doing what is reasonable. But simply, if I would find a tool for sanitizing the code, I could met my needs, the company needs and also the community needs (because to exist the community need people to post their code) \$\endgroup\$ – Revious Dec 4 '14 at 16:08
  • \$\begingroup\$ I've clarified the question a lot.. \$\endgroup\$ – Revious Dec 4 '14 at 16:35

You must log in to answer this question.

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