-
6
- #1
Mike Lewis
Programmer
When posting messages in the forum, it is very common to include snippets of program code - see example, below. (Note: the actual code I'm showing here is not important. The point I want to make concerns the appearance of the code. I chose this snippet at random from another thread, and no criticism is intended of the code itself or the person who originally posted it.)
Define Class TimeTimer as Timer
Interval=1000 && every second
oLabel = .null.
Procedure Init()
_screen.AddObject('lblTime','Label')
This.oLabel = _screen.lblTime
This.oLabel.Visible = .f.
ENDPROC
Procedure Timer()
SELECT pendlog
DO WHILE .t.
IF RECCOUNT("pendlog") = 0
loop
ELSE
exit
ENDIF
ENDDO
GO top
DO WHILE !EOF()
IF ALLTRIM(UPPER(pendlog.status)) = "PENDING"
REPLACE STATUS WITH "Transferred"
IF pendlog.nctr = 5
CLOSE DATABASES
RELEASE ALL
ENDIF
ENDIF
SKIP
ENDDO
Endproc
Enddefine
This is fine as far as it goes. But, clearly, the snippet would look much better if it was nicely formatted, like this:
There are some obvious advantages to this:
1. The code stands out from the surrounding text. It is easy to see where it starts and ends.
2. The code is rendered in a mono-spaced font. This makes it easy to see small characters, such as dots and commas.
3. Most importantly, the indentation is preserved. Indentation is one of the most useful tools for seeing at a glance the structure of a program.
How to do it
The easiest way to apply this formatting is to highlight the block of code, and then click on the "Code" button in the toolbar (at the top of the edit window). This button is in the right-hand half of the toolbar, between "Quote" and "Spoiler". You will be prompted to specify the code's language, which you can just leave blank.
An alternative method is to type the tag [ignore]
[/ignore] at the end.
Of course, many of us already format our code in this way. If you don't, please consider doing so - for the reasons stated above.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
Define Class TimeTimer as Timer
Interval=1000 && every second
oLabel = .null.
Procedure Init()
_screen.AddObject('lblTime','Label')
This.oLabel = _screen.lblTime
This.oLabel.Visible = .f.
ENDPROC
Procedure Timer()
SELECT pendlog
DO WHILE .t.
IF RECCOUNT("pendlog") = 0
loop
ELSE
exit
ENDIF
ENDDO
GO top
DO WHILE !EOF()
IF ALLTRIM(UPPER(pendlog.status)) = "PENDING"
REPLACE STATUS WITH "Transferred"
IF pendlog.nctr = 5
CLOSE DATABASES
RELEASE ALL
ENDIF
ENDIF
SKIP
ENDDO
Endproc
Enddefine
This is fine as far as it goes. But, clearly, the snippet would look much better if it was nicely formatted, like this:
Code:
DEFINE CLASS TimeTimer AS TIMER
INTERVAL=1000 && every second
oLabel = .NULL.
PROCEDURE INIT()
_SCREEN.ADDOBJECT('lblTime','Label')
THIS.oLabel = _SCREEN.lblTime
THIS.oLabel.VISIBLE = .F.
ENDPROC
PROCEDURE TIMER()
SELECT pendlog
DO WHILE .T.
IF RECCOUNT("pendlog") = 0
LOOP
ELSE
EXIT
ENDIF
ENDDO
GO TOP
DO WHILE !EOF()
IF ALLTRIM(UPPER(pendlog.STATUS)) = "PENDING"
REPLACE STATUS WITH "Transferred"
IF pendlog.nctr = 5
CLOSE DATABASES
RELEASE ALL
ENDIF
ENDIF
SKIP
ENDDO
ENDPROC
ENDDEFINE
There are some obvious advantages to this:
1. The code stands out from the surrounding text. It is easy to see where it starts and ends.
2. The code is rendered in a mono-spaced font. This makes it easy to see small characters, such as dots and commas.
3. Most importantly, the indentation is preserved. Indentation is one of the most useful tools for seeing at a glance the structure of a program.
How to do it
The easiest way to apply this formatting is to highlight the block of code, and then click on the "Code" button in the toolbar (at the top of the edit window). This button is in the right-hand half of the toolbar, between "Quote" and "Spoiler". You will be prompted to specify the code's language, which you can just leave blank.
An alternative method is to type the tag [ignore]
Code:
[/ignore] at the start of the code, and [ignore]
Of course, many of us already format our code in this way. If you don't, please consider doing so - for the reasons stated above.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads