[Gambas-user] Better use of prefixes

Jussi Lahtinen jussi.lahtinen at gmail.com
Sat Mar 16 23:02:14 CET 2019


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

On Sat, Mar 16, 2019 at 11:33 PM Cedron Dawg <cedron at exede.net> wrote:

> I like "suffix" rather than "postfix", but both are entirely
> understandable as well.
>
> It's a matter of specificity precedence if I may abuse some language.
>
> Do you like "perro negro" or "black dog"?
>
> Jussi Lahtinen or Lahtinen, Jussi
>
> I can totally understand once you get used to something, it becomes your
> preference.  And preferences are just like opinions everybody..., ummmm,
> wait a moment, they are opinions.
>
> Please tell my your opinion on this.  Which version do you find more
> comprehensible?  Quick, now.
>
> http://gambaswiki.org/wiki/doc/naming
>
> I could not find "ScrollBar" or "Container".  Not sure where it is in the
> source tree either.  So I'll guess "scb" and "cnt"
>
> So my code:
>
>
> '=============================================================================
> Public Sub MoveVerticalSteps(ArgSteps As Float)
>
>         Dim theNewY As Float
>         Dim theContainer As Container
>
>         theContainer = myScrollBar.Parent
>
>         theNewY = myScrollBar.Y + ArgSteps * myScrollBar.H
>
>         If theNewY + myScrollBar.H > theContainer.H Then
>             myScrollBar.Y = theContainer.H - myScrollBar.H
>         Else If theNewY < 0 Then
>             myScrollBar.Y = 0
>         Else
>             myScrollBar.Y = theNewY
>         Endif
>
> End
>
> '=============================================================================
>
> Becomes:
>
>   Dim fY As Float
>   Dim cntMain as Container
>
>   cntMain = scbMain.Parent
>
>   fY = $scbMain + fSteps * $scbMain.H
>
>   If fY + $scbMain.H > cntMain.H Then
>       $scbMain.Y = cntMain.H - $scbMain.H
>   Else If fY < 0 Then
>       $scbMain.Y = 0
>   Else
>       $scbMain.Y = fY
>   Endif
>
>
>
>
>
> ----- Original Message -----
> From: "Jussi Lahtinen" <jussi.lahtinen at gmail.com>
> To: "user" <user at lists.gambas-basic.org>
> Sent: Saturday, March 16, 2019 5:13:55 PM
> Subject: Re: [Gambas-user] Better use of prefixes
>
> I like short variable names and I find prefixes aesthetically more
> pleasing than postfixes.
> Thus I strongly prefer "btnThis" than "ThisButton". But both are fully
> understandable.
>
>
> Jussi
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190317/718767c2/attachment.html>


More information about the User mailing list