I learned to code in OO languages. I've always been interested in design patterns, clean code, etc., etc. - you know the type.
Now at work I'm using a BASIC dialect. Given modern programming values, should we try to carry over these same principles to new procedural code?
I'm pondering the following issues, and I wondering if I'm on the right lines.
Variable Names
Variables are not strongly typed (nightmare!), they're given short names and written in ALL CAPS (why?!) - basically I find them hard to read and they could be anything. Once upon a time, I'm sure XCNT = 1
would have offered performance gains over int_EXISTINGCUSTOMERCOUNT = 1
, but we're past that now - surely? I choose the verbose name here.
GOSUB
I want to break down long blocks of code down into multiple smaller blocks. Internally, GOSUB
is used (over a FUNCTION
) if the helper is not re-usable by other programs / functions. Given its ability to add / modify variables without the safety of scoping (as we know it in the OO world) GOSUB
scares me.
This is typical:
GOSUB GET_BEST_CUSTOMER
IF RC = 0 THEN CRT CNAME
But I would write:
rc_GETBESTCUSTOMER = 1 ; !Default exception
str_CUSTOMERNAME = ""
GOSUB GET_BEST_CUSTOMER ; !set rc_GETBESTCUSTOMER, populate str_CUSTOMERNAME
IF(rc_GETBESTCUSTOMER = 0) THEN
CRT str_CUSTOMERNAME
END
With the caveat that GET_BEST_CUSTOMER
would only modify rc_GETBESTCUSTOMER
and str_CUSTOMERNAME
in 'global' scope.
There's more, but it's all along the same lines. Given the editor of choice (Notepad++), I'd say my coding style makes the code easier to read and understand - therefore easier to maintain. But I'm sure some BASIC die-hard would readily tell me I'm doing it all wrong.