Like Tree8Likes

[code] coloring breaks [color]

This is a discussion on [code] coloring breaks [color] within the General Discussions forums, part of the Community Boards category; Originally Posted by quzah The version they have (had?) in place now with [code] does line numbering, and you can ...

  1. #31
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by quzah View Post
    The version they have (had?) in place now with [code] does line numbering, and you can even click-drag-copy-paste and it won't add the line numbers. It's pretty nice (except for having to shift+reload to get it to show up) except for the color choices.


    Quzah.
    I wasn't sure,I didn't get too much of a chance to play around with it before it was suspended.
    :insertrandomjoketobumpmypostcount:
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  2. #32
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,594
    I like the idea to mandate indentation as part of the rules. This is not something we should be babysitting; it is something those who want help have to learn and do right.
    AndrewHunter likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    This is not something we should be babysitting...
    Indeed which is why my personal policy is no indentation = no help. Everytime I try to go in and add indentation to a post that has none I end up making it worse than before.
    quzah likes this.

  4. #34
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If it's hard to read, it's not going to get read. It's not my job to make sure you give me something good to read. If you want it read, make it readable.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #35
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by VirtualAce View Post
    Indeed which is why my personal policy is no indentation = no help. Everytime I try to go in and add indentation to a post that has none I end up making it worse than before.
    That is usually because of the "white space disaster" phenomenon. Something that an auto formatter, if added, would alleviate and allow us to work on the code. Heck, sometimes having the OP just see their code formatted the right way might be enough to allow them to solve their own problems.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #36
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by AndrewHunter View Post
    That is usually because of the "white space disaster" phenomenon. Something that an auto formatter, if added, would alleviate and allow us to work on the code.
    I like syntax highlighting and it is a very concrete thing to do, but I think whitespace formatting is more problematic and expensive. Whitespace is mostly irrelevant to parsers/compilers, except in places where very strict rules have replaced braces with tabs (python), and C/C++ is not one of those.

    I have no problem with syntax highlighting my code but I do not want to see it auto formatted beyond that. People can and should do that for themselves and if not it is very easy to point out, easier even than simple syntax errors.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #37
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    970
    Okay, I've tweaked the color coding logic a little bit so that it automatically detects code blocks with any HTML in them--which should allow anyone to render their own color coding without any interaction from the color coding script.

    I've also tweaked the background color a little bit so that it's not quite as dark.

    Next steps:

    1) Make it automatically run when a post is submitted. (For now, it falls back to the old code tag box until a page refresh. Note that this impacts only the poster--anyone loading the page will see the highlighting, as will the poster once refreshing.) My first attempt at fixing this failed; I need to look at the sequence of a "Post Quick Reply" operation.)
    2) Adding an option to disable the highlighting for users who don't want it. Either a per-code-box button or a user setting.
    3) automatically pick up the right kind of brush from the forum URL (right now it's also C++, but it should be possible to properly color C# and C)

  8. #38
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,460
    2) Adding an option to disable the highlighting for users who don't want it. Either a per-code-box button or a user setting.
    Ah! Thank you.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #39
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by webmaster
    3) automatically pick up the right kind of brush from the forum URL (right now it's also C++, but it should be possible to properly color C# and C)
    I wonder if it is better to default to just line numbering, then highlight syntax according to language if specified, e.g.,
    [code=c++]#include <iostream>
    // ...[/code]
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #40
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    970
    @laserlight I expect the forum URL will choose the right brush almost all the time, without requiring manual intervention that many new posters won't know about (and that won't benefit older posts created before the new syntax). The failure mode of choosing say the C++ brush when highlighting C code won't be catastrophic. It might be an interesting idea to allow specific manual overrides, though I'm not sure I see many use cases for it (someone posting Java?)

  11. #41
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,460
    This is indeed a programmers forum, webmaster. Is it that important the code coloring mechanism works for the layman, or -- even stranger -- works for older posts? I think anyone in the process of learning a programming language (since I don't expect folks come here to learn about tupperware) will pick up on manual code highlighting just fine. It's not really that big of a brain cell investment. Especially if you make a point of adding some help text on the new post screen. Make them earn their programmer stripes; know what I mean?... No?

    My personal experience always told me that there's a divide between easier things and things that work. I'm just not sure you can effectively reconcile code coloring for the newb with code coloring that just works. How do you plan to handle the Tech board, or Windows Programming board, or Linux Programming board, or Game Programming board, et cetera? I'd rather have code coloring that works.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #42
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure how you enable the new color syntax highlighting, but it doesn't know how to handle multi-line quotes for broken strings. See this: Need help with errors

    The bottom prinf statements should actually look like this:
    Code:
    printf( "hello "%d", foo );
    printf( "world "%d", bar );
    ... and so on

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #43
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by quzah
    The bottom prinf statements should actually look like this:
    I do not think so. The second line printf should not be highlighted as a string literal because it is not part of a string literal since there is no \ line continuation. Whether the broken string literal on the first line should be highlighted... I am not so sure if it matters. Highlighting it makes sense because it is at least the start of a string literal, yet not highlighting it might make the mistake more obvious (or perhaps not).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #44
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well even if we go by not splitting lines, you still would end up with:

    printf("Number of 50 cents "%d", fifty);

    Or they should change the string color so it is not as close to black as it is, so that it is clearly obvious that your strings are broken.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #45
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    970
    Quote Originally Posted by Mario F. View Post
    This is indeed a programmers forum, webmaster. Is it that important the code coloring mechanism works for the layman, or -- even stranger -- works for older posts?
    There are a over one million posts that have already been made--people find them via searching the forums, via Google and via links to old threads in new threads. If something can improve a large majority of these pages, it's worth doing.

    Quote Originally Posted by Mario F. View Post
    My personal experience always told me that there's a divide between easier things and things that work. I'm just not sure you can effectively reconcile code coloring for the newb with code coloring that just works. How do you plan to handle the Tech board, or Windows Programming board, or Linux Programming board, or Game Programming board, et cetera? I'd rather have code coloring that works.
    In my inspection of about 80 posts on those forums, I found no egregious errors, and only a single example where the syntax highlighting was a bit amiss (some C# code that didn't have C# keywords colored). I also found one XML code example that looked fine, and one compiler output that also looked fine.

    I did notice a tendency for the highlighting to fade out preprocessor directives, even though folks seem to disproportionately quote them (for example to point out old header files being used). This may be an argument for adding more contrast for this kind of thing. (There's a bit of an asymmetry between "broken code" color choice and "working code" color choice; in working code, you probably care much less about what's being included than in broken code.)

    Quote Originally Posted by laserlight
    I do not think so. The second line printf should not be highlighted as a string literal because it is not part of a string literal since there is no \ line continuation. Whether the broken string literal on the first line should be highlighted... I am not so sure if it matters. Highlighting it makes sense because it is at least the start of a string literal, yet not highlighting it might make the mistake more obvious (or perhaps not).
    I agree, it seems like a tossup. Highlighting is probably more correct but it's not obviously much better, and may have some downsides.

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switching from MinGW to Pelles C, code breaks
    By Hear.Me.ROAR in forum C Programming
    Replies: 4
    Last Post: 08-11-2011, 11:21 AM
  2. my code breaks unique pointer rule?
    By George2 in forum C++ Programming
    Replies: 19
    Last Post: 02-17-2008, 02:26 AM
  3. Code-Coloring
    By Vber in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-08-2003, 10:29 PM
  4. Paste code into word keeping color
    By GaGi in forum C++ Programming
    Replies: 1
    Last Post: 02-07-2002, 07:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21