locked
Why is the facility to post code so bad? RRS feed

  • Question

  • An open letter...

    [This is a re-post, with a couple of ammendments, of a thread I posted in the General Office Development forum].

    It is frequently necessary, on this set of forums, to write source code to communicate an issue or solution. When using normal text (the type of this paragraph) you have the problem of long spaces after a carriage return; lack of color as you would see in Visual Studio; and terrible indenting.

    Presumably the 'Insert Code Block' feature was designed to overcome these issues. However, there are a number of persistent issues with inserting code blocks. Everyone who uses these forums regularly will know them, but to summarize:

    • Though an attempt is made at coloring text as with an IDE, the algorithm is terrible. It doesn't seem to be language specific; whether I write C#, Visual Basic or C++, regular code ends up comment-green, comments are often string-red, purple is sometimes added for no identifiable reason (see here).
    • Once code blocks have been inserted, they are not easily editable. I usually resort to copying it to the clipboard, deleting it, inserting a new code block, and then pasting, just to add a single line. If you want to insert normal text after the code block, and did not think to add a suffixing carriage return (or other text) before you went to insert the code block, you have to delete the code block and re-create it, because you can't place the caret below a code block that lies at the end of the text editor.
    • Double carriage returns are sometimes lost, particularly when copying and pasting from Visual Studio (see here, two thirds of the way down). This particularly makes it difficult to read long segments. When trying to add them back manually, I found it would only allow adding a double-carriage return.
    • Indentation is not allowable or else workable. When typing the code block, the tab button/character cannot be used. However you can paste in text where the tab button/character has been used.
    • The font used for code blocks has characters of different widths. This is probably the least consequential point on this list, but I think it would benefit from being as Visual Studio; it makes it easier to visually compare commands and especially strings. There is no option to change to a monospaced font when in the code block editor, however you can paste in a monospaced font.

    I have also experienced the following two issues. However, despite looking, I have not been able to find any examples, which makes me think they may have already been resolved:

    • Code often extends off the right side of the post, occasionally off the side of the screen. Possibly this differs by browser, but I have experienced it on IE and Firefox. I have had to copy and paste the text to a text editor to be able to read it.
    • I think particularly on Firefox, the last line of a code block is completely hidden if there's a horizontal scroll bar. Again, to view it it's necessary to copy it from the web page and paste it into a text editor.

    Since explaining with code is such an important, and often used, tool on these forums, I think the above is worth being properly addressed. I feel that Microsoft, world leading software company, ought to do better.

    Joe Fox


    • Edited by JosephFox Monday, August 6, 2012 10:39 AM Ammended thread title
    Monday, August 6, 2012 10:26 AM

All replies

  • The code for the "Insert Code Block" feature is a third party tool, and Microsoft seems to have little control over it. I'm convinced the colorization has changed over time. The colorization definitely has flaws (bugs), and several people have complained about it. I have seen examples of code running off the right side of the screen, but I think it happens when people paste code in the editor without using "Insert Code Block". When you use "Insert Code Block", long lines result in a scroll bar to avoid word wrapping. Some people do not like this. Occasionlly, the scroll bar will obscure the last line of code (even if there is only one line). However, this is a flaw in the forum code that displays the reply. If you wait, the same reply will later show all lines of the code. The behavior comes and goes, and not everyone sees the problem. My theory is that sometimes I get bad code from a server.

    My solution has been to not use the "Insert Code Block" feature, but to use the "Insert HTML" button. I use scripts to convert all of my code into HTML, complete with colorization, and paste it in a reply with "Insert HTML". If I edit the code, I do it in the HTML editor. This way I get a fixed-width font (important to me), all spacing and indenting is maintained, and I get the colorization I want. It's up to me to make sure long lines do not wrap. However, this is not a viable option for anyone else.


    Richard Mueller - MVP Directory Services

    Tuesday, August 14, 2012 2:27 AM
  • Thanks for your thoughts, Richard. Good to know I'm not alone in all this!

    A demonstration that, you're right, the scroll bar issue is still present: This thread just got posted in my hideout, the Word for Developers forum. Using IE8 I can't see the bottom line of the Code Block at all. Using Firefox (latest version) I can't see the bottom line, or half of the second-to-bottom line.

    Edit: Judging by the font, the code in the above thread looks like it was copy and pasted from Visual Studio. Now I think about it, this may be an important factor. I remember it happening to my posts when I did that.
    • Edited by JosephFox Wednesday, August 15, 2012 2:20 PM
    Wednesday, August 15, 2012 1:51 PM
  • Yes, the code in that question is really bad. I also do not see the last line, and pasting the code in notepad is a mess.

    I have a sandbox thread with code pasted using various methods, so I can check how it gets rendered (since it changes over time). In my sandbox thread, code with long lines pasted with "Insert Code Block" (so there is a scroll bar) now shows the last line for me, and yet the thread you linked does not. This is the first time I have seen this, where the last line shows in one thread but not another. My sandbox thread is TechNet, your example is MSDN. Since nothing else seems different, the code that renders replies must be different (for me) on the two platforms.


    Richard Mueller - MVP Directory Services

    Wednesday, August 15, 2012 3:08 PM
  • This is a single line of code pasted using the "Insert Code Block" feature (with no language specified):

    dsquery * -Filter "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=65536))" -attr distinguishedName sAMAccountName givenName sn displayName

    This line is long enough that a scroll bar is necessary to prevent word wrapping. Based on my recent experience with my sandbox thread, this line should be visible (at the present time), at least for me (perhaps not for others).


    Richard Mueller - MVP Directory Services

    Wednesday, August 15, 2012 3:18 PM
  • Yes. I too can see the line you added fine. However, the font is different to how it sometimes is when you paste from Visual Studio.

    I don't have a clue. The background is grey, for some reason, on the thread I linked to above.

    I definitely remember having to add extra carriage returns because the bottom line was covered, when copying and pasting C++ from Visual Studio.
    • Edited by JosephFox Wednesday, August 15, 2012 4:47 PM Added second and third paragraph
    Wednesday, August 15, 2012 4:33 PM
  • And I don't see the line of code at all, only the scrollbar...

    Cindy Meister, VSTO/Word MVP

    Tuesday, August 21, 2012 3:20 PM
  • Cindy, I see the line of code (at this moment), but your experience confirms what I remember from before. Some people see the last line, some do not, and what you see changes over time. That's why I think the explanation is that sometimes we get bad forum code from somewhere. Depending on where you are, you probably get your forum code from a different source. Some server somewhere has bad code (and has for months). If my theory is correct, it could be very difficult to troubleshoot.


    Richard Mueller - MVP Directory Services

    Tuesday, August 21, 2012 4:36 PM