Questions tagged [code]
Questions relating to code that appears in a question or answer, such as answers which are entirely code. Do not use this tag for questions about code formatting; use [code-formatting] instead - and NEVER EVER USE THIS TAG TO ASK A PROGRAMMING QUESTION ON META!.
137
questions
245
votes
1
answer
73k
views
How do I format my code blocks?
How do I post text so that it is formatted as code?
What do I need to do so that my code shows up properly—not escaped or removed—when posted? And how do I get the correct syntax ...
194
votes
12
answers
9k
views
Can we get some explicit clarification on the *intended* legal usage of code from SO answers?
I was recently told by someone that due to the fact that Stack Overflow uses the CC BY-SA 3.0 license any code examples cannot be used in a commercially available closed source application. This ...
157
votes
7
answers
4k
views
Is it bad practice to post a short answer first and then add details afterwards?
I have the habit of posting quick code-only answers to "simple" questions, and then add details / context later... for example on a question that I stumble upon in a review queue, that can ...
133
votes
6
answers
3k
views
Reduce "try this" answers by giving a helpful message
An answer that consists solely of a code block or "Try this" (and variations) followed by a code block and nothing else is usually not useful if not very low quality. So let's encourage people to fix ...
77
votes
9
answers
6k
views
Should questions about obfuscated code be off-topic?
Per another Meta it came to our attention that there was a user posting potentially malicious code. There's no real rule about that, but, for unrelated reasons of moderation, the account that posted ...
75
votes
6
answers
4k
views
But seriously. How to be nice when trying to say the code is crap?
I came upon a question just now where the OP's code has serious errors which leads to problems, and the OP asks how to solve the problems. So far, so good, but after having the serious errors pointed ...
53
votes
3
answers
889
views
Are imports useful when posting code on answers?
Today I've seen this user editing multiple posts and he's being doing it for a couple of days. His edits only remove imports on the code (Example) and sometimes he improves something else, that, IMO ...
48
votes
2
answers
2k
views
Is there really a universal code requirement?
On a question asking for an approach to solving a programming problem such as this one the user is not asking it as a "gimme teh codez" (as far as I interpret it). So I don't interpret it as being ...
47
votes
0
answers
511
views
Reach out to Code Sandbox or some other mechanism for avoiding these links
I've seen a few questions where the code is all in a markdown link with an image to Code Sandbox:
[](https://codesandbox.io/s/new)
...
44
votes
3
answers
1k
views
Are edits that insert Swift 3 code into existing Swift 2 answers acceptable?
We have received complaints about some recent edits that inserted Swift 3 code into Swift 2 answers. One such example is here. Moderators have rolled back these edits, only to have them reinstated.
...
43
votes
1
answer
819
views
Edited question made less readable
A co-worker posted a question and came back later to see that it had been edited.
TL;DR: a Java stacktrace was edited to wrap at 90 chars instead of scroll.
When we checked the edit my eyes glazed ...
42
votes
0
answers
821
views
Bad CSS on quoted code on Meta
As seen in How to include code inside a quotation?
A very quick investigation (literally, right-click, Inspect Element :D) found the cause. For some reason, the minifier has interpreted tabs to be ...
40
votes
3
answers
2k
views
What's better: a question with no attempt or with an unfixable/irrelevant attempt?
We sometimes get downvoted on Stack Overflow by posting one-liner, working answers to some users with a very clear problem, like here.
So, OK, we're not a code-writing service, but what about the bad ...
40
votes
3
answers
1k
views
How will Article 13 (EU) impact content on the Stack Exchange network?
As you hopefully know, in a few weeks, EU Parliament will vote for new copyright laws.
These new laws/directives (especially its most controversial component, Article 13) (Julia Reda shared the ...
36
votes
11
answers
1k
views
Should provided code in an answer work?
I'm wondering whether answers that involve some guidance on how to use an API or sketch an algorithm should be fully functional. I often consider the answers to be pseudo-code that guides the OP in ...
36
votes
0
answers
521
views
Punctuation characters being escaped in code
For the past couple of days, it seems that when users paste code into their questions, but don't put it into a proper code block, many punctuation characters are being automatically escaped with ...
33
votes
1
answer
1k
views
How best to correct poor coding practice which isn't related to the answer
Inspired by this question.
How should I let a user know that the code they've written goes against Microsoft's recommended practice? In this case, instantiating an SPSite instance with a hardcoded ...
32
votes
3
answers
1k
views
Is it wrong to fix mistakes in quoted material?
I found a well-received but link-only answer.
I attempted to edit the answer to copy the linked article into a blockquote but I found out that the code has a bunch of syntax errors (it looks like a ...
30
votes
0
answers
342
views
Please remove scrollbar-width: thin from code blocks AND fix the missing ends
Horizontal scrolling of code blocks is a thing to say the least.
foo bar baz buzz foo bar baz buzz foo bar baz buzz foo bar baz buzz foo bar baz buzz foo bar baz buzz foo bar baz buzz foo bar baz ...
29
votes
2
answers
1k
views
Should code from pastebin be edited into a question? [duplicate]
Sometimes when I review edits in the Suggested Edits queue, code or text from a linked pastebin is edited into the question. Is this encouraged? Should this be approved?
28
votes
6
answers
777
views
Should we change "void main()" to "int main()" in the OP's code?
Recently I noticed a question where a long time user edit the void main() in the OP's code to int main(). I left a comment asking how did he know that is not using void main()? I got a reply back ...
28
votes
0
answers
455
views
Inlining external code - copyright?
Today I came about a question in the review queue which could benefit from inlining the small code sample that was linked by OP by including it directly into the question.
But: Code hosted on Stack&...
27
votes
2
answers
772
views
Are backticks appropriate for emphasizing references to things that show up in code?
I've been following this "When should code formatting be used for non-code text?
" post for guidance on removing backticks when reviewing suggested edits as well as when forming my own questions and ...
27
votes
3
answers
409
views
Can we please have a shortcut for "Do not post code or errors as images"?
I find myself typing this phrase multiple times a day. A shortcut that led directly to the FAQ explanation would be really helpful.
26
votes
1
answer
807
views
Typos in code snippet from a good answer? [duplicate]
I tried to edit a typo in a code snippet in answer from another user (here, 4-letter edit to make, owner fixed it) but I couldn't even submit my change for review as it is only 5 char long.
This ...
26
votes
2
answers
728
views
Remind people that included files are part of an MCVE
This question concerns C or C++, but it may be relevant to other languages.
When constructing a minimal, complete, and verifiable example (MCVE), occasionally the question asker does not include the ...
25
votes
6
answers
2k
views
Should we edit a question to transcribe code from an image to text?
Context: "How to call a method from a class referenced as a string?"
More general context: how do we educate occasional users, or new users, to the best practices to follow when posting a ...
22
votes
0
answers
368
views
Should we automatically detect pastebin (and other related) sites?
New users can only post a limited amount of links. However, they might reserve this link for paste sites such as pastebin, bpaste and so on. In my opinion, these kinds of websites are useless as the ...
21
votes
0
answers
128
views
Add codesandbox.io to the list of sites that prompt to put code in the question itself?
As far as I am aware, if someone asks a question and pastes a link to websites like JSFiddle, JSBin, or CodePen, they get prompted to put code in the question itself.
Lately I've been seeing links to ...
20
votes
2
answers
1k
views
Answers with large amounts of code (whole scripts)
I answered a question (since closed: "This question needs debugging details. It is not currently accepting answers," and deleted) a little while ago, and it really is a good answer, because ...
18
votes
1
answer
554
views
Can't Seem to get This Code Into a Codeblock
I wrote an answer that uses a ton of conversions:
chrono::system_clock::to_time_t(chrono::system_clock::time_point(chrono::duration_cast<chrono::seconds>(chrono::duration<double>(input))))...
17
votes
1
answer
499
views
How to use the regular code snippets in the 2018 Stack Overflow update
I am a little confused with the new update of Stack Overflow, particularly on using the regular JavaScript/CSS/HTML code snippets we used to have to write our questions. Now the new update made it ...
17
votes
0
answers
301
views
Add a means for tab stacking code snippets
The vast majority of questions on Stack Overflow come with a specific language tag and no post in the tag will contain any language other than that specified language.
However, for some questions are ...
16
votes
1
answer
668
views
Is it possible to link directly to a full-screen code snippet?
This answer is a thing of beauty. I want to share it far and wide, but I can't figure out how to link directly to the snippet in full screen mode. The helpful "Expand Snippet" button is great and ...
16
votes
2
answers
506
views
Brackets/curly brackets highlighting in code samples
I wonder if in code samples we can highlight the closing bracket when the opening bracket is clicked (and vice versa).
This can sound like a silly feature but it does help a lot visually to quickly ...
14
votes
2
answers
627
views
How to provide additional code to comment an answer?
I asked a question and provided corresponding code inside my question using the tools Stack Overflow provides. Now, someone answered, but I feel like I need to provide additional code specific to his ...
13
votes
2
answers
608
views
What's the difference between the two code formatting styles (code-fences vs indented blocks) regarding syntax highlighting?
I have been using code fences to highlight my code in SO
```javascript
```
Recently I have noted that my code is being edited and the below syntax is being used
<!-- lang-js -->
I have seen ...
13
votes
3
answers
571
views
Stack Exchange removes certain unicode characters from code blocks (causing some code to not work)
Bug
I answered a question recently on CodeGolf.SE and my answer included the character U+0007 in my code; however, Stack Exchange (including Stack Overflow) removed certain unicode characters from ...
13
votes
3
answers
316
views
Should code samples be tailored for readability or efficiency?
Posing this question resulting from a comment debate on my answer here: send gmail using powershell - Current suggestions on S.O. are NOT working
When providing code samples on Stack Overflow, should ...
12
votes
1
answer
203
views
Which flag should I use for too much code? [duplicate]
I just got the privilege to edit or review questions and answers. Now I'm faced with the question: what flag is the right one, when the question includes too much code?
Surely Needs author edit, but ...
12
votes
0
answers
118
views
Why do we still have strange escape backslashes appearing in question code?
I was wondering why would users have that weird backslashes when pasting code. Now I noticed that this is a persisting issue1, 2, 3. Why hasn't this been solved yet? See here. I've edited several ...
11
votes
2
answers
160
views
How should I review answers with screenshots of code in Low Quality Posts?
This is related to Should I review questions with images of code as "looks ok" or "requires editing"?, but for Low Quality Posts, which I consider a different situation than Triage....
10
votes
3
answers
182
views
Do you need to change the language of variables to English when asking a question? [duplicate]
For instance, I am Dutch and most of the time is I use Dutch words to declare variables. for smaller lines of code it's easy to translate, but is it something you should always do?
Is the question ...
10
votes
5
answers
737
views
Should I demonstrate best practices in example code or be concise?
A commenter to an answer I recently posted said:
Please don't ignore errors in "example" code... You know some fool will blindly cut-n-paste it and... later make some other SO answerer's life ...
10
votes
1
answer
411
views
Should I reject or approve this code edit suggestion? [duplicate]
I've already read main question on this topic, When should I make edits to code? and this one too, still I'm not sure what to do with this edit suggestion:
https://stackoverflow.com/review/suggested-...
9
votes
2
answers
181
views
When reviewing, is it OK to accept code edits to an answer? [duplicate]
While doing reviews for suggested edits something like this occurs frequently
with comment like
... removed unused try-catch block ...
I strongly feel that if an answer "needs" code editing as ...
9
votes
1
answer
243
views
Would it be better to post code with or without the terminal prompt? [duplicate]
This is with regards to answering questions in scripting language tags such as Python, where you can also execute code in an interpreter/REPL session. I am talking about these kind of prompts:
In [...
8
votes
1
answer
405
views
Code added in edit by unrelated user
While editing a moment ago, I came across this edit which was made by a user seemingly unrelated to the OP.
The edit however added the full code that should have been in the question, which is fine ...
8
votes
1
answer
313
views
How to fix an answer with a link to plnkr.co? [duplicate]
On Jul 3 '14, Shog9 forbid plnkr.co snippet links without code on Stack Overflow.
Regarding posts left without code but with plnkr.co links: for questions, I may vote to close as "No MCVE in the ...
8
votes
1
answer
785
views
Best practice for using code snippets from Stack Overflow
Is there a best practice for reusing code snippets from Stack Overflow in production code?
Personally I always do something like this:
// Handling input that is not parseable as an integer.
// ...