42

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 question on Stack Overflow (like, in this instance, on code block fence, and syntax highlighting)?

  • quick downvote/vote to close with the comment "Don't post images as code, read the manual", as it was done here? That seems like an advertisement for Reddit (where the same question would actually be answered)

  • or try to educate them by example, editing the question to include the code (I use Google Lens to transcribe the image to code: my phone can send the detected text directly to the clipboard of my computer: all I have to do is Ctrl+V, and some light edits)

The current FAQ "When should I make edits to code?" says:

Don't:

  • ...
  • Transcribe code from an image to text. It's just too easy to introduce new errors.

This 2016 discussion "Can we close questions that put most code in an image?" says:

If the question is well asked, well described and the image is the only problem, I would drop a comment, giving OP a chance to edit their question and replace the image with actual code

I usually don't see informative comments, just downvotes and vote to close, which, in my opinion, contribute to the negative feeling towards asking questions on Stack Overflow.

The particular question I reference at the start of this post might very well remain closed: I trust the SO Close Vote Reviewers on this, where I have posted my tag. And I thank them for their welcome of the SOCVR noob that I am (their FAQ is great).

But regarding picture as code, is it bad to replace them? Or, as expressed in SOCVR:

reject edits that simply inline images, or worse, edit the code in that's the OP's responsibility.

Yes, the OP has a responsibility to understand what the best practices are, but, in my experience, downvoting and closing a question immediately does not often lead to further investigation of how Stack Overflow works (not to mention that even I was not aware of the edit FAQ: that resource should be of interest to any new contributor asking a question on SO).

I prefer showing, hence my edit. I am interested in your opinion.

22
  • 3
    don;t forget to check the whole code obtained from Google Lens, (also not sure if it is allowed to provide user content to another site) - but we must do that, otherwise StackOverflow will never become the best IDE on the network (this last part was meant to be more sarcastic than anything else - "just post a screenshot here, it will be transcribed, corrected, optimized, ...") Commented Jan 2, 2022 at 8:32
  • 6
    Given that Stackoverflow is a question answer site and if questions may be improved by transcribing the code in the interest of community, I see no problem with it, even if it directly conflicts with the author's intent or the author's original question.
    – TheMaster
    Commented Jan 2, 2022 at 8:34
  • 1
    @user16320675 That would be neat! Adding a "Google Lens" button to the Stack Overflow inline editor ;) I suspect the Google license fee for that one might not be cheap though.
    – VonC
    Commented Jan 2, 2022 at 8:39
  • 22
    Leaving aside the issues with that specific question, the problem I see with this idea is that edits can be suggested by anyone. So if you allow transcribing images into code, users under 2k rep who are eager to help will push those edits into the review queue and now the reviewers have to spend a substantial amount of time to vet the transcription
    – blackgreen Mod
    Commented Jan 2, 2022 at 9:10
  • 8
    The canonical is Why not upload images of code/errors when asking a question?. Commented Jan 2, 2022 at 10:17
  • 6
    Not sure if it actually answers what you're asking, but I personally have a canned comment I quickly post on code-images posts (along with a close-vote and a follow): "Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly as a [mre]. You can get more formatting help here. You can also read about why you shouldn't post images/links of code."
    – Tomerikoo
    Commented Jan 2, 2022 at 10:17
  • 11
    Re "how do we educate occasional users, or new users, to the best practices to follow": We can't. Users will always take the path of least resistance. It has unfortunately become too easy to make screenshots. Though it would be nice with an approved and effective canned comment. Commented Jan 2, 2022 at 10:22
  • 5
    @PeterMortensen I don't have hard numbers and the percentage is probably low, but I do remember a few instances where it actually had a positive effect (i.e. OP replaced the image with actual code and sometimes even pinged me with a thank you)
    – Tomerikoo
    Commented Jan 2, 2022 at 10:33
  • 8
    It is true that the uptake of users that do end up editing their post to add the code as text, rather than the image, is low (in my experience), however, I feel it's a very important step that the user takes the time to do it themselves. Posting code as an image is, in my opinion, reason to downvote and/or close and the OP needs to learn what Stack Overflow is about; I feel often people that post images don't understand the community or have taken the time to. Others fixing such severe and fundamental problems doesn't fix their understanding and could likely mean they continue making such bad posts.
    – Thom A
    Commented Jan 2, 2022 at 11:35
  • 3
    No amount of commenting, downvoting, (demonstrative(?)) editing, or closing will solve this problem (they are all very inefficient tools). Outright deletion is an option, but it is probably too draconian. Commented Jan 2, 2022 at 11:41
  • 4
    cont' - Posting text as an image should be blocked at the source (like titles that are too short or using links like "https://mysite.com") - e.g. "Body cannot contain text as an image. Please copy paste the text instead. More info", but that will probably never happen. The reputation points requirement to be able use such images anyway could be set to 2500 or 5000. Weren't there some meta posts about this? Commented Jan 2, 2022 at 11:41
  • 4
    @PeterMortensen wouldn’t that require this site to recognize whether an image is “text posted as image” rather than “helpful screenshot (which may contain text as well) illustrating the issue”?
    – Holger
    Commented Jan 3, 2022 at 9:19
  • 2
    The 'don't transcribe images' rule is there for the masses of normal users who would just transcribe code without due diligence. I'm certain no one was thinking of exceptional users such as yourself... unfortunately no effort was made to carve out an exception since it would basically resort to 'picking favorites' (since it's not feasible to couch the transcription ability behind a rep threshold, for example).
    – TylerH
    Commented Jan 3, 2022 at 14:56
  • 4
    screenshots of code is another WET - a DRY principle violation. anyone who wants to try that code, will have to type it again.
    – ASh
    Commented Jan 4, 2022 at 19:33
  • 4
    On Stack Overflow, within the comments [mre] is replaced by Minimal Reproducible Example, @MrWhite , much like the prior link to SO was actually the text [main] in my comment text. The [mre] "magic link" however does not work on meta, only the main site.
    – Thom A
    Commented Jan 5, 2022 at 2:02

6 Answers 6

120

I feel that we should not be editing a post to transcribe code in an image into text. Some of these reasons have already been touched on in the other answers, such as:

  • Could introduce errors.
  • Might not replicate original characters (for example due to similar ASCII and Unicode characters, inconsistent use of tabs and spaces or non-printable characters).

I dislike the idea of using an automatic transcription tool as well, for the same reason that we don't allow automatic translations of post content; it can be inaccurate. If we allow automatic transcribers, like Google Lens, then we might as well allow people to Google Translate posts in a different language, as doing so is very similar.

Getting the OP to put the code in text is also a very important learning step for them. Often users that post code as images don't understand the site (in my experience); they see Stack Overflow as a "Free coding/consultancy service" not a Q&A site. If someone else does the "work" of posting their code as text for them, they are unlikely to learn that posting code as an image is not acceptable. In my opinion, posting an image of code is often a reason to downvote and/or Vote to Close, and if a user continues to post images of code they should be on the receiving end of a post ban, or rate limit. If people continue to transcribe their images, then they could easily continue to do so for many questions to come; wasting the time of 100's of users.

Another point that's raised in the comments, that I think is really important, is about the edit queue. If someone with < 2K reputation performs such an edit, then the reviewer has 2 choices:

  1. Reject because it's something the OP should be doing.
  2. Very carefully inspect the image and the text and make sure they are identical, which will take a significant amount of time, and then accept/reject accordingly.

Option 2 adds a huge amount of work for the person doing the review; probably more so than someone that just dumped the image into Google Lens. That isn't going to help the review queue get smaller for edits, as it's often already completely full.

The person who posted the question is by far the best person to post the code. They have access to the original code, and for them, putting the code into the question is as simple as highlight, Ctrl+C, go to post, Ctrl+V. Then the code is pasted exactly as it was in their IDE; no errors introduced, no Unicode characters misinterpreted, no arduous character by character checks by a reviewer. What we (the other users) should be doing is educating the user (see Why not upload images of code/data/errors when asking a question?) and then voting down and/or voting to close.

11
  • 23
    "Might not replicate original code (due to similar ASCII and Unicode characters)." -- not to forget about zero-width characters, and other fun unicode stuff Commented Jan 2, 2022 at 12:17
  • 2
    Yeah, those are just a couple of examples, @Zoe , the list is (unfortunately) far larger. :(
    – Thom A
    Commented Jan 2, 2022 at 12:21
  • 9
    Who needs unicode @Zoe, what about people who mix tabs and spaces in python Commented Jan 2, 2022 at 12:22
  • 2
    Yes, we should never ever give up. But I am pessimistic about the learning part. Most people don't want change or learn. Only an actual school setting (or the equivalent) that "forces" them to learn can change that. Commented Jan 2, 2022 at 12:23
  • 11
    And those people that don't want to learn or change end up with question bans, @PeterMortensen , because they continue to receive downvotes and their questions are closed with a <=0 score.
    – Thom A
    Commented Jan 2, 2022 at 12:31
  • 2
    If someone transcribed an image of code, this question might not have been solved. Commented Jan 5, 2022 at 0:22
  • Seems self correcting; If the image is transcribed the answers may not work but also may not be affected by the error. If it doesn't work the poster will mention that, then the reason is stated, "this is what's in your data, fix it if its incorrect" and we'll review. Most user's who do this are new and if they don't get a answer in 1 or 2 days or their question is closed, even when explained why, they are gone. Do we want to take advantage of the question and have it answered for others to make use of or just have it sit their gathering dust?
    – moken
    Commented Mar 21, 2023 at 9:13
  • 1
    I'm sure of your point. If the question contains an image of code, then transcribing it is the wrong action; close/down voting and (if needed) education is the answer. It's up to the OP to paste the code into Stack Overflow; if they don't do that then yes, the question will likely be closed and probably later deleted (by Roomba).
    – Thom A
    Commented Mar 21, 2023 at 9:17
  • I feel like this is true in most cases, but might not cover ALL scenarios. I've just had a suggested edit denied for converting a few lines of CSS from an image to text and directed here, but in that specific scenario this doesn't really apply IMO. Although it would have been better had the OP included the code as text, it doesn't mean another person (myself) can't do it as well. Perhaps we should be a bit more lenient with regards to this.
    – Jacob
    Commented Dec 17, 2023 at 2:36
  • 1 row, or many, @Jacob , all the points apply, including to your suggestion.
    – Thom A
    Commented Dec 17, 2023 at 9:30
  • Just to mention regarding "inconsistent use of tabs and spaces", SO converts tabs to 4 spaces when rendering a post, however they can still be accessed by viewing the source (clicking edit or via revision history > Source button).
    – wjandrea
    Commented May 26 at 16:09
48

No, it is clear from the tutorial and help pages that code and data must be in text form, so that it can be reproduced.

So close these questions for a lack of details.

7
  • 4
    Presumably "Needs details or clarity". There is also "A community-specific reason""Other - add a comment" (and the inaccurate "Needs debugging details" - "The question should be updated to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem.") Commented Jan 2, 2022 at 11:52
  • 4
    @PeterMortensen unfortunately the "close reason" system is completely inadequate a lot of the time, but that's a topic for another question. Commented Jan 4, 2022 at 18:22
  • 4
    The draconian attitude of "So close these questions for a lack of details" is exactly the attitude that brings SO's reputation down. Give the OP the opportunity improve the question. If you want the OP to read the tutorial and help pages, provide the link, however, IMHO, I think fewer visitors to SO read those pages than there are car drivers who stop at every Town Hall to read up on traffic ordinances (unposted traffic laws). Commented Jan 4, 2022 at 21:12
  • 6
    @user3481644 Agreed. Almost all offenders are new posters, and immediate deletion/downvoting without comment is not automatically OK simply because somewhere on SO it is stated that text should not be posted as an image. Immediate close voting without comment is fine and appropriate for questions that are not salvageable (e.g Off topic), but close voting a question without any explanation in this scenario is a great way to drive new users away from SO. If you want to use your privilege of downvoting/closing due to posting text as an image then also leave an explanatory comment.
    – skomisa
    Commented Jan 5, 2022 at 18:28
  • @user3481644: Agreed. OPs ought to be given the opportunity to improve their questions before any voting (incl. close voting), perhaps with a timescale measured in days. The questions do not need to appear on the public Internet until after this process. Commented Jan 16, 2022 at 11:59
  • @skomisa Don't you get some kind of warning about posting code when you try to upload an image? If not, that should definitely be changed. Commented Apr 9, 2023 at 23:14
  • 1
    @PiotrSiupa I was not aware of that, but apparently you are correct - see the answer here from NotTheDr01ds for details. That said, I think the wording of that warning could be improved.
    – skomisa
    Commented Apr 11, 2023 at 0:08
28

The answer is pretty simple: No.

There is a FAQ that addresses the issue:

Please do not upload images of code/errors when asking a question.

It is the OP's responsibility to post the actual code. The help center requires that a minimal reproducible example be provided, which cannot be done with an image.

20

I think the key point here is, as in the second bullet of your first quote:

It's just too easy to introduce new errors.

OK, in the particular case (your edit) that prompted this, I don't see an issue, at all. I spotted it in the Reopen queue and, though I skipped that, I then raised the whole issue of image-to-text transcription in SOCVR, where it was discussed at some length; and, presumably, that discussion prompted this Meta post.

With manual transcription, it really is "too easy" to inadvertently 'auto-correct' simple/trivial (but potentially significant) typos in the code (when asked to copy the text, "This is a racehouse" under a picture of a galloping horse with a jockey on it, almost all test subjects auto-corrected the spelling error, without realizing they had done so); especially tricky things are non-ASCII space/control characters and 'weird' Unicode symbols that look like plain ASCII characters. (Greek Question Marks, anyone;)

On automated transcription, I'm less sure. How good is Google Lens? Does it properly understand the difference between (say) smart quotes and plain, ASCII quotes (this is a common problem I've seen from new users in code)? Can it spot Unicode spaces? (I'm not sure what Python does with indentation using "em space" or "en space" characters – but happy to learn.)


On your more 'general' point about helping out new users: I don't see a problem with either action: editing to transcribe (as you prefer) or voting to close (as many do, and as I have often done). I think that is a personal choice – however, I admire your willingness to help/guide/educate new users: after all, we have no problem editing to add proper code formatting.

2
  • 3
    To be fair, Google Lens is far from perfect, especially with code. You definitively need to edit the text Lens has detected.
    – VonC
    Commented Jan 3, 2022 at 6:49
  • "test subjects" - Sorry, what test? If you're citing a scientific study, please link it.
    – wjandrea
    Commented May 26 at 16:11
6

From the original question:

Yes, the OP has a responsibility to understand what the best practices are, but, in my experience, downvoting and closing immediately a question does not often lead to further investigate how Stack Overflow works (not to mention that even I was not aware of

While we do have a lot of community guidelines around here that are difficult for new users to discover, IMHO this just isn't one of them. New users (less than 20 rep, I believe), receive a warning message when inserting an image into their question through the toolbar:

Image warning

Images are useful in a post, but make sure the post is still clear without them. If you post images of code or error messages, copy and paste or type the actual code or message into the post directly.

I usually try to be quite sympathetic to issues in users' posts (especially new users), and correct them as I can, but when they willfully ignore this warning and post text-as-image-only (when text is available), I'm honestly okay with them receiving downvotes or closure until the problem is fixed. We can certainly post a comment reminding them of this, but keep in mind that it's a warning they've already received at least once.

Of course, I will usually take the rest of the quality of the post into account. If it's a very well-researched and/or really good question other than the text-as-image problem, I'll probably be more "forgiving" ...

2
  • That text is unfortunate. It could be read as "Text as an image is perfectly OK to post. They want me to do this extra work. For what? The text is right there in the image! I am not going to do it." Commented Sep 18, 2022 at 19:13
  • @Peter How does "make sure the post is still clear without them" jive with "Text as an image is perfectly OK to post"?
    – wjandrea
    Commented May 26 at 16:15
-14

My understanding is that if you edit someone else's code into the question, you are adding content to the site that is not yours and infringing the author's copyright. If someone has shown a picture of their code, that does not grant you permission to post their actual code on the site.

Regardless of whether it is text or an image, someone can include the URL of a resource in a post without asserting or granting any rights over that resource. Adding the code itself to the question assumes the author's permission to do so and to grant SO permission to keep the code according to SO's licence.

The OP has to post their own code to grant the site the licence to keep it.

According to Zoe's comment, if the image is uploaded to stack.imgur then it is licensed by that action; so it follows that this concern only applies to images residing on any other location.


I'm not saying that copyright affects images and text differently; I'm saying that including the URL of an image is the same as including the URL of some code on another site. Suppose a question is posted saying

Why doesn't this code work? 
[some GitHub url]

The linked code hasn't been posted to the site, only its URL has, so for an editor to add the code to the question, trying to be helpful, would be assuming rights over the code that they are not entitled to.

Similarly, if someone posts

Why doesn't this code work? 
[some image url]

then the code depicted in the image has not been posted to the site, only its URL has, so it hasn't been put under SO's licence, unless the image was posted to stack.imgur.

Not a lawyer.

12
  • 4
    Interesting angle. Do you have a citation for this? Commented Jan 2, 2022 at 9:19
  • 1
    No, but that's my understanding. A picture of code is really a link to some information that's not in the question. By editing the code into the question, you're putting it on the actual site, which the OP is supposed to do to grant the site the licence to keep it.
    – khelwood
    Commented Jan 2, 2022 at 9:27
  • 23
    That argument might hold for third party hosts, but if it's uploaded to stack.imgur (as in, it's uploaded through the editor), it's already licensed under CC-By-SA 4.0 on-site. Seems to me like this won't hold up for most images on the site. (Also not a lawyer, for the record) Commented Jan 2, 2022 at 10:57
  • 2
    Automated processing does not affect copyright. OCR is automated processing.
    – Holger
    Commented Jan 3, 2022 at 9:16
  • 1
    @Holger I didn't mean that converting the image to text affected the copyright. I meant that posting content directly on the site, in the text of the question, that was previously only a url of content posted elsewhere, assumed rights that the OP had not granted. But according to Zoe, posting a picture of code on stack.imgur grants the required rights, so in those cases it is not an issue.
    – khelwood
    Commented Jan 3, 2022 at 15:36
  • 2
    Different countries have different laws, but as far as I know, most (if not all) copyright laws deal with publication from the user’s (citizen’s) perspective rather than “where is it hosted”. So, as soon as the OP has included the image into this site as part of their question, appearing to us as integral part of the question, running OCR on it and including it as text makes no difference—we still see the text as part of the question as published by the OP Denying accessibility is rarely seen as a right of the creator, rather more than often, providing accessibility may excel copyright aspects
    – Holger
    Commented Jan 3, 2022 at 15:49
  • 1
    @Holger Regardless of whether it is text or an image, there is certainly a legal difference between including code in a question and including the url of a resource containing some code. I can include a url in a post without asserting or granting any legal rights to the contents of that resource.
    – khelwood
    Commented Jan 3, 2022 at 16:43
  • 2
    Also, for the record, the image license appears in the upload dialog: "User contributions licensed under cc by-sa". Commented Jan 4, 2022 at 10:05
  • 11
    I'm not sure why this answer has a delete vote on it. It's a valid answer, and relevant to the question. Disagreement with the contents of the answer should be expressed via downvotes (or comments), not deletion.
    – cigien
    Commented Jan 4, 2022 at 12:01
  • 1
    If you can reproduce the code from an image, there is no difference in the copyright protection. Reference - the (now ancient) computer magazines that published copyrighted code for subscribers to type in. If a person posts an image of the text of their code and somebody else types it in, it is the same content in a different format - but the same content in the same location. No new content was added. Commented Jan 4, 2022 at 21:31
  • 1
    I think people are misunderstanding my point. I can find some image of code on the internet and include it in my question just by typing the URL in the question. That isn't the same as posting code to the site. Writing a URL in a post doesn't assert ownership over the contents of that URL. I understand that if the image is uploaded to stack.imgur, that's a different situation because that implies agreeing to the licensing terms of stack.imgur. But other than that, transcribing code into a question is assuming the author's right to place that content under SO's licence.
    – khelwood
    Commented Jan 4, 2022 at 21:40
  • infringing the author's copyright -- [citation needed] it's not always the author's. It could be some code found on another forum that the OP wants an answer, then copy-paste into that forum. Not saying that that's happened before, but still.. Commented Jan 5, 2022 at 0:24

You must log in to answer this question.

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