[Gambas-user] Better use of prefixes

Cedron Dawg cedron at exede.net
Sat Mar 16 20:25:02 CET 2019


Understood, and I'm not disagreeing.

But I am saying you can do better.  If a newbie needs a secret decoder ring to figure it out, it isn't clear.

$iMyNumber
$nMyNumber 
$lngMyNumber

What does the "My" mean here?

You can specify the type explicitly as a suffix if you really need to.

myNumberInt
myNumber???
myNumberLong

What does "n - An integer storing a number of objects." even mean?  Integers store bits (or Horsey Numbers).  Do you mean "Count"?

"NumberButton" to me, immediately says I have a button on the form with the caption "Number", so the routine name would be:

Sub NumberButton_Click()

Clear, even to a guppy.

Do you think "Sub btnNumber_Click()" is really better?

How about iCount?  What does that tell you?  You've got an integer that is counting, but counting what, where is it defined?

theCount would say the same thing.  Counts are always integers aren't they?


theLineCount tells me a local variable counting lines
argLineCount tells me a passed argument in a private sub 
myLineCount tells me it is a class level private variable

MyLineCount tells me it is an exposed class level public variable.

theEmptyLineCount 

theFullLineCount

theResult is not as clear.  If needed, add a type:  theResultInt or kind: theResultText

A good specifier is location + identification + kind.

Look at a filepec = path + basename + extension

The bottom line is code should be as readable to as wide of an audience as possible, not tailored to specific conventions understood by a select few.

>From your own reference "All the users of the hungarian convention that I know have in a first time hated it".  Damn straight and for good reason.  It is backward, like reverse Polish calculators.

Again, from a program maintenance point of view, knowing the scope of a variable is a lot more important than knowing its type.  Following my convention you get both in a readable format vs only type (with the $ exception) in the (not sure what polite words to use here).

When I taught a class in advanced VB many years ago and we went through the exercise of placing controls on a form, I would have them hit [End] and backspace to remove the number, then [Home] to enter a meaningful name, then [Shift-Home] to highlight it, [Ctrl-C] to copy, then click on the Caption property and [Ctrl-V] to paste.  This works well in Gambas too.



----- Original Message -----
From: "Gianluigi" <bagonergi at gmail.com>


> More readable for whom? 
For me I speak only for myself. 

The prefix is not a dogma is an indication and the programmers who use I find them very nice. 
If I read a variable $ iMyNumber or $ nMyNumber or $ lngMyNumber I understand that it is an integer, if I read btnNumber or btNumber I understand that it refers to a Button. 
For example, I use btn for each type of button, not just Button. 
No one forces anyone and you are free to do as you wish. 

Regards 
Gianluigi 



More information about the User mailing list