These are chat archives for dennisdoomen/CSharpGuidelines

25th
Aug 2015
Oleg Kleyman
@OlegKleyman
Aug 25 2015 00:08

Hey Guys, with respect to AV1515. Would the literal used here be considered a magic number when the constructor is define as:

/// <param name="characterCount">The amount of characters that a segment should have.</param>
public Segment(int characterCount) and the usage is as such public class

ModelSegment : Segment { public Model() : base(4) {} }

Would the 4 above be considered magic or is being aware of the definition of the parameter be enough?

Dennis Doomen
@dennisdoomen
Aug 25 2015 06:02
@OlegKleyman I would still treat that as a magic number. If you're reading this line in an online diff such as on github, you have no clue what it means. And in most cases, the base-class definition would be in a seperate file.
Oleg Kleyman
@OlegKleyman
Aug 25 2015 08:47
@dennisdoomen Then how would you know if the naming is an accurate representation of the value if you're unaware what it's used for?
Dennis Doomen
@dennisdoomen
Aug 25 2015 12:12
That should have been verified when the base-class is being reviewed.
Oleg Kleyman
@OlegKleyman
Aug 25 2015 13:03
@dennisdoomen but if you're reviewing the child class and you don't know what the base class documentation is then wouldn't you have to look at the documentation for it anyway to verify that the constant is named correctly?
Dennis Doomen
@dennisdoomen
Aug 25 2015 13:27
Well, yes, but if you name the constant something like SegmentCharacterCount, it should be pretty clear.
Oleg Kleyman
@OlegKleyman
Aug 25 2015 22:29
@dennisdoomen but lets say the name of the constant is SegmentCharacterCount, but you are unaware of the base constructor it is used in. Wouldn't it mean that it's not possible review the code for correctness because you wouldn't know whether the name SegmentCharacterCount is correct? On the flip side if you are aware of what the base constructor is doing then wouldn't you be aware of what the literal represents without it being in a constant?