en
Program code should profit from readable typography and be as well-structured as any literary text. Indentation is a readability issue.
In 1977 I was at a computer conference where a group from Italy presented their ideas of editing and compiling program code by indentation. This eliminated completely the ugly end (and in the case of Pascal there is an ugly begin too!).
The idea of the Italian group was simple:
when you look vertically down from the first letter of a statement, you should find the first letter of the following statement or the alternative.
They had no need of opening or closing brackets or begin-end pairs.
In LiveCode there is no control over indentation: the editor does it for you, with no possible options. On the whole I can live with what the LiveCode editor does, but it could be better.
As an example, here is what two routines of mine would look like if LiveCode used the idea of the Italians. You will note that the next statement is always found just by dropping down and there is no need for end.
on RecurseOverFolders fFolderPath,fFileHandler,fFolderHandler,fCaller
-- fFolderPath is the path to the folder we want to recurse over,
-- fFileHandler is the handler to call for each file, with the file path as argument
-- fFolderHandler is the handler to call for each folder, with the folder path as argument
-- fCaller is the name of the object where the call-back handlers are located.
put the defaultfolder into lDefaultFolder
if there is a folder fFolderPath then
put fFolderPath into lRootFolder
set the defaultfolder to lRootFolder
put 1 into lFolderDepth
RecurseOverFoldersDoFolders lRootFolder,lFolderDepth,fFileHandler,fFolderHandler,fCaller
else
answer "No such folder..."
set the defaultfolder to lDefaultFolder
on RecurseOverFoldersDoFolders fFolderPath,fFolderDepth,fFileHandler,fFolderHandler,fCaller
-- get the alphabetical mixed list of files and folders:
put empty into lItems
FolderItems fFolderPath,lItems
put the keys of lItems into lItemKeys
put (the number of lines of lItemKeys)/2 into nItems
-- lItems[i,1] is either "f" for a file, or "d" for a directory (folder)
-- lItems[i,2] is the name of the item
repeat with iItem=1 to nItems
if lItems[iItem,1] = "f" then
put fFileHandler&space"e&fFolderPath&(lItems[iItem,2])"e&","&fFolderDepth into lCall
send lCall to fCaller
else
put fFolderHandler&space"e&fFolderPath&(lItems[iItem,2])&"/""e&","&fFolderDepth into lCall
send lCall to fCaller
RecurseOverFoldersDoFolders fFolderPath&(lItems[iItem,2])&"/",fFolderDepth+1,fFileHandler,fFolderHandler,fCaller
The handler FolderItems is not given here.
Note that the second routine is only called from within the first, and it would therefore be useful to put it inside the first (see procedure nesting). That saves on parameter passing, makes the names shorter, and therefore makes it all clearer:
(Impossible to do at present, but would be good:)
on RecurseOverFolders fFolderPath,fFileHandler,fFolderHandler,fCaller
-- fFolderPath is the path to the folder we want to recurse over,
-- fFileHandler is the handler to call for each file, with the file path as argument
-- fFolderHandler is the handler to call for each folder, with the folder path as argument
-- fCaller is the name of the object where the call-back handlers are located.
local lRootFolder,lFolderDepth
on DoFolders fFolderPath,fFolderDepth
-- get the alphabetical mixed list of files and folders:
put empty into lItems FolderItems fFolderPath,lItems
put the keys of lItems into lItemKeys;
put (the number of lines of lItemKeys)/2 into nItems
-- lItems[i,1] is either "f" for a file, or "d" for a directory (folder)
-- lItems[i,2] is the name of the item
repeat with iItem=1 to nItems
if lItems[iItem,1] = "f" then
put fFileHandler&space"e&fFolderPath&(lItems[iItem,2])"e&","&fFolderDepth into lCall
send lCall to fCaller
else
put fFolderHandler&space"e&fFolderPath&(lItems[iItem,2])&"/""e&","&fFolderDepth into lCall
send lCall to fCaller
DoFolders fFolderPath&(lItems[iItem,2])&"/",fFolderDepth+1
put the defaultfolder into lDefaultFolder
if there is a folder fFolderPath then
put fFolderPath into lRootFolder
set the defaultfolder to lRootFolder
put 1 into lFolderDepth
DoFolders lRootFolder,lFolderDepth
else
answer "No such folder..."
set the defaultfolder to lDefaultFolder
Now go look at some typical C or C++ code, or worse, Javascript. Observe the large number of "{" and "}", the immense space wasted in a frantic attempt to make the code "clear". To me all these "{" and "}" look more like dust on the page than aids to understanding the code.