Write clear McBasic™
Use explicit types, small procedures and predictable control flow before adding framework APIs.
Declare the values you mean#
Start new source files with Option Explicit. Use String for text, Boolean for decisions, a suitable numeric type for calculations and the documented object type for runtime services. A caption is presentation text, not the place to store a database identity.
Option Explicit
Public Function Greeting(ByVal name As String) As String
Dim clean As String
clean = Trim$(name)
If Len(clean) = 0 Then
Greeting = "Enter a name."
Exit Function
End If
Greeting = "Hello, " & clean
End FunctionKeep the contract small#
Use a Sub for an action and a Function for a returned value. Assign the function name to return a value. ByVal is the safer default when a procedure should not mutate its caller’s variable; use ByRef deliberately when mutation is the contract. Public members form an API; Private members are implementation details.
Optional parameters and ParamArray belong in a documented API with clear defaults. Do not assume a Visual Basic or VBA function with the same name has the same supported overloads: consult the compiler-owned intrinsic signatures.
Write control flow that is easy to test#
Use If/Else for decisions, Select Case for a set of alternatives and the supported loop forms for repetition. Keep an early guard near the top of an event when input is missing. Test the branch that does no work as carefully as the normal branch.
A loop over an array should use its declared bounds. A Collection uses one-based positions. JSON arrays use zero-based positions. Those are different contracts, not interchangeable conventions.
Choose conversions deliberately#
CStr formats a value as text; it does not validate arbitrary user input for a business rule. Check whether input is acceptable before converting it, and handle overflow as a failure. Currency and Decimal are useful when your calculation requires decimal behavior; floating-point types have different precision characteristics.
Separate shared code from instance state#
A standard module holds shared procedures. A class gives each instance its own fields and public members. Use Set for object assignment, test Is Nothing before using an optional object and use Is for identity. With captures its receiver at block entry, so reassigning the variable later does not retarget the existing block.
Work through the language workbench for declarations, loops, arrays, collections, a class, errors and tests. The With lesson makes receiver identity visible.
Learn the implemented language#
McBasic™ is its own implementation, not a promise to run every historical BASIC program unchanged. Check the supported signatures and compile a small case when porting code. A diagnosed unsupported construct should be redesigned using supported behavior rather than concealed with an unrelated cast.
20f4bfed6b · Build manifest