Question

I'm reading Petzold's free (.PDF) WP7 book, and he says that he always changes "EventArgs e" to "EventArgs args" in event handlers (which makes sense to me, as "e" sometimes conflicts with what I want to name the Exception object); but he also says he removes the accessibility modifiers that are automatically prepended sometimes.

I'm wondering why he does so, and:

1) Should I adopt the same practice
2) If that's a better way (Petzold is no wet-behind-the-ears greenhorn), why doesn't MS create these methods that way by default?
Was it helpful?

Solution

(I'm assuming this is a matter of removing the private access modifier from a method. If it's removing (say) public then that's a semantic change, and a different matter.)

It's definitely a matter of personal preference. I used to favour removing the access modifier when it was the default, but these days I prefer to be explicit.

Benefits of leaving it implicit:

  • Less clutter (important when writing books, which may well be relevant here)
  • As the default is always "the most private you can express explicitly" it makes it more obvious which members have been "promoted" to have wider access

Benefits of making it explicit:

  • Readers who don't know the language as thoroughly are left in no doubt
  • It introduces one more mental reminder that you need to actively think about this. (I'm sure people often leave things in a default way without further thought otherwise - I see relatively few virtual methods in C# compared with Java, just because of the defaults.)
  • Assuming you follow mental reminders, it shows the reader that this was a deliberate decision.

If you want an "appeal to authority" you may be interested to know that Miguel de Icaza favours (vehemently) the former approach, and Eric Lippert favours the latter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top