Beta [SOLVED] 5.8 : Variable name cannot be the same as sub name

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
Just to report as it is the first time since over 3 years that I used that code and today I've got that warning in the Logs from beta 5.8 (of course I have corrected my error easily)

In a code module where I have something like this (very cleared for the demo)

B4X:
Sub LoadContent
  Dim Content as Map
  Content.Initialize
  Content=ReadMap(Destination,"MapFileName")
End Sub

Sub Destination as Boolean
Return File.ExternalReadable
End Sub

Sub ReadMap(Destination as Boolean, MapName as String) as Map
  Dim MyMap as Map
  MyMap.Initialize
  If Destination then
    MyMap=File.ReadMap(File.DirExternal,MapName)
  Else
    MyMap=File.ReadMap(File.DirInternal,MapName)
  End if

  Return MyMap
End Sub
 
Last edited:

Mark Read

Well-Known Member
Licensed User
Longtime User
When I did my first programming course, the first thing I learned was

1. Never use a reserved (command) name for a variable name OR subroutine name.
2. Using an event variable (as in Destination here) as variable is also a no go.

Maybe old fashioned and is not always required but I stick to it. I tend to use descriptive variable names e.g. RPiBluetoothConnection (as boolean) and mix upper and lower case.

But then again, Murphy does have a way of sneaking in sometimes. I can remember on my Sinclair Spectrum, I wrote a long basic program and used the function keys to save. Unfortunately pressing 2 together - careless! The result was the command save "load""" and bang, my program was deleted and the spectrum crashed. Everything gone!

Just my two pennies worth. :D:D
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Just my two pennies worth.
And you are absolutely right. It was an extracted example of a long code module where the two subs weren't at the same place (reason why I had used the same name for the sub and the variable). That said, it is great that the new version will be able to warn about such stupid mistakes :)
 
Upvote 0
Top