#262 Enhancements to magic number check

Future
closed
nobody
Check (274)
5
2015-10-22
2003-10-30
Joe Comuzzi
No

I'd like to propose the following RFE for the magic
number check.

Add a property "ignoreContext" where magic number
checks will be suppressed. The ignoreContext would take
a list of possible values:

1) RHS of static initializes. This permits initializes like:

static final int BUF_SIZE = 8*1024;
static final State START = new State(1);

etc. The justification for ignoring this context is that
such magic numbers are magic, but that's OK (for some
users). There can be some complications involving
embedded class definitions as pointed out by Lars.
Still, it seems relatively easy to implement.

2) In the body of the hashCode method. The
justification for ignoring this context is that hash
function implementation commonly contain prime
numbers which are magic - but that's OK (for some
users). This one seems easy to implement - since the
hashCode method is a specific well known method on
Object.

3) In initializes for the default size of HashTables, etc.
These magic numbers are not as dangerous as magic
numbers which reflect the fixed size of a table.
This one seems harder to implement, maybe
ignoreContext would specify "constructorArgument" and
another property could specify a list of constructors it
applied to.

The intent of all of the above is to reduce the number of
unimportant (or less important) magic number reports so
that it's tractable to actually run with this check turned
on and find the REALLY bad ones. I suppose if there's a
way (as has been previously requested) to suppress
warnings by adding comments - that would also solve
this - but it's not as attractive as being able to
customize the checks.

Discussion

  • Lars Kühne

    Lars Kühne - 2006-01-13

    Logged In: YES
    user_id=401384

    Note that this request is against the old implementation.
    The check has been changed significantly in Version 3.5,
    e.g. magic numbers such as thise in "1)" are now always ignored.

     
  • Roman Ivanov

    Roman Ivanov - 2015-10-22
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks