Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 8 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Coding Guidelines in Modern IDE

At 12:06 PM on Jun 9, 2006, Alexandra Rusina wrote:

Yes, it’s true: this post is a reply to the Java style guideline for more efficient coding in modern environment tip recently posted at Javalobby. It was really amazing to read that someone follows coding guidelines to help a “modern” IDE with… completion! At JetBrains, developers believe that it should be exactly the other way round. It’s IDE that must help YOU to follow whatever you like for whatever reason you need.

As for completion, I have already posted a couple of tips about basic and smart completion features that can accelerate you development without forcing you to use naming conventions. But of course, it is useful to be able to quickly distinguish local variables from fields, classes from abstract classes and interfaces, static methods from non-static ones, and so on. In your own code, you can use naming convention for that. But what if it’s someone else’s code?

One more problem with naming conventions is constant changes in the code (if you convert a local variable to a field, will you rename it?). And of course, developers often simply forget about all these conventions and cannot remember whether it is necessary to use upper or lower case first letter for a constant.

With IntelliJ IDEA, the solution for all these problems is code highlighting. If you still think that code highlighting only makes keywords bold, just look at IntelliJ IDEA highlighting settings (Settings | Colors and Fonts | Java).



Here you can define the color schema for:
  • Class
  • Abstract Class
  • Interface
  • Local Variable
  • Parameter
  • Instance field
  • Static field
  • Method call
  • Static Method call
  • And more

So, you can easily understand the code of your team mates even if no naming convention is used within the team. All you need is to adjust your color schema!

In fact, syntax highlighting can be an even more powerful tool for code analysis than naming convention (if you use a really modern IDE, of course). For example, in IntelliJ IDEA you can highlight unused symbols, so you can easily find the potential dead code. One more useful trick is to highlight reassigned parameters to see whether parameters change their values within the method body (that is often considered as “bad coding style”). Also you can highlight reassigned local variables.

Well, suppose you still think that naming convention is a must for your team. The only problem is that team members always forget about this prefixes, postfixes, and underscores. And while you consider violation of the naming convention a serious coding error, the compiler doesn’t. So everybody keeps violating them without a notice.

A good IDE should not force you to use naming convention, but should help you with following the convention if you choose one. In IntelliJ IDEA, there is a set of code inspections that allows you to define naming patterns and then check whether the code violates them. You can configure naming convention settings in the Settings | Errors dialog.



If you set the constant naming conventions as shown on the screenshot above, when incorrectly named constants will be highlighted right in the editor.



The yellow light bulb shows that IntelliJ IDEA can help you with solving the problem. Just press Alt + Enter, and select to rename the symbol. All the usages of this symbol in the code will be also renamed. This way you can quickly make the code to follow the necessary convention.

IntelliJ IDEA inspections can help your not only with naming conventions, but also with other coding guidelines (comments, annotations, parenthesis, and more) and static code analysis. But this can be a subject of a separate topic.

Got interested? Find more tips and tricks at IntelliJ IDEA blog.
1 . At 10:47 AM on Jun 11, 2006, Jean-Marie Dautelle DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

> ... It was really amazing
> to read that someone follows coding guidelines to
> help a “modern” IDE with… completion!

You misunderstand the previous Javalobby post. The coding convention proposed (inherited from c/c++) is not intended to help with "modern" IDEs; it just happens to work particularly well with auto-completion (side effect).
I will not discuss the advantages/disadvantages of the proposed guideline as it has been extensively debated already.
Jean-Marie Dautelle - Marlboro, MA
-- Javolution: Everything should be made as simple as possible... -- JScience: But not simpler!
2 . At 12:35 PM on Jun 11, 2006, Stephen Colebourne DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

This is a marketing piece, pure and simple.

I would request the moderators to remove this post.
Joda-Time (replacement Date and Time) -- Apache Commons (Useful utilities)
3 . At 4:38 AM on Jun 12, 2006, James wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

yes it's maketing but isn't-it nice?
4 . At 5:57 PM on Jun 12, 2006, Heath Borders wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

Eclipse has most of these options as well (Netbeans probably does, too). However, Eclipse's editor does a horrible job of parsing code that is not syntactically correct, which makes the IDE code-style worthless. To make matters worse, even when you correct the syntax, the code-style errors persist. I hope IDEA/Netbeans handle this better.
5 . At 4:07 AM on Jun 13, 2006, Jeroen Wenting DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

> > ... It was really amazing
> > to read that someone follows coding guidelines to
> > help a “modern” IDE with… completion!
>
> You misunderstand the previous Javalobby post. The
> coding convention proposed (inherited from c/c++) is
> not intended to help with "modern" IDEs; it just
> happens to work particularly well with
> auto-completion (side effect).

Maybe, but a disturbing number of things proposed as "standards" and even language changes have no other reason than to make code easier to read for tools.
That's the sole reason annotations were introduced for example, to make code generators easier to write.

Styleguides and language changes should benefit the programmer working in that language, not be designed for the tool vendor writing code generators or editors.
They should rather work to reduce the burden of the programmer, rather than have the programmer do more work so the tool is easier to write.
6 . At 9:37 AM on Jun 14, 2006, M!k3 wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

IDEA does handle it MUCH better.
7 . At 6:29 PM on Jun 15, 2006, Ray Cromwell DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

If so, I would request moderators remove all the glowing Eclipse marketing pieces. The fact that something can be had for free doesn't mean a message isn't "marketing" something. If someone spams my mailbox or favorite message board with dozens or hundreds hyperbolic "pro" open-source software missives, it's going to be junk marketing material nonetheless.

I think this message had enough informative information about how to use features of a popular tool that it deserves to left alone, just like all of the other "tips" on JL.
8 . At 4:56 AM on Jun 20, 2006, Gernot Veith wrote:
  Click to reply to this thread Reply

Re: Coding Guidelines in Modern IDE

when I read the postings - welcome back to the IDE bashing :-/ IMHO one should not post messages with "how to use/configure your favorite IDE". RTFM !
If you are the only one working on a project you can use whatever style guide you want. But if there are some more developers, just find a working compromise for naming, coding and so on.

thread.rss_message