Naming rules priorities, ReSharper 4.5

I find it a little odd that, e.g., the "Constant fields" rule and the "Static readonly fields" rules seem to take precedence over the "Instance field (not public)" and  "Static field (not public)" rules (respectively). This means for instance, that I get a warning about a static readonly field that I've named with a leading underbar (e.g. _myField), and the suggestion to rename it to MyField, when in fact it's a backing field for a public static property that already has that name.

To my mind, the fact that fields are private is more important in this context that that they're constant or readonly. It seems that you can control priority among user-defined rules, but (according to a simple experiment that I did) all the user-defined rules are lower priority than the predefined ones. Seems unnecessarily painful. Why not keep them in a single list, the order of which I can control? Or am I missing some useful aspect of this arrangement?

6 comments

Hi, Dan.

I see your problem.

It is a question of philosophy if ‘private constant’ private or is it constant. In my experience it is more constant but I may mistake.

To work out these ambiguities we designed ‘User defined rules’. User defined rules OVERRIDE general rules. Unfortunately there is a bug. ‘Field constant’ doesn’t work (fixed for 4.5.1).

We are also thinking of adding private constants and readonly fields to the predefined entity kinds set since you’re not еру only user who experience problems like this.

0

Thanks for the information. Could you explain a little more what you mean by "override"? Does this mean that user-defined rules are always searched before the predefined rules (leaving aside the bug you mention)?

It still seems like it would be conceptually simpler if user-defined and predefined rules were in a single list that could be re-ordered at will. With your current setup, it seems like someone might be forced to create several user-defined rules to replace predefined ones, just in order to get them to be tested in a desired order. (But at least that's possible, which is good.)

Yes, the choice of which characteristics should take precedence in choosing a rule certainly is something where preferences will differ. I had to think a bit about why I found the precedence surprising and bothersome. I have a read-only field which is a backing field for a public property. The common recommendation is to avoid exposing fields, read-only or otherwise, as public, so the public property is not redundant. Since these are static, eliminating the backing field using an auto-property would require a static constructor to initialize it -- and static constructors have some disadvantages related to timing. So, having both a static property and its private read-only backing field, they obviously can't have the same name. But I don't want to change the rule for static read-only fields in general -- if it were public, I'd want it to use upper camel case. The deciding factor in choosing a name here is certainly that the field is private.

0

Hi Sergey,

The "Field constant" bug is a real problem for us too.
Is there any release date for 4.5.1.

Thanks!
Jens

"Sergey Shkredov" <no_reply@jetbrains.com> schrieb im Newsbeitrag
news:7762714.77701239695918955.JavaMail.clearspace@app8.labs.intellij.net...
>

Hi, Dan.

>

I see your problem.

>

It is a question of philosophy if 'private constant' private or is it
constant. In my experience it is more constant but I may mistake.
To work out these ambiguities we designed 'User defined rules'. User
defined rules OVERRIDE general rules. Unfortunately there is a bug. 'Field
constant' doesn't work (fixed for 4.5.1).

>

We are also thinking of adding private constants and readonly fields to
the predefined entity kinds set since you're not only user who experience
problems like this.

>
>
>
>

---
Original message URL:
http://www.jetbrains.net/devnet/message/5235765#5235765



0

You’re right. User-defined rules are always searched before the predefined rules.

I like your explanation why you need specific rules for private readonly field and I think we’ll introduce two extra groups of identifiers (issue):

  1. Private readonly fields.
  2. Private constants.

What is concerned single list of rules I don’t think it is a good practice to put items of different kinds into a single list. Off cause it is possible to make ‘predefined rules’ look like ‘user defined’ and introduce a single list with priorities. But we are trying to make settings simple when common practices are used so I think the last solution seems too heavy).



0

We plan to start nightly builds publishing next week.

0

Sergey.Shkredov wrote:

You’re right. User-defined rules are always searched before the predefined rules.

I like your explanation why you need specific rules for private readonly field and I think we’ll introduce two extra groups of identifiers (issue):

  1. Private readonly fields.
  2. Private constants.

What is concerned single list of rules I don’t think it is a good practice to put items of different kinds into a single list. Off cause it is possible to make ‘predefined rules’ look like ‘user defined’ and introduce a single list with priorities. But we are trying to make settings simple when common practices are used so I think the last solution seems too heavy).




Thanks, I look forward to the fix.

As far as the one-list solution goes: Beauty is in the eye of the beholder, I guess. I find the idea of a single list of similar items to be conceptually simpler, thus less "heavy". In fact, I could have addressed this problem merely by rearranging the order of the predefined rules, so not only is it conceptually simpler but also, at least for an issue of this sort, it would be less work to use. But I won' belabor the point further; your solution will work, too, as long as user-defined rules continue to take precedence and they can be made to mimic any of the built-in rules.

0

Please sign in to leave a comment.