12

I'm observing an increasing number of new questions being posted with code samples that are broken, because the code had been wrapped in places where wrapping a line is invalid. Yet the people who posted the questions claim that their code did not throw the syntax errors that the code in their question clearly does (if they respond at all, that is).

Example from a recent question in the PowerShell tag:

... | where { Test-Connection -
ComputerName $_ -Count 1 -Quiet }

The above code should actually look like this:

... | where { Test-Connection -ComputerName $_ -Count 1 -Quiet }

To me it looks like the code had been line-wrapped to make it fit the width of the content area. I suspected the new "ask a question" wizard might have something to do with that, but I just tested the wizard and the resulting question was formatted just fine.

Is it just me, or are others observing this as well? Does anyone have an idea what might be causing this?

7
  • 1
    I have noticed it in a couple of VBA questions recently, where long lines are broken into two or three lines without having a _ at the end of each "part". I can't tell for sure if that was above normal though. Sep 4, 2018 at 18:30
  • 2
    No clue why this is happening...but dealing with this is straightforward - VTC as "unclear". Otherwise I'm not sure what exactly you're looking for in this.
    – Makoto
    Sep 4, 2018 at 18:36
  • I'm well aware of how to deal with it, although I usually VTC as "no mcve". I'm more interested in whether this is a general trend and what might be causing it. Sep 4, 2018 at 18:42
  • 2
    Are you thinking it might still be a bug that you just haven't figured out how to reproduce?
    – BSMP
    Sep 4, 2018 at 18:43
  • Could be, but I'm not sure. I just find it very peculiar that in all questions where I noticed this the wrapping seems to have happened in a way that an automatic formatting routine would do. Like inserting a line break between hyphen and parameter name as in the example. Sep 4, 2018 at 18:51
  • 4
    Maybe it's just a habit of people in your tags? I see plenty of questions in javascript pasting big ol' one-liners (usually a JSON dump) making the horizontal scrollbar thumb awfully small. Sep 4, 2018 at 20:15
  • @HereticMonkey I agree, probably caused by the tool (the console) itself. Personally, having copied code from Powershell window, I can see this happening. Some Powershell askers might just don't notice it when writing their question
    – Pac0
    Sep 6, 2018 at 10:07

1 Answer 1

4

If this is coming for PowerShell, it might be simply due to the person copying from the PowerShell window.

Line breaks will be added in copy-paste in this case, at least from my version, if the instruction line actually wraps on several console lines.

It can happen also with some editors which have "auto-wrap" enabled.

You can advise OP to copy their code from their text script file instead, and/or just edit the question if it is clear from the context that the line breaks were not the issue.

Personally, reading mostly C# and Web stuff, I haven't noticed any change on code line breaks inserted by Stack Overflow.

6
  • Maybe just coincidence then. It's not just PowerShell, though. I've noticed the same in the VBScript tag. Sep 6, 2018 at 10:37
  • ah, interesting! Maybe add those additional example to your question, if you can catch one.
    – Pac0
    Sep 6, 2018 at 12:43
  • 2
    "`copy its code" I'm all for using gender-neutral pronouns but the accepted way is to use the plural pronouns "they", "them", "their", etc. So that should be "copy their code". I guess maybe English isn't your first language so it might not sound strange to you but it sounds very weird to my ears! :P
    – Clonkex
    Sep 7, 2018 at 4:47
  • 1
    @Clonkex I really appreciate the feedback, indeed English is not my first language :)
    – Pac0
    Sep 7, 2018 at 14:03
  • @AnsgarWiechers Just saw during review a question withbroken python code : stackoverflow.com/questions/52246916/… (in the first for block, else part)
    – Pac0
    Sep 9, 2018 at 22:27
  • After seeing a couple more occurrences in the PowerShell tag it looks like the effect might indeed be caused by copy/pasting from the PowerShell console. Sep 15, 2018 at 23:34

You must log in to answer this question.

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