Naming Conventions in JustCode

by Just* Team | Comments 3

Choosing appropriate identifiers for the constructs in your code provides better readability and maintainability. With the latest build of Telerik JustCode you can now easily set naming conventions for all your code elements.

Configuration and Supported languages

These rules can be set for C# and VB.NET and are part of the Code Style section of the JustCode options dialog:

These options are part of the shared settings so you can share them per solution as well.

Naming Rules

There are seven types of rules that a user can choose from:

  • camelCase
  • PascalCase
  • UPPER_UNDERSCORE
  • lower_underscore
  • Sentence_underscore
  • PascalCase_Underscore
  • camelCase_Underscore

You can also disable the naming convention for a specific construct. Just choose “Disabled” from the rules combo box.

Warnings

JustCode will analyze every identifier in your solution and will show a warning if the name of the construct does not match the specified naming rule:

 An appropriate fix will be available:

Secondary rules

There are some cases, in which you would like to set two rules for a construct, so that JustCode will accept either one of them when analyzing the name of the construct.

Consider the following case, where you want to have constants that are Pascal Case as well as constants that are UPPER_UNDERSCORE_CASE:

JustCode is showing a warning that the second constant does not match the naming conventions, because the naming rule for constants is set to “PascalCase”. You can, however, specify a secondary rule. To do so, click on the “Add” button in the Naming Conventions section or choose from the available context menu “Add Secondary Rule”. Save the chosen setting and the analysis will be refreshed automatically. The warning will not be shown anymore:

Code Generation

JustCode does not only show warning if the identifier of a construct does not match the chosen rule, but also uses the Naming Conventions when generation new constructs:

Quick-Fixes

The Naming Conventions are also used in the quick-fixes that JustCode suggests:

That’s it for today. If you are eager to put your hands on these new functionalities, you can give Telerik JustCode a try! We hope you like what you see, much more to come. Your feedback is welcome and appreciated. Write to us in forum or support.

What's Coming?

Our Q1 2012 Webinars are just around the corner. If you attend the What’s New in Tools for Better Code webinar, you can see live demos of the features mentioned in this blog post and much, much, more. One lucky winner from the Just* webinar will receive a Telerik Ultimate Collection worth $1999. More importantly, you will sharpen your ninja skills to write better code! 

Happy Coding!

The JustCode team

About the author

Chris Eargle

Chris Eargle

is a Telerik Technical Evangelist and Microsoft C# MVP with over a decade of experience designing and developing enterprise applications, and he runs the local .NET User Group: the Columbia Enterprise Developers Guild. He is a frequent guest of conferences and community events promoting best practices and new technologies. Chris is a native Carolinian; his family settled the Dutch Form region of South Carolina in 1752. He currently resides in Columbia with his wife, Binyue, his dog, Laika, and his three cats: Meeko, Tigger, and Sookie. Amazingly, they all get along... except for Meeko, who is by no means meek.

3 Comments

John Smith
moderated because of foul language
Ravi Kaushika
I hope some one is reading this blog.  I have been following a convention like this: _varPageVariable for whole page or whole class variable (private or public) and varLocalOrMethodOrFuncVariable for inner function variables.  right now, how do I say, it is ok to have 2 levels of variables.  when i am trying to debug the code at line # 2856, i cannot be doing page ups to see whether it is a member variable or a XAML.cs file level variable.  to distinguish a larger scope variable from a member level var, i pre-fix the larger scope with an underscore.
how to not get that warning with a suggested name.    adding a new 'option' as suggested there is not work for some reason.  i have version 2012.1.315.3 of justcode.
thanks and regards
ravi.
thanks for
Ivan
Thank you for your feedback. I tried to reproduce your issue, but I was not able to. Furthermore, there is no need for you to add a secondary naming convention. If you want to have a prefix "_" for all of your fields, you should only edit the primary naming conventions. JustCode defines several conventions for fields depending on their modifiers. If you want all of them to have "_" as a prefix, you have to edit the conventions for:
Private Fields,
Protected Fields,
Public And Internal Fields,
Constant Fields,
Non ReadOnly-Static Fields
Private ReadOnly Static Fields
Non-Private ReadOnly Static Fields.
Please note, that in some cases you should change the rule from PascalCase to camelCase(for Public And Internal Fields for example).
I have prepared a sample demo how to do this: http://screencast.com/t/w6UoJyKO8.
If you have any more questions, remarks or you still experience the same behaviour, please do not hesitate to contact us again!

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by Just* Team - or - read latest articles in Developer Tools