Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DECLARE LIBRARY at the end of your code?
#1
Now, I know this might seem a little strange, but hear me out:  I think folks need to start adopting the strategy of placing DECLARE LIBRARY routines at the end of their code, rather than at the beginning of it.

Now, hold up a moment there!  Before you go saying, "Welp, Steve's finally lost his marbles, everybody's always placed those declarations at the top of their source code!", give me a chance to showcase why I'll probably be adopting this new coding style from now on:

Code: (Select All)
Print BorderWidth, TitleBarHeight


Function BorderWidth&
    $Let GLUTGET = TRUE
    BorderWidth = glutGet(506)
End Function

Function TitleBarHeight&
    $Let GLUTGET = TRUE
    TitleBarHeight = glutGet(507)
End Function

Sub ScreenMove_Middle
    'Moves to the absolute middle of the desktop, ignoring border and title, so the program window is centered without
    'taking them into consideration.
    $Let GLUTGET = TRUE
    _ScreenMove (_DesktopWidth - _Width - BorderWidth) / 2 + 1, (_DesktopHeight - _Height - BorderWidth) / 2 - TitleBarHeight + 1
End Sub

Sub ScreenMove (x, y)
    'Moves to the absolute coordinates of the desktop, ignoring border and title, so the program window is
    ' positioned with the program window at the desired position, without taking them into consideration.
    $Let GLUTGET = TRUE
    _ScreenMove x - BorderWidth, y - BorderWidth - TitleBarHeight
End Sub

$If GLUTGET = TRUE Then
    $If GLUTGET_DECLARED = UNDEFINED Then
        $Let GLUTGET_DECLARED = TRUE
        Declare Library
            Function glutGet& (ByVal what&)
        End Declare
    $End If
$End If

As you can see from the code above, I can now write my SUB and FUNCTION in such a manner that they make certain that the DECLARE LIBRARY in question is included in my source.

Now, what's the point to such tomfoolery, you ask? 

In this case, it allows me to wrap everything up nice and neat in one *.BM file.  I don't need to turn the above into two different libraries, with one just for the *.BI Declare Library.  It also allows me to write these routines and wrap them up so that I can limit which ones I require in a program.  (See the recent Github Toolbox here https://github.com/SteveMcNeill/QB64-Pho...on-Toolbox for an example of this SUB/FUNCTION inclusion/exclusion at work.) 

Now, using this style, I can include one of those routines uniquely in my code as needed, and it'll automatically add in the DECLARE with it.  And, without me manually including one of those routines which need this particular DECLARE LIBRARY, it's simply excluded and not used at all in my program, keeping EXE filesize and memory usage as small as possible for whatever app I end up building.  Smile

DECLARE LIBRARY at the end of your code, instead of at the front.  It might not be just as crazy as you'd think it is at first glance.  Wink
Reply


Messages In This Thread
DECLARE LIBRARY at the end of your code? - by SMcNeill - 10-13-2023, 02:23 AM



Users browsing this thread: 1 Guest(s)