Thread: [site suggestion] syntax highlighting hack/mod for BB

  1. #1
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104

    [site suggestion] syntax highlighting hack/mod for BB

    I think it will be better if the site has syntax highlighting mods for C,C++,C#..
    that are available for vBulletin.. it makes the code posted by the users more readable..
    currently this site has only PHP highlighting though nobody uses that..
    I know it can be used for C. but it will be better if we have different for each code type

    I found one here
    Advanced Syntax Highlighting - BBCode [highlight]


    And optionally codefolds if available, if it is not too much of effort

    comment on this feature

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Most of the code posted here is pretty unreadable with or without syntax highlighting. In fact, a lot of the code posted here won't even compile. And you know what syntax highlighting does to broken code, right?

    All it takes is one missing */ somewhere and suddenly all your code is highlighted in "comment color."

    I'm not sure it would be helpful.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I think it would be helpful if it were optional. So, for long, complicated code, one could use syntax highlighting; but for something like this, you could opt for not using it:
    Code:
    // your syntax error is here:
    if(!strcmp(name, "Joe"))) {
    There have been lots of discussions about this, actually. Here's a recent one. http://cboard.cprogramming.com/showthread.php?t=88629

    As the author of codeform, I of course like syntax highlighting.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If it's coloured and badly formatted, then I guess I'll start referring to it as "Jackson Pollock" style
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by brewbuck View Post
    Most of the code posted here is pretty unreadable with or without syntax highlighting. In fact, a lot of the code posted here won't even compile. And you know what syntax highlighting does to broken code, right?

    All it takes is one missing */ somewhere and suddenly all your code is highlighted in "comment color."

    I'm not sure it would be helpful.
    I dont think that users who post codes leave their message without seeing how their message is..
    not atleast when there is syntax highlighting.. it is more likely to happen with normal monospaced letters than with colored letters.

    Quote Originally Posted by dwks View Post
    I think it would be helpful if it were optional. So, for long, complicated code, one could use syntax highlighting; but for something like this, you could opt for not using it:
    Code:
    // your syntax error is here:
    if(!strcmp(name, "Joe"))) {
    There have been lots of discussions about this, actually. Here's a recent one. http://cboard.cprogramming.com/showthread.php?t=88629

    As the author of codeform, I of course like syntax highlighting.
    ya.. I know that.. I did use the search button provided by the BB. and endedup with lot many threads. finally I saw yours and some discussion on 2 different highlighters. I visited the home page of codeform and downloaded the source and made it.. and I found that I need a clipboard copy commandline.. those sources shipped along with the source are for windows.. I am on linux.. I again googled for command line util, and found that xclipboard is avilable. and then again.. I have to make it save to file go to command get the output into file or clipboard.. or make a command in the editor I am using..
    even after all this, there is a lot of overhead thats going into database&bandwidth with that or any other userside developed round about way to color their code for better understand of the other users..
    so I was thinking of asking the admins to just put up that mod. interested and known users use it and rest wont..
    there isnt much that this Board will be loosing.. its just few more CPU cycles of the server..
    so it sounds affordable and better way than other highlightings
    Also there is high lighting for PHP.. I dont know why its still there but its there

    Quote Originally Posted by Salem View Post
    If it's coloured and badly formatted, then I guess I'll start referring to it as "Jackson Pollock" style
    I totally agree with that.. well formatted code needs no highlighting..
    but highlighting saves a lot of effort.. like 'printf' might get 'pritnf' and we dont notice it and sometimes double quotes ended with single quotes etc..
    The bottom line is 'something is better than nothing', may be pollock's art, at least we have an art

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you figure out a way to manipulate the clipboard under Linux like the Windows code does, let me know -- I'd be very interested in it myself, as I use Linux a lot more than Windows.

    Here's what I think. Really long code is immensely easier to read if it's syntax highlighted. However, in certain situations it's best if the code in not syntax highlighted, as in the example I posted. So if CBoard does support syntax highlighting, it should at least not make it mandatory.

    Of course, if you have some code that you really want highlighted you can use an external syntax highlighter to do the job for you. This has several disadvantages, however. It's difficult to edit the code once you've syntax-highlighted it -- you have to keep the original code, modify that, and re-highlight it. (Unless the syntax highlighter supports de-highlighting, but that's another story.) As you mentioned, it takes up a lot of space on the server to store all of those tags. And finally, everyone likely has their own favorite highlighting style, so you'll probably highlight your code your way. This could lead to confusion if the styles vary wildly, and readers might be annoyed if the style varies sufficiently from what they're used to. (Ever seen vim's syntax highlighting? . . .)

    These two points are what make me believe that syntax highlighting should be supported by CBoard, but it should not be forced upon you. The best way to solve this, in my opinion, is to allow the web browser to use syntax highlighting (like DaniWeb does). You can toggle syntax highlighting if the code is really long, or turn it off if you choose. If it was done properly, you should even be able to choose which style the code is highlighted in.

    But of course, until we convince some administrators, we're grasping at moonshine.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by brewbuck View Post
    I'm not sure it would be helpful.
    Of course it would be helpful!
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Sang-drax View Post
    Of course it would be helpful!
    Not if it was applied to everything. It would be a mess. I'd say half the posts here are by people who's code does not compile. When you apply syntax highlighting to syntactically broken code you end up with highlight soup.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    When you apply syntax highlighting to syntactically broken code you end up with highlight soup.
    The good part is that we can then ask them to look at the syntax highlighting and come back to us after they have fixed it, heheh.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by dwks View Post
    If you figure out a way to manipulate the clipboard under Linux like the Windows code does, let me know -- I'd be very interested in it myself, as I use Linux a lot more than Windows.

    Here's what I think. Really long code is immensely easier to read if it's syntax highlighted. However, in certain situations it's best if the code in not syntax highlighted, as in the example I posted. So if CBoard does support syntax highlighting, it should at least not make it mandatory.

    Of course, if you have some code that you really want highlighted you can use an external syntax highlighter to do the job for you. This has several disadvantages, however. It's difficult to edit the code once you've syntax-highlighted it -- you have to keep the original code, modify that, and re-highlight it. (Unless the syntax highlighter supports de-highlighting, but that's another story.) As you mentioned, it takes up a lot of space on the server to store all of those tags. And finally, everyone likely has their own favorite highlighting style, so you'll probably highlight your code your way. This could lead to confusion if the styles vary wildly, and readers might be annoyed if the style varies sufficiently from what they're used to. (Ever seen vim's syntax highlighting? . . .)

    These two points are what make me believe that syntax highlighting should be supported by CBoard, but it should not be forced upon you. The best way to solve this, in my opinion, is to allow the web browser to use syntax highlighting (like DaniWeb does). You can toggle syntax highlighting if the code is really long, or turn it off if you choose. If it was done properly, you should even be able to choose which style the code is highlighted in.

    But of course, until we convince some administrators, we're grasping at moonshine.
    I googled a lot for the clipboard program code on Linux. apparently there are 3 types of clipboards on linux provided by different daemons (I am not sure though, somebody on a forum said). to be frank those all asked me to go through that X Windows Communication standards.. I dont know abc of X, I tried a bit though.. but gave up for now.. coz I got my assignments to submit first then I will come back to my linux
    I dont know bout daniweb.. but it sounds cool to let user choose the highlighting of the code..
    if this board could put it up that will be the best to do.. if its not too much of work to get it..

    Quote Originally Posted by brewbuck View Post
    Not if it was applied to everything. It would be a mess. I'd say half the posts here are by people who's code does not compile. When you apply syntax highlighting to syntactically broken code you end up with highlight soup.
    ya.. it would be a mess.. but that clearly shows where the prob is.. if a person posts a code that is syntactically wrong how could it be working?
    so the next post from other users will be saying you have syntax prob here..
    if the original thread starter takes care of it all then fine.. rest all will go smoothly.
    I dont find anything we are missing here..
    and if it is possible to put up something like the daniweb does then.. there wont be any prob at all..

    what do you say guys?
    C's Motto: who cares what it means? I just compile it!!

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > ya.. it would be a mess.. but that clearly shows where the prob is.. if a person posts a code
    > that is syntactically wrong how could it be working?

    If a person posts code that is syntactically correct, how could it not be working?
    I'm honestly thinking that you're overstating its effectiveness, but that's my opinion. Syntax highlighting has never helped me fix a syntactical issue, at least not like, "Wow! Am I ever glad that Visual Studio uses blue here!" And one could argue that syntactical problems are not the most important ones. I don't know why this continues to be an issue here.
    Last edited by whiteflags; 11-10-2007 at 02:56 AM.

  12. #12
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by citizen View Post
    If a person posts code that is syntactically correct, how could it not be working?
    I'm honestly thinking that you're overstating its effectiveness, but that's my opinion.
    I never said that syntactically correct code should work the way you wanted it to..
    my intention is not to say that syntax highlighters fix 90% of the probs posted here..
    but they will help users a little in going through the posted code
    and if this little comes with not much effort.. then its a good deal..

    Quote Originally Posted by citizen View Post
    Syntax highlighting has never helped me fix a syntactical issue, at least not like, "Wow! Am I ever glad that Visual Studio uses blue here!" And one could argue that syntactical problems are not the most important ones.
    ok, it never fixed your probs..might because you take care of that even before compiling..
    but you never put it off coz it never helped you.. lol.. tell me if you really did
    Quote Originally Posted by citizen View Post
    I don't know why this continues to be an issue here.
    the issue is not about the posted code is syntactically correct or not..
    its about how readable it is..
    I say that with highlighting it will be little better than having nothing..
    C's Motto: who cares what it means? I just compile it!!

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No, because most of the problems are logical problems, nothing to do with syntax. When it is, it's usually missing ';' or an odd number of brackets, I don't see how colour can solve either.

    Consider the following,
    Code:
    if(foo = malloc(11 * sizeof(bar))) != NULL)
    The colours didn't help pick up the missing bracket. Just as colour doesn't make code any easier to read, not to mention it could hinder colour blind users. I would say it's more useless or bad than is worth the effort

    >I say that with highlighting it will be little better than having nothing..
    If you love colour so much, I suggest codeform, I don't know if dwks still has an online version running, you could always ask him, or you can use the [php ][/php] tags which already exist, so you could say that there is optional syntax highlighting

    PHP Code:
    if((foo malloc(11 sizeof(bar))) != NULL
    Last edited by zacs7; 11-10-2007 at 05:54 AM.

  14. #14
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by zacs7 View Post
    No, because most of the problems are logical problems, nothing to do with syntax. When it is, it's usually missing ';' or an odd number of brackets, I don't see how colour can solve either.

    Consider the following,
    Code:
    if(foo = malloc(11 * sizeof(bar))) != NULL)
    The colours didn't help pick up the missing bracket. Just as colour doesn't make code any easier to read, not to mention it could hinder colour blind users.
    normal
    Code:
    if(foo = malloc(11 * sizeof(bar))) != NULL)
    userside colored.. (most IDEs/editors do the same)
    Code:
    if(foo = malloc(11 * sizeof(bar))) != NULL)
    site Inbuilt coloring
    PHP Code:
    if(foo malloc(11 sizeof(bar))) != NULL
    keeping lame ppl apart. all I am asking is to give us programming editor looks and not windows notepad
    do ppl who think that code coloring is not at all needed OR have probs looking their code colors etc.. put off the syntax highlighting available on their editors/IDEs?

    anyway.. is there any editor that colors brackets depending on their matchings? (something like k-colored graph, every adjacent braces have diff color & matching brace has the same color)
    I never found one.. except IDE's that parse the code runtime and underline syntax probs.. if we could get that it will be too good

    lol.. if nothing turns out thats what I want to do..
    and these 'code' tags are also making the actual page awkward.. because they are not able to putup scroll bars in the code.. and forcing the whole forum page to put it :P
    Last edited by gibsosmat; 11-10-2007 at 06:16 AM.
    C's Motto: who cares what it means? I just compile it!!

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't know if dwks still has an online version running
    Yup, it's still there, though it's been moved. dwks.theprogrammingsite.com/myprogs/cfonline.htm

    If you think that syntax highlighting doesn't affect how you read source code, try turning off your favorite editor's syntax highlighting. It's almost unconscious, but it really does make a huge difference.

    Take some moderately complicated code from codeform.
    Code:
    /*! Binary searches through the existing variables in \a rt for the position
        that the variable \a p should be in, putting the result in \a pos.
        \param vars The existing variables to search through.
        \param p The text representing the new variable to search for.
        \param pos The variable to store the position found in. Set to (size_t)-1
            if no match was found.
        \return 1 if an exact match (to the shortest length) was found, 0
            otherwise.
    */
    int find_var_pos(struct rulevars_t *vars, const char *p, size_t *pos) {
        size_t mid = (size_t)-1, first = 0, last = vars->number-1;
        int v = 0;
    
        *pos = (size_t)-1;
    
        if(!vars->number) return 0;
    
        while(first <= last && last != (size_t)-1) {
            mid = (first + last) / 2;
    
            v = strcmp(p, vars->data[mid]->from);
    
            if(first == last && v) break;
    
            if(v < 0) last = mid-1;
            else if(v > 0) first = mid+1;
            else {
                *pos = mid;
                first = mid+1;
            }
        }
    
        if(*pos != (size_t)-1) return 1;
    
        if(v < 0) *pos = mid;
        else *pos = mid+1;
    
        return 0;
    }
    Now I've highlighted it:
    Code:
    /*! Binary searches through the existing variables in \a rt for the position
        that the variable \a p should be in, putting the result in \a pos.
        \param vars The existing variables to search through.
        \param p The text representing the new variable to search for.
        \param pos The variable to store the position found in. Set to (size_t)-1
            if no match was found.
        \return 1 if an exact match (to the shortest length) was found, 0
            otherwise.
    */
    int find_var_pos(struct rulevars_t *vars, const char *p, size_t *pos) {
        size_t mid = (size_t)-1, first = 0, last = vars->number-1;
        int v = 0;
    
        *pos = (size_t)-1;
    
        if(!vars->number) return 0;
    
        while(first <= last && last != (size_t)-1) {
            mid = (first + last) / 2;
    
            v = strcmp(p, vars->data[mid]->from);
    
            if(first == last && v) break;
    
            if(v < 0) last = mid-1;
            else if(v > 0) first = mid+1;
            else {
                *pos = mid;
                first = mid+1;
            }
        }
    
        if(*pos != (size_t)-1) return 1;
    
        if(v < 0) *pos = mid;
        else *pos = mid+1;
    
        return 0;
    }
    Come on. There is a difference.

    And colour-blind people? Yes, it's true that reading coloured code could be difficult to read. I know someone who is colour-blind, and my printer is so bad, that I'm aware of the issues. So use syntax highlighting, but with bold, italic, and underlined text! It would still be much better than ordinary text.

    If syntax-highlighting was done client-side, then a colour-blind user could choose to change all syntax-highlighted code to this style, or disable it completely if they wanted to.

    [edit]
    anyway.. is there any editor that colors brackets depending on their matchings? (something like k-colored graph, every adjacent braces have diff color & matching brace has the same color)
    I never found one.. except IDE's that parse the code runtime and underline syntax probs.. if we could get that it will be too good
    I actually modified codeform once so that it would do this. Search around the board if you're interested. SlyMaelstrom was the one who requested it. [/edit]

    [edit=2] Ah, that thread was lost when CBoard crashed. I saved it, though. (Along with a few other threads.) Here it is: http://dwks.theprogrammingsite.com/m...orm_632617.htm
    [/edit]
    Last edited by dwks; 11-10-2007 at 02:50 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM