twinBASIC Update: September 19, 2021

Highlights include discussions around block scoping and a planned ObjRefCount() function.

twinBASIC Update: September 19, 2021

On April 23, 2021, I helped Wayne Phillips introduce the world to twinBASIC at the Access DevCon Vienna conference.  I boldly predicted that twinBASIC (along with the Monaco editor) would replace VBA and its outdated development environment by 2025.  With that goal in mind, this weekly update is my attempt to keep the project fresh in the minds of the VBA development community.

Every Sunday, I will be providing updates on the status of the project, linking to new articles discussing twinBASIC, and generally trying to increase engagement with the project.  If you come across items that should be included here, tweet me @NoLongerSet or email me at mike at nolongerset dot com.


Highlights

It doesn't happen often, but it appears a full week passed without a new release of twinBASIC.  Perhaps there is a good reason for that...

"...I'm a little busy finalizing the GUI framework at the minute."
 - Wayne Phillips (September 14, 2021)

Around the Web

Block scoping

Andrew Mansell opened a discussion on the possibility of Block Scoping in twinBASIC.

Consider the following piece of code:

Option Explicit

Sub Test()

    If True Then
        Dim x As String ' Is this block scoped, or procedure scoped?
        x = "Hello, World!"
    End If
    MsgBox(x) ' We find out here
End Sub

In VBx, this will show "Hello, World!". In VB.Net, it will refuse to compile as x is not defined in the same scope as the call to MsgBox.

From there, the discussion expanded to include:

  • possible block-scoping syntax
  • local functions
  • anonymous functions
  • type inference

It's a fascinating discussion about language features, even if none of the discussed features end up making it into twinBASIC.

Planned ObjRefCount() function

As you may know, VBA/VB6 use reference counting to keep track of objects and release memory when no longer needed.  The language manages the reference counting internally.  You don't even need to explicitly release objects by setting them to Nothing; an object's reference count automatically decreases whenever a referencing object variable goes out of scope.  As long as you avoid circular references, things should run smoothly.  

However, there are some situations where you may intentionally create circular references.  In those cases, you need to be intentional about explicitly releasing objects (Set MyObj = Nothing) to avoid leaking memory.  

In such situations, a function that returns the current reference count for an object would be very handy for debugging purposes.  It sounds like such a function is in the works for twinBASIC.

Changelog

Here are the updates from the past week.  You can also find this information by installing the twinBASIC VS Code extension and clicking on the Changelog tab of the extension page:

Nothing to see here this week!

All original code samples by Mike Wolfe are licensed under CC BY 4.0