One of the things that I picked up a few years ago was to be generous with your comments. Not only for yourself, but also for anyone else who'll review your code. I would typically only insert a comment at the beginning of the file to describe what the primary function of the batch file is for, and some of the functions, just to explain what's going to happen, or what's going on. As far as indentation, typically should indent things such as an IF or FOR. Here's a quick example.
:: Check username of currently logged in user.
@ECHO OFF
:: Declare variables
SET Something=abc
SET SomethingElse=def
SET FinalNumber=20
:: Start of batch file
:GetUsername
:: Get username of currently logged in user, and output to file
CLS
ECHO %USERNAME%>Test.txt
:CheckAdmin
:: Check if username = Admin, Echo numbers in a FOR loop
CLS
IF "%USERNAME%" EQU "Admin" (
ECHO Admin is currently logged in
ECHO Printing numbers 0-%FinalNumber%
FOR /L %%I IN (0,1,%FinalNumber%) DO (
ECHO %%I
ECHO %%I>>Test.txt
)
) ELSE (
ECHO Admin is not logged in
ECHO Printing numbers %FinalNumber%-0
FOR /L %%I IN (%FinalNumber%,-1,0) DO (
ECHO %%I
ECHO %%I>>Test.txt
)
)
:: Wait 5 seconds, than loop through again, because why not?
ECHO %Something%
ECHO %SomethingElse%
TIMEOUT>NUL /T 5
GOTO :GetUsername
While I'm no "Expert", hopefully this helps clear up a few things for you. As you can see, I prefer to use ::
versus REM
for comments, and I also set labels :GetUsername
on the various functions. Some will say this is right, this is wrong, I feel just go with what you're comfortable with.