Coding to suit the editor

Something I’ve noticed is how web developers behave when color coding in their favorite editor doesn’t work,

Take, for example, if you have a single apostrophe (‘) within a comment field, and your development environment, for some reason, insists on interpreting it as the start of something which isn’t closed.

What I’ve seen, with myself as well as others, when the editor fails on color-coding the code, people start to adapt their code to suit their editor, hence getting the nice colors they want. The editors are starting to dictate our coding style, and if they do something wrong, we rewrite code to fall into that pattern. It’s a bit scary, isn’t it? πŸ™‚

What do you do when the result isn’t as expected?

17 Comments

  • I take a moment to myself and post random comments on your blog … and then I get back to work πŸ˜‰

  • I check for errors, since that usually means I forgot to close or escape an apostrophe or quote πŸ™‚

    Also, most editors allow you to change your colour coding to suit your needs πŸ™‚

  • I've ditched editors because it was impossible for me to get my syntax higlighting working the way I wanted it. πŸ˜‰

  • It seems a bit related to my request in precedent post .. isn't it? πŸ˜€

    In this case, you opened twice something … closing once.

    var p = "start something "continue and close";

    this is a parser error, that usually means you committed a mistake πŸ˜›

    Anyway, scintilla, notepad++, sometimes komodo 3.5, Eclipse and Zend Studio, has similar problems with some strange not closed code.

    Next time it will happen, I know where to post the case.

    Kind Regards πŸ™‚

  • Robert Nyman says:

    Jeroen,

    Way to go! πŸ™‚

    Ok, let me explain this a little bit more:

    If you you have code in, for instance, HTML and have a comment:

    <code><!– This code can't fail –></code>

    Then you have editors which will fail to color-code anything following that single apostrophe since it thinks something isn't closed (which is, per se, correct), but since it's in a comment it should be overlooked.

  • I've never run into the problem, actually. Must have been lucky.

    I wrote my two recent (JS-)projects in Smultron without syntax-coloring, so I guess it doesn't matter in the end. I usually do quick fixes in nano, the lightweight CLI editor.

    On the other hand, I tend to use nano and Smultron quite a lot because Eclipse get my Powerbook G4 on it's knees … ^^

  • I've never run into the problem, actually. Must have been lucky.

    I wrote my two recent (JS-)projects in Smultron without syntax-coloring, so I guess it doesn't matter in the end. I usually do quick fixes in nano, the lightweight CLI editor.

    On the other hand, I tend to use nano and Smultron quite a lot because Eclipse get my Powerbook G4 on it's knees …

  • Binny V A says:

    Eclipse has this issue in my system. If a lot of lines are affected, I will change the code so that the bug wont bother me. If only that line is affected, I wouldn't care much.

  • Andreas says:

    I know exactly what you mean, but most of the time I simply ignore it.

    I structure all my code modular so I'm never looking at that much code at the same time (normally like 20 lines of HTML/CSS/JS per module) and it's bearable because it's short.

    Textmate is pretty good though, don't think I've run in to these kinds of problems with it but in Coda you can't open the html-element in one file (header.php for example) and close it in another (footer.php or whatever) because then Coda will not highlight the code properly. I suppose it's to alert the user he's coding invalid code but it's very common to divide HTML in several files so I'm not sure it's that good.

    That said, I'm no Textmate or Coda-expert and I'm sure there are ways to configure the syntax highlighting to your liking. Especially in Textmate which seems endless in configuration-possibilities.

  • Rowan Lewis says:

    I always end up modifying my editors files (gedit / gtksourceview-2) to do what I want, for some reason they default to one line strings, so when you have a string more than one line long you get this issue.

    I also wrote a syntax highlighter tool that overcomes these issues by allowing syntax rules to be nested. Won't go into that, but it works πŸ˜‰

  • Robert Nyman says:

    Thanks for sharing! Pesonally, I use TextMate, and is very happy with it. here's just the occasional color coding problems and some times with encodings, but otherwise it's a great editor.

  • Stephen Hill says:

    Notepad doesn't have syntax highlighting?

  • Maaike says:

    I never run into this problem. Perhaps because I'm using Dreamweaver?! πŸ™‚

  • Johan says:

    Been using EditPlus for ages, and it doesn't run into any syntax highlighting problems that I've seen. Your example doesn't cause any problems either. πŸ™‚

  • Robert Nyman says:

    Stephen,

    Only Notepad++.

    Maaike,

    Yeah, maybe. πŸ™‚

    Johan,

    Good, I'm glad for you! πŸ™‚

  • Jeremy Dill says:

    Hey Robert, make sure you are editing in the write language for your purposes. I have seen this problem too, and to resolve, I had to simply switch the language associated with my filetype to HTML. You can do this in the select box at the bottom of TextMate.

    – Jeremy

  • Robert Nyman says:

    Jeremy,

    Thanks for the tip, although I'm fairly sure I had the correct language. Can't guarantee it, though, so I'll make sure to double-check the next time it occurs. πŸ™‚

Leave a Reply to Rowan Lewis Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.