[Gambas-user] Better use of prefixes

Cedron Dawg cedron at exede.net
Sat Mar 16 23:27:50 CET 2019


I think it was representative of a lot of the issues.  Put up a piece of code in your preferred style, and I'll make it Dawggy Style, and we can compare.  Not too long though, please.

In this case there is clearly only one scrollbar, as the reference is inside a class definition that is not part of a form.

Had there been more than one, a good name would be 

myCatapaultScrollBar or myCatapaultSB

See, I'm not totally abbreviation averse.  I often name references to objects with an uppercase abbreviation for the Class name.  But I don't need a secret decoder ring to figure it out, just find the declartion and it becomes obvious.

  Private myCatapaultSB As ScrollBar

As the programmer, that is different than having to know "scb" in advance.  As a maintainer

  Private $scbMain As ScrollBar 
  
would tell me what "scb" meant.  

Also, in the same Class, I have:

  Private myW As Float ' Equilibrium Width

  Private myPr As Float ' Position of Recoil Factor

  Private myCoconut As CoconutClass

So, if I do use an abbreviation, I try to always provide a comment right next to the definition saying what it stands for.

Ever see a scroll bar hurl a button?  I've attached the code.

As for the $ on object references, the naming convention link states "All private variable names of a class start with $".  I interpret an object reference as a variable.  If you leave the $ off, it does indeed make the code look less "geekish", but not by much.

Previous renditions of BASIC have had type declaration characters.  Those were type suffixes enforced by the compiler and I used them heavily as I don't like having to dim all my variables.  First thing I would do in VB is shut off "Option Explicit".  Not many people used them, and Gambas doesn't support them, so that is a moot issue.  Though a few function names, like ChrS(), are vestigial leftovers.



----- Original Message -----
From: "Jussi Lahtinen" <jussi.lahtinen at gmail.com>
To: "user" <user at lists.gambas-basic.org>
Sent: Saturday, March 16, 2019 6:02:14 PM
Subject: Re: [Gambas-user] Better use of prefixes

I don't think your code example is representative of the whole issue. What if there are multiple containers, buttons, etc? What if there are long / complex lines? 
Even in your chosen example "myScrollBar" says nothing about its function or identity, only that it is scrollbar. But "scbMain" hints right away how the scrollbar is used (not much but still). 
More descriptive the variable name is, longer it becomes and it really adds up in already long lines. So, I chose not to waste space for the type information, when it can easily be shortened. 

I don't think $ is used in names of controls. They shouldn't be public anyway. 


Jussi 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CoconutThrower-0.0.2.tar.gz
Type: application/x-compressed-tar
Size: 14489 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190316/9cf55260/attachment-0001.bin>


More information about the User mailing list