Monday, September 24, 2007

More on modularity

Run BASIC gives you the ability to create web pages that are component based. You define your own components and the ease at which you can plug these things together comes essentially for free. Here is a really simple example that I posted in our beta testing forum:

[masterPage]
cls
html "Program manager"
link #wiki, "Wiki", [runTheWiki]
print " ";
link #multi, "Multicounter", [runTheMulticounter]
print
if launchFlag then render #subProg
wait

[runTheWiki]
run "runWiki", #subProg
launchFlag = 1
goto [masterPage]

[runTheMulticounter]
run "multicounter", #subProg
launchFlag = 1
goto [masterPage]

Here is a version that doesn't use any GOTOs:

global launchFlag
call displayMasterPage
wait

sub displayMasterPage
cls
html "Program manager"
link #wiki, "Wiki", runSubprogram
#wiki setkey("runWiki")
print " ";
link #multi, "Multicounter", runSubprogram
#multi setkey("multicounter")
print
if launchFlag then render #subProg
end sub

sub runSubprogram linkKey$
run linkKey$, #subProg
launchFlag = 1
call displayMasterPage
end sub

So what does this do? It creates a simple web page with a title and two links. Click on the wiki link and the wiki program becomes part of the web page. Click on the multicounter link and the multicounter replaces the wiki part of the page. You can switch back and forth between the wiki and the multicounter at will with just the click of a mouse. What's even more interesting is that the multicounter is already a modular program, so you get three levels of modularity but you aren't limited to that.

So for programmers who like to put all their code in one file, there's nothing to prevent that. But people who like modules can have a field day.

No comments: