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!.
43
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
6
votes
2
answers
497
views
Is it possible to add a CSS compiler/transpiler (Sass or Less) in stack code snippets?
We need to support a CSS compiler - Sass and Less. If CSS compilers are not supported on Stack Overflow code snippet which must be included. If it can't be supported in stack code snippets, allow ...
5
votes
1
answer
282
views
How to deal with post containing only code
How should I deal with stuff that contains only code (both question, "here code, fix it" and answer that has just a bunch of lines and not comment at all)?
Is:
for answer: flagging it as "This is ...
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 ...
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?
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 ...
-11
votes
1
answer
443
views
Idea - long/wide code on Stack Overflow page - expand or open in bigger window [duplicate]
My idea is only for wide and long code, not easy to read without scroll left, right, up and down. Possibility to expand (when clicking on it or hover over) or open this code in a bigger window (button)...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
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 ...
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
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 ...
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 ...
5
votes
0
answers
77
views
Why have strings within certain language-syntax code blocks gone green? [duplicate]
Strings in certain languages used to be a browny-redish colour. They're now green:
// JavaScript
"Hello, world"
// PHP
"Hello, world"
// C++
"Hello, world"
I'm very used to green representing the ...
4
votes
1
answer
79
views
Should exceptions resulting from code be inside code snippets?
I've always used block quotes to display the resulting exception from code I need help with or something I didn't understand. But for some reason people always seem to edit them and put the exception ...
3
votes
2
answers
166
views
Edit code to reduce the used space
I usually read the sql tag here on Stack Overflow and sometimes in the questions there are long queries with very little code on every single line, for example this question.
The particular point is ...
1
vote
0
answers
40
views
Please add a "full screen view" button for code parts [duplicate]
The need for horizontal scrolling on code is very annoying. Full visibility helps to better understand.
update:
Most of the time,the focus is on asking question and giving answer,and not according to ...
0
votes
0
answers
55
views
Add feature to POPUP the overflowed code [duplicate]
1) In many cases, we see the "scrolling-bar"-ed codes. It would be nice, it there was "full-screen view" button on the right bottom side, af, after clicking on it, the code should show/popup on full-...
-1
votes
2
answers
402
views
Is pasting code from the reference source from Microsoft legal?
When using .peek and ReSharper in Visual Studio (15) you can check the implementation of framework types. It will download a reference source debug file, and you can check the reference-only code.
...
-1
votes
1
answer
203
views
Prohibit low-rep users from posting links to images
No matter how much we discourage it, posters frequently write questions with all the code in an image that they link to. I personally don't think this should be a reason to close the questions -- if ...
-5
votes
1
answer
308
views
Require image of Scratch script for Scratch questions
It's hard to visualize a script in visual programming language like Scratch. Here's an example of what I mean:
The correct way to make an infinite loop without the forever block is to use the repeat ...
-6
votes
2
answers
271
views
How to ask a question about proprietary code my company won't allow me to post? [duplicate]
I am currently struggling with a piece of code at work, but legally I am not allowed to post the code online.
This is a very specific problem, and I am sure it's not possible to create a minimal code ...
-9
votes
2
answers
205
views
Piece-of-code-highlight/error highlight for Stack Overflow (and possibly others)
Similar questions
I have checked some previous questions/answers like this one: Highlight Line of Code
But I did not like the answer and this can be troublesome.
Proposal
Let's say I post a big (but ...
-40
votes
2
answers
354
views
Should we allow answers that contain hard-coded values?
I've seen answers where values in the example code are hard-coded. An example might be
if (name === "Robert") {
} else if (name === "John") {
}
It isn't considered best practice to hard-code values ...