cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
ImDaFreaK:
few coding tips for you:
if you make a private variable, it can never be accessed outside this class. you dont need to make a property for it too. just use the variable name. properties are used mainly when we want to present an internal variable to other classes as a different type, name or to add some validation to getting/setting - its not really needed in this case and is an extra hoop for the cpu
all the code ive ever seen uses either underscores or initcaps to delimit words - i rarely see both. VB's excuse in the case of Control_EventThing is that the control is called Control, the event thing is called EventThing and you would normally say Control.EventThing if addressing it as a property - VB will convert the . to _ to maintain some familiarity and give a good unique name ofr an event on a control etc..
it's mainly a time/extra keypresses for you, and that as a developer that uses the styles interchangeably but never combined, i find it looks weird, and doesnt help me determine whether what i'm looking at is a variable, class, event, sub name etc..
you rarely need to say Me. to refer to a local variable - the designer does for safety as it doesnt look to see if youve called a variable with the same name, publicly globally accessible elsewhere in your code. i typically find it adds to the visual clutter and i remove it wherever its not specifically needed..
i didnt find your variable names very easy to understand. Cancel_Context_Menu sounds like an action - a method/sub that will cause a context menu to be canceled. Microsoft typically recommend that boolean variables have a name that implies a yes/no logical outcome and also that the tone of the variable name is positive.. this is why i chose ctxMenuClosingEvtMustCancel
Perhaps ctxMnuCloseEventMustBeCanceled would have been even better. i did call it dontCloseContextMenu to start with, then remembered my own advice of giving a positive tone.. i.e. i would be setting a true when i wanted something not to happen and a false when i wanted somethign to happen. hence i would maybe have had to write:
If Not dontCancel Then e.Cancel = true...
whereas arranging a boolean variable name with a positive tone allows us to write:
If somethingShouldHappen Then doThatSomething()
vs
If Not somethingShoudntHappen Then doThatSomething...
so, key points on code readability really are: reduce clutter, make variable names nicely self documenting and think carefully about the tone of variable names etc
at the end of the day, coding is very much personal opinion - i've seen quite a bit over the time that ive been coding and have usually nicked the neat looking ideas to develop my own personal style. i'm passing this on not so much as a "hey, do what i do" but as a hey "here's what most people would do, in my opinion", and of course, youre free to ignore it
few coding tips for you:
VB.NET:[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] m_Cancel_Context_Menu [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE] [SIZE=2][COLOR=#0000ff] [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] Cancel_Context_Menu() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Get [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Return[/COLOR][/SIZE][SIZE=2] m_Cancel_Context_Menu [/SIZE][SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Set[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] value [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2]) m_Cancel_Context_Menu = value [/SIZE][SIZE=2][COLOR=#0000ff] End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Set [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property [/COLOR][/SIZE]
if you make a private variable, it can never be accessed outside this class. you dont need to make a property for it too. just use the variable name. properties are used mainly when we want to present an internal variable to other classes as a different type, name or to add some validation to getting/setting - its not really needed in this case and is an extra hoop for the cpu
all the code ive ever seen uses either underscores or initcaps to delimit words - i rarely see both. VB's excuse in the case of Control_EventThing is that the control is called Control, the event thing is called EventThing and you would normally say Control.EventThing if addressing it as a property - VB will convert the . to _ to maintain some familiarity and give a good unique name ofr an event on a control etc..
it's mainly a time/extra keypresses for you, and that as a developer that uses the styles interchangeably but never combined, i find it looks weird, and doesnt help me determine whether what i'm looking at is a variable, class, event, sub name etc..
you rarely need to say Me. to refer to a local variable - the designer does for safety as it doesnt look to see if youve called a variable with the same name, publicly globally accessible elsewhere in your code. i typically find it adds to the visual clutter and i remove it wherever its not specifically needed..
i didnt find your variable names very easy to understand. Cancel_Context_Menu sounds like an action - a method/sub that will cause a context menu to be canceled. Microsoft typically recommend that boolean variables have a name that implies a yes/no logical outcome and also that the tone of the variable name is positive.. this is why i chose ctxMenuClosingEvtMustCancel
Perhaps ctxMnuCloseEventMustBeCanceled would have been even better. i did call it dontCloseContextMenu to start with, then remembered my own advice of giving a positive tone.. i.e. i would be setting a true when i wanted something not to happen and a false when i wanted somethign to happen. hence i would maybe have had to write:
If Not dontCancel Then e.Cancel = true...
whereas arranging a boolean variable name with a positive tone allows us to write:
If somethingShouldHappen Then doThatSomething()
vs
If Not somethingShoudntHappen Then doThatSomething...
so, key points on code readability really are: reduce clutter, make variable names nicely self documenting and think carefully about the tone of variable names etc
at the end of the day, coding is very much personal opinion - i've seen quite a bit over the time that ive been coding and have usually nicked the neat looking ideas to develop my own personal style. i'm passing this on not so much as a "hey, do what i do" but as a hey "here's what most people would do, in my opinion", and of course, youre free to ignore it