suffix instead of a prefix
issueid=105 16-11-2010 21:17
zak zak is offline
Senior Member
Number of reported issues by zak: 12
suffix instead of a prefix

Hi Petr
in a future TBGL module, what about replacing the prefix TBGL_ by a suffix like _GL , something like: GetWindowKeyState_GL instead of TBGL_GetWindowKeyState
i do not know how the other people feel, but for me the prefix are making chaos in my memory, it keeps poping up in my brain and hiding the original and most important word.

i think remembering and manipulating:
MouseGetPosX_GL
MouseGetPosY_GL
MouseGetLButton_GL
CenterCursor_GL
..... etc
in the brain dictionary of an average man/woman
are easier than
TBGL_MouseGetPosX
TBGL_MouseGetPosY
TBGL_MouseGetLButton
TBGL_CenterCursor
.... etc
this is may be my own neuro health problem, but i feel i must express my idea, for a future contemplation.
Issue Details
Issue Number 105
Issue Type Feature
Project TBGL
Category Unknown
Status Implemented
Priority Unknown
Suggested Version Unknown
Implemented Version (none)
Votes for this feature 0
Votes against this feature 0
Assigned Users (none)
Tags (none)




16-11-2010 21:52
Super Moderator
Hi Zak,

I must say I still like the prefix way - and I think it will work in future better for stuff like code completion this way... (you first specify module, which quickly differentiates TBGL_IsWindow from UI module IsWindow) but that does not mean there is no solution to this problem

As thinBASIC supports ALIAS keyword, you can redefine all the function names to suit your preference. Even better, such a keyword mod can be done in automated way using thinBasic itself :)

Just run this script once, it will generate new, complete alias include file for you:
  Uses "File"
  uses "TBGL"

  Dim sListOfKeywords As String
  Dim Keyword()       As String
  Dim nKeywords       As Long
  Dim i               As Long
  Dim sFileContent    As String
  
  sListOfKeywords = APP_ListKeywords
  
  '---Parse string into an array
  nKeywords = Parse(sListOfKeywords, Keyword, $TAB)

  '---Creates output buffer
  sFileContent = "' This is include file of Zak's custom names for TBGL" + $CRLF(2)
  For i = 1 To nKeywords
    If StartsWith(Keyword(i), "TBGL_") Then
       sFileContent += "ALIAS " + Keyword(i) + " AS " + PetrsTBGLNameToZaksTBGLName(Keyword(i))+ $CRLF
    End If
  NEXT

  '---Save buffer into .INC file
  FILE_Save(APP_Path + "\Inc\" + "CustomTBGLFunctionNames.inc", sFileContent)
  
  Function PetrsTBGLNameToZaksTBGLName( sNameIn As String ) As String
    sNameIn  = Remove$(sNameIn, "TBGL_")
    sNameIn += "_GL"
    Return sNameIn   
  End Function
... and then, in your programs, just use:
#INCLUDE "CustomTBGLFunctionNames.inc"
... like in this example:
Uses "TBGL"    

#INCLUDE "CustomTBGLFunctionNames.inc"

Function TBMain()
  Local hWnd      As DWord
  Local FrameRate As Double
  
  ' -- Create and show window
  hWnd = CreateWindowEx_GL("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
  ShowWindow_GL 

  ' -- Initialize lighting
  UseLighting_GL(%TRUE)
  UseLightSource_GL(%GL_LIGHT0, %TRUE)

  SetLightParameter_GL(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1)

  ' -- Resets status of all keys 
  ResetKeyState_GL()

  ' -- Main loop
  While IsWindow_GL(hWnd) 
    FrameRate = GetFrameRate_GL

    ClearFrame_GL 
      Camera_GL(15, 15, 15, 0, 0, 0)
      
      Color_GL(255, 128, 0)
      Box_GL(1, 1, 1)

    DrawFrame_GL 

    ' -- ESCAPE key to exit application
    If GetWindowKeyState_GL(hWnd, %VK_ESCAPE) Then Exit While 

  Wend 

  DestroyWindow_GL
End Function
I know the TBGL_ prefix can be annoying, maybe in future when some dark magic like namespaces will be supported, you will be able to do something like:
USING TBGL
  CreateWindowEx(...)
  ShowWindow
  
  ResetKeyState()
END USING
and so on. But that would need major change in the parser and also the IDE (to still provide context sensitive help), so I guess this is not comming that soon. But I hope the include file way is acceptable for you at the moment.


Petr

16-11-2010 23:55
Member
>>>> lol <<<<

17-11-2010 06:54
Member
I am not familiar with many other basic languages, but the Alias keyword seems to put thinBasic above the rest. Although there are limitations, you can use thinBasic in almost any way you want, making it easier for you.

Go thinBasic! :D



Mark

17-11-2010 07:32
zak zak is offline
Senior Member
this is a complete magic.
like a magician who show a rabbit out of nothing, or like a topology in wich the impossible elastic shapes are possible, yes it works, i have read your message yesterday but because i have a mild influenza i was not able to try the example, so i have tried it today.
your method can be used also by any one who may suffer from what i call :
" Prefix Illness Syndrom ", and that more people will enjoy and attracted to the TBGL module.
what can i say !!, you have saved me.
thank you

17-11-2010 13:14
thinBasic author
Petr,

once again you have the ability to quicly find so cool and clever solutions.

Eros

17-11-2010 14:02
Super Moderator
Hi Petr,

great job. Doesn't thinAir support userkeywords and so your script could create these too. Then you get the full support by syntax highlighted ALIASES.

Cheers
Michael

17-11-2010 14:31
Super Moderator
Good idea,

in case of custom defined keywords it can get complicated, as there can be some already present, so we cannot just overwrite the definition file. But what we can do is to get existing items, new items, combine them, make sure there are no duplicates and then save again. It sounds complicated, but thanks to ARRAY UNIQUE it is not :)
  Uses "File", "Console"
  Uses "TBGL"

  Dim sListOfKeywords   As String
  Dim Keyword()         As String
  Dim nKeywords         As Long
  Dim nNewKeywords      As Long
    
  Dim sCustomKeywords         As String  
  Dim Lines()                 As String
  Dim nLines                  As Long  
  Dim CombinedLines()         As String  
  
  Dim i                 As Long  
  Dim newKeyword        As String
  Dim userKeywordsFile  As String
  Dim sFileContentINC   As String
  Dim sFileContentINI   As String
  
  PrintL "Generating include file..."
  sListOfKeywords = APP_ListKeywords
  
  '---Parse string into an array
  nKeywords = Parse(sListOfKeywords, Keyword, $TAB)

  '--- Create include file
  '---Creates output buffer
  sFileContentINC = "' This is include file of Zak's custom names for TBGL" + $CRLF(2)
  For i = 1 To nKeywords
    If StartsWith(Keyword(i), "TBGL_") Then   
       nNewKeywords    += 1
       
       newKeyword       = PetrsTBGLNameToZaksTBGLName(Keyword(i))
       sFileContentINC += "ALIAS " + Keyword(i) + " AS " + newKeyword + $CRLF
       sFileContentINI += newKeyword + $CRLF
    End If
  Next

  '---Save buffer into .INC file
  FILE_Save(APP_Path + "\Inc\" + "CustomTBGLFunctionNames.inc", sFileContentINC)

  PrintL "Generating custom keywords for thinAir..."
  PrintL
  '---Add new items to custom syntax file
  userKeywordsFile = APP_Path + "\thinAIR\Syntax\thinBasic\" + "thinBasic_Keywords_Usr.ini"
  If FILE_Size(userKeywordsFile) = 0 Then
    ' -- It is empty, we can safely overwrite it
    FILE_Save(userKeywordsFile, sFileContentINI)
  Else                                          
    ' -- We need to add only new items
    sCustomKeywords = FILE_Load(userKeywordsFile)
    
    ' -- We get existing items
    nLines          = Parse(sCustomKeywords, Lines, $CRLF)     
    
    ReDim Preserve Lines(nLines+nNewKeywords)
    
    ' -- Add new items to it
    For i = 1 To nNewKeywords
      newKeyword      = Parse$(sFileContentINI, $CRLF, i)
      Lines(nLines+i) = newKeyword
    Next
    
    ' -- Remove duplicates                              
    Array Unique Lines, CombinedLines  
    
    ' -- And save it back
    sFileContentINI = Join$(CombinedLines, $CRLF)                                
    
    FILE_Save(userKeywordsFile, sFileContentINI)
  End If
  
  PrintL
  PrintL "Done, press any key..."        
  WaitKey                                                                                                       
  
  Function PetrsTBGLNameToZaksTBGLName( sNameIn As String ) As String
    sNameIn  = Remove$(sNameIn, "TBGL_")
    sNameIn += "_GL"
    Return sNameIn   
  End Function
Petr

17-11-2010 15:22
zak zak is offline
Senior Member
the greatness itself,
after applying Petr code above now the SetLightParameter_GL ... are highlighted , like in the picture:


17-11-2010 16:40
Super Moderator
That is why I love thinBasic and all the people in this community. Problem, discussion and thanks because of our swiss army knife called thinBasic, solution found.

13-12-2010 20:20
Issue Changed by Petr Schreiber

13-12-2010 20:45
Issue Changed by Petr Schreiber
  • Status changed from On Hold to Implemented

+ Reply