How should dangerous code fragments be published?

When you discuss (ask / answer questions about writing blog posts, etc.), some programming questions, it may be advisable to give examples of the source code of what you are talking about; but in some cases, these fragments can be dangerous, not because they are directly harmful, but because they seem to work first, but only tune in to problems later. Two examples would be when discussing concurrency issues, where the code runs most of the time, but rarely and non-deterministically fails, and when discussing security issues, where the code seems to work, but actually can be used; and there may be other examples.

It is necessary to be able to discuss such issues in order to at least contribute to their awareness. However, I am always worried that someone will come from a search engine, barely read a message, copy and paste a fragment and use it for something; more subtly, someone can read the message, try the code in a test project and confirm that it can really be used (as it is encouraged to do), then after a while reuse the dangerous code, since it forgot that the code is dangerous and more there is no blog post explaining why the code is dangerous around the fragment.

So, I’m wondering how to mark such a code so that part of it somehow does not create it (or if it ever was, then the responsible party could not plausibly deny awareness).

One of the ways I came up with is to put:

  • the #error directive (or similar) inside each function, and also
  • repeated comments warning of the danger of the code (since someone who tries the code in a test project to confirm the problem will remove the #error directive).

But since these comments will only clutter up the fragment when reading on the Internet, I make them the same color as the background (or at least I try, see how I put it into action here , I, by the way, have a question on doctype.com asking how best to do this).

, , concurrency ( ) , , ( ), ; .

( , programers.stackexchange.com , , programers.stackexchange.com, , .)

+5
2

, , . #error , .

, , - . , #error.

. , , . , , . , .

, : , . .

+1

, , , .

, , , , . , , , .

, .

0

All Articles