PDA

View Full Version : Syntax Highlighting


JMJ_coder
06-18-2008, 02:24 PM
Hello,

What is your take on syntax highlighting? I must admit, I find it a very useful feature - but not all editors support it.

sverreh
06-18-2008, 02:45 PM
I like it too. Helps a lot when searching for errors in scripts with VIM. (Of course, since I almost never produce faulty scripts, I don't need highlighting) :rolleyes:

drhowarddrfine
06-18-2008, 02:52 PM
It seems many editors, particularly on Windows machines, make your editor look like a circus. I ran my code through an editor once and counted seven different colors including hot pink. Too often, code words are highlighted because they can but it serves no purpose.

I can see where highlighting of certain significant keywords can be helpful, but I'm not entirely convinced of this either. I frequently find highlighting just grabbing my attention while scanning and distracting me.

In typography, highlighting is used just for that. To grab your attention so you don't miss something. Do you want to do that while reading through the logic of your code? I always tell myself I'm going to experiment with this but haven't yet. I might like highlighting when I'm searching for a keyword but not otherwise.

I think some like colored highlighting because it seems to make the page more attractive to look at. I also think this is only a temporary effect which quickly wears off and, again, only causes distraction and confusion.

RandomSF
06-18-2008, 02:58 PM
(Of course, since I almost never produce faulty scripts, I don't need highlighting) :rolleyes:

Right, but when I am sent to correct the mistakes of others it's still quite handy. :)

I also use Vim and just pick a color scheme that provides decent highlighting without driving me insane. I find that I use different color schemes on different computers probably because of differences in monitors and lighting.

deemon
06-18-2008, 05:10 PM
Do you want to do that while reading through the logic of your code?

It's exacly opposite for me - highlighting different parts of code - keywords, braces, strings, variable defs, etc - helps to navigate and read the code. It's easier to discard different parts of your code and only see that which is important.

Syntax highlighting has no downsides for me. Atleast in the editors I use (which consists of gvim / vim in xterm only).

sverreh
06-18-2008, 06:36 PM
In typography, highlighting is used just for that. To grab your attention so you don't miss something. Do you want to do that while reading through the logic of your code? I always tell myself I'm going to experiment with this but haven't yet. I might like highlighting when I'm searching for a keyword but not otherwise.

Well, it can be useful for other purposes. Just to give an example: If you forget the closing $-sign for a mathematical expression in a .tex file, all the rest of your document will be shown in wrong colours. Very easy to notice the mistake. I also like it when working with Perl or shell scripts, where operators, variables and constants are shown in distinct colours. Helps me, not just because it is "pretty". But it is all probably a matter of taste, and it does take some time to get used to it. I agree that it can be a bit distracting in the beginning. Give it a try, you may end up liking it. (And then you will be lost when you have to work on a system without a highlighting editor. :p

halber_mensch
06-18-2008, 10:26 PM
On a similar note, paren-highlighting is also a coder-friendly feature, especially when you've nested several levels of parens and brackets. It's one of the things I really enjoy about the language major modes in emacs. When your cursor is on a paren or you type in a paren, if it has a partner the cursor flashes on it briefly, or you get a status message indicating an unmatched paren. It saves a lot of counting =)

JMJ_coder
06-18-2008, 10:36 PM
Hello,

Some of the benefits of syntax highlighting (at least as in done in vim) are:

If you mistype a keyword or forget a quote or semicolon, the coloring is all out of whack - no need to wait until compile time to realize a mistake is made.

Brace matching allows you to easily if you have enough braces and to see logical deliminations of blocks of code.

I have heard that staring at large chunks of plain code for hours on end - it all looks the same (I haven't spent hours at a time in front of plain code to know this first hand).



^^^ The second item could be easily lived without, but as to the other two - those who do not use syntax highlighting, could you please expound on why plain code is superior to syntax highlighting or where syntax highlighting falls short of desired results.

JMJ_coder
06-18-2008, 10:38 PM
Hello,

Most vi clones (i.e., vim) have developed syntax highlighting as part of their editor. Is there anyway to incorporate syntax highlighting with (n)vi?

TerryP
06-18-2008, 10:42 PM
I suppose when it comes to text editing, decent editing keybindings/mappings (e.g. no need for a mouse) and syntax highlighting is probably about all I really ask for.


I think I agree with people in #vim, code should _not_ look like a Christmas tree !!!


I like syntax highlighting because I spend a lot of time in text editors, which is probably why I like nvi and vim. The first time I tried creating a color scheme for Vim that took over my syntax highlighting.. I found the colours to distracting and chucked it.

In Vim I use the 'astronaut' colo in a pseudo transparent terminal and find find it to have very good effects on syntax highlighting.


Some keywords are underlined and coloured, keywords and some types of things coloured, strings colored differently + diff colour for %stu \ff and coloured comments.

I loved astronaut so much for Perl and felt so at home with it for Python, that I created my own personal colour scheme based on it.


I like syntax highlighting when it _helps_ me. If you really know how your syntax highlighting works, you can use it to quickly scan bits of information and differentiate parts of code quickly.


One thing I do like is providing a highlight of some sort for {}. (), [], and when XML/SGML based stuff is around <tag></tag>.


I've found syntax highlighting very helpful for Perl, PHP, LaTeX, and XHTML in particular. Especially if I forget a freaking sigil or start a string with ' or " and end it with the opposite one by mistake :eek:

I can use the warning/error messages and the syntax highlighting to quickly locate the offending code. Now if only there was a way to make vim add missing ';'s on :w hehe.

drhowarddrfine
06-19-2008, 05:20 AM
Give it a try, you may end up liking it. (And then you will be lost when you have to work on a system without a highlighting editor. :p

I "gave it a try" years ago, for years, so I don't need to do that. In geany, I tried setting some simple highlighting but I'm not sure what works best. I kind of like bold function names in dark blue but when I'm not searching for function names, they get in the way. Some of the posts here mention certain highlighting functions which aren't syntax highlighting but error checking. And as far as staring at monochrome all day, it's my preferred method and with no X.

JMJ_coder
06-19-2008, 08:59 PM
Hello,

Some of the posts here mention certain highlighting functions which aren't syntax highlighting but error checking.

Could you expound on some alternatives then for said error checking?

drhowarddrfine
06-20-2008, 06:01 AM
Your thread is about syntax highlighting, not error highlighting.

Carpetsmoker
06-20-2008, 06:08 AM
I find syntax highlighting very useful, not only does it let you scan text much faster, it also lets easily detect simple errors (like a missing */).

I use Vim's default color scheme, it works well, although I do recommend enabled 256 colors, it offers just that extra little bit of extra contrast over the default 16 colors ... See:
http://vim.wikia.com/wiki/256_colors_in_vim

TerryP
06-21-2008, 07:46 PM
Your thread is about syntax highlighting, not error highlighting.

Syntax highlighting highlights elements of visible text based on a defined syntax.

If missing an ending " makes the rest of my file highlight as a string until I type the ending quote, I ain't got a problem that feature. I consider it just a part of selectively changing text colours (highlighting) based on syntax ;-)

ai-danno
06-22-2008, 06:31 AM
It's been mentioned twice that it helps with PERL... and I would completely agree with that... perhaps a junky color scheme might be distracting, but one that is contrasting enough but that also isn't offensive seems to be the most useful for me concerning PERL scripting.

corey_james
06-22-2008, 08:14 AM
I don't think there's anything that irritates me more than syntax highlighting.

I'm not 100% sure why i don't like it but i think i focus more on the colours than the actual code.

Drives me nuts logging into a *nix machine where i can't navigate around the fs or edit a file without getting a rainbow appearing in my terminal window hehe ;)

drhowarddrfine
06-22-2008, 03:24 PM
My point exactly, corey, but I wonder if it's a matter of personal preference or not really noticing the difference.