Style survey

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:02 pm

by Anonymous >> Sun, 29 Oct 2006 20:34:29 GMT

Another two bob's worth ...



I'm absolutely with Brendan, John and Alistair; clarity and readability are everything.



I even concede to use i,j as counters for simple loops, but long, descriptive (and carefully thought out) names are the best way to convey meaning. Using a verb-noun notation for method names usually allows easy distinction from properties, etc, so making () unnecessary.



Hungarian Notation became popular in other languages for compiler specific reasons, and just isn't relevant in Jade. An exception I occasionally find useful is prefixing local variables with 'str' within a display formatting method, to distinguish from the native primitive.e.g.

strPaymentAmount := (paymentAmount / 100).userFormat($Dollars).



I like the underscore prefix for parameters because it is less of a distraction than 'p', which can sometimes convey an erroneous meaning at a glance (e.g. "pCode", "pAct", and what is a "pangle", "ploop" or "pupper"?). Underscore also follows the convention (not entirely consistently) used in Jade meta-code.



self isn't necessary for Ctrl1,2 to work. Jade allows parameters and local variables with the same name as properties (was this always allowed?). I've seen this used in 'set' method parameters (no underscore or 'p' required). If you do use this 'feature', then selective use of self can be used to distinguish local variables from class properties.



setValues(code : Integer; .... );

...

self.code := code;



I reckon John makes a good point in his first posting - conventions are fine if followed by the whole team, otherwise inconsistent application can cause confusion than it attempts to avoid. Perhaps Alistair's "the way we each prefer" should taken in moderation (oh no, not the style police!)



Cheers,

Robert

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:02 pm

by Barry >> Sun, 29 Oct 2006 22:18:23 GMT

I like adding self. for a couple of reasons:

1. If someone inadvertently adds a new local variable or parameter to the method that happens to have the same name as a property it will not introduce unwanted, and probably unnoticed, changes to the method logic.

2. It is useful when you are in the debugger and actually want to inspect self. Unless someone can tell me a way to inspect self when there is no self in the method source other than going up a level in the call stack to get to the effective self.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:02 pm

by BeeJay >> Sun, 29 Oct 2006 22:39:20 GMT

Barry,

1. Personally I'd prefer it if you could not have a local variable or parameter with the same name as a property so that developers can't shoot themselves in the foot like this. That said, if this is your main reason for always adding self it seems like overkill for the odd occasion that this may actually happen.

2. When you press the Inspect button on the ToolBar with no text selected in the debug window, or as I normally do via the Ctrl+I keyboard shortcut, if you then type self into the resultant dialog it will inspect self as desired.

Since others have mentioned Hungarian, I may as well add that one place where I do like the use of Hungarian notation is for controls on forms such as txt for TextBoxes etc. Unfortunately is also the one place where use of Hungarian notation also means you more quickly run out of characters for naming your control due to the naming convention of event methods for those controls. Who else would like to see the character limit for properties/classes/etc increased - doubling the length would be a good start, especially for dictionary class names, and references that use those dictionaries, and for control names.

Cheers,
BeeJay.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:02 pm

by Robert >> Mon, 30 Oct 2006 2:23:48 GMT

Double-click stack entries in the debug window to inspect the selected method's receiver.
Double-click the top stack entry to inspect self.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:02 pm

by Barry >> Mon, 30 Oct 2006 3:22:37 GMT

Thanks BeeJay, that is useful.

Robert - nothing happens when I double click an entry on the call stack form in the debugger. Actually that is not entirely correct, each click on the call stack window swaps focus to the method source window with the appropriate method source displayed, so perhaps that is stopping the double click working. What windows do you have open in the debugger when you use this technique as it sounds like it would be quicker than typing self each time like BeeJay suggested. I normally have the following 4 windows open in the debugger:

Local Variables
Call Stack
Breakpoints
Method source

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:03 pm

by Anonymous >> Mon, 30 Oct 2006 22:52:01 GMT

Sorry Barry, you're quite right ... this works in the "popup" debugger window (from the exception dialog box, etc), but not from the "debugger" debugger window ... I have a feeling this feature was introduced not so long ago (Jade 5), and has since disappeared, but I may be getting my debugger windows confused. So I'm afraid Beejay's solution is your best bet. Cheers,
Robert

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Style survey

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:03 pm

by BeeJay >> Wed, 1 Nov 2006 1:15:51 GMT

Robert,

Actually, having now started to use this in the UHE debug window I keep wanting to double click the debugger application's call stack window in a similar manner.

I've therefore opened an NFS suggesting it would be nice if the debugger application's call stack window did the same thing on a double click.

Cheers,
BeeJay.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests