Friday, October 1, 2010

modern IDEs influencing coding style?


It would be nice if globals, locals, and members could be syntax colored differently. That would be better than g_ and m_ prefixes.

- John Carmack



I saw this from John Carmack last week and thought, what a great idea! It seems very natural and easy to do and makes a lot more sense than crazy prefix conventions. I've been mostly programming in Java, so the conventions are a little different, but I'd love it if we could get rid of using redundant "this" qualifiers to signal member variables, and the super ugly ALL_CAPS for constants... it just seems so outdated.

Eclipse actually provides this kind of highlighting already:



Notice that the member variable "greeting" is always in blue, while the non-member variables are never highlighted. Also, the public static constant "DEFAULT_GREETING" is blue and italicized.

Notice that if you rename DEFAULT_GREETING, it's still completely recognizable as a constant:



I think it's interesting that modern IDEs are able to give us so much more information about the structure of our programs. Stuff you used to have to explicitly call out via conventions like these. How long until we're ready to make the leap and change our code conventions to keep up with our tools?

The main argument against relying on tools to provide this kind of information is that not all tools have caught up. I'm not sure I completely buy this. Hopefully you're not actually remotely editing production code in vi or something. There are a lot of web apps for viewing commits and performing code reviews, and they're unlikely to be as fully featured as your favorite IDE. Still, the context is often limited enough to avoid confusion, and the majority of our time is spent in our IDEs anyway.

So, can we drop the ALL_CAPS already?

2 comments:

Kyri said...

DROP ALL CAPS? NEVER!

I'm all for dropping superfluous this prefixs like this.foo = bar; for accessing member variables though.

Jhon Davis said...

Well, the modern IDE's are really very efficient and help a lot to code. Just for an example, look at the Visual Studio IDE, the most strong and powerful interface allows you code just on the flow of wind. Other IDE's for open source coding (php etc.) like Dreamviewer and even Notepad++ is strong enough.

However, using conventions and coding notations is really desirable for readability, maintenance and further extensions to code.

- John Devis
Magento Themes