Re: Trailing blanks in batch file



Interesting comments, see my responses in-line...

"Alexander Suhovey" <asuhovey@xxxxxxxxx> wrote in message
news:C7BBE70E-41D5-4D4E-A696-9620955B8A56@xxxxxxxxxxxxxxxx
"Al Dunbar [MS-MVP]" <alan-no-drub-spam@xxxxxxxxxxx> wrote in message
news:ekYwgEGPHHA.3668@xxxxxxxxxxxxxxxxxxxxxxx
Hey, it's so ugly it will probably remain a single character for the
rest
of
its life!

Haha, that was a good one! Love it!

I can't seem to buy a good straight line these days, so when one comes along
for free, I go for it!

set DAY=%%a&rem :: DO NOT add whitespace between the "%%a" and the "&"

Same applies to parentheses and quotes, isnt it? :-)

Yes and no. Yes, the prevention of a trailing blank isn't the primary reason
for them, but no: the parentheses and quotes at least surround the command
they are there to protect, whereas the ampersand simply follows it, a fact
that I contend makes its meaning at least somewhat less obvious. Also, the
quotes are normally understood to differentiate what is in a string from
what is not in a string, and the parenthesis' function is to group one or
more commands, thereby similarly differentiating what is in the command(s)
from what is not. If what is not happens to be a space, well that is still
simply these things doing their normal function, when this poor
(non-existent) space is given short shrift.

We could argue endlessly, or we could do a test with a hundred batch
programmers and ask them to modify this script to make it more readable, but
still yielding the same result:

set DAY=%%1&(set TIME=%%2)

I bet that the "&" would either be replaced with an endline character or
preceded and followed with a blank MORE often than would the final ")" be
preceded by a blank.

In my mind, then, it is not really which method is most aligned with the
original intent of the feature as I initially suggested, but which will
result in a more intuitive understanding of what it is doing in this
context.

The problem here is not
somebody putting extra trailing spaces by accident, it's some text editors
that can automatically do that for whatever reason they have.

That may indeed be the cause of the majority of cases, however, I see the
problem as there *being* a trailing space whose presence creates a problem.
And that problem is further exascerbated by the difficulty of knowing the
blank is there when it is followed by more whitespace in the form of an
endline character.

If someone exclusively used an editor that displayed blanks as grey dots,
then it might be less important for them to do this (unless, of course, this
is one of the editors that indiscriminately pads lines with blanks), but one
can never be sure that one's script will never be edited by someone else
with a different editor.

Also, you
probably know that some forum engines have this problem too: when you post
a
code snipplet using [code][/code] tags, every line inside gets an extra
trailing space which can very well result in broken batch code if you
copy-paste it to your text editor.

Which is one reason for the many posts over the years recommending the
explicit use of parentheses, or, sometimes, double-quotes.

but both are bad because the main function of "&" is to separate two
commands on a line, not terminate one, something it does incidentally.

Sure, but I don't see how it's that bad other than it looks ugly. There
are
other things in batch scripting that weren't meant to be used in the way
they are used by scripters today.

I agree, like 80%! Ugliness alone may not be a bad thing; ugliness that
interferes with one's ability to detect subtle nuances about what is really
going on in a script, now *that* is a bad thing.

Like "set /p" command which purpose is to provide interactive user input
facility but somebody figured it also can be used to append the output
text
to the same line.

Or ping as a way to add pauses to the script.

@echo off
set /p foo="Working ..."<nul
for /l %%i in (1,1,40) do (
ping -n 1 127.0.0.1>nul 2>&1
set /p foo="."<nul
)
echo Done.

Sure, I use those techniques, and more... That is because the side effects
in question are sometimes almost important as the obvious intent of such a
feature, and the side effect is not really available otherwise without
writing an executable to do it. But, ideally, one should never use code for
its side effects unless the meaning is documented, or at least in general
use in the batch scripting community.

/Al


.



Relevant Pages

  • Re: Writing and debugging VBS
    ... rem that out temporarily then re-run your script and see what ... > Editor in Excel or Word, in the hope that the editor would step through ... > screen changed for a few seconds, before reverting to the design mode. ... > (in a similar way to the VBA editor) to step through my VBS code? ...
    (microsoft.public.scripting.vbscript)
  • Re: [PATCH] Speed up "make headers_*"
    ... 'use strict' and 'use warnings' is recommended. ... The parentheses are not needed for most of the built-in functions. ... More or less the same comments would apply to the next script as well. ...
    (Linux-Kernel)
  • Re: JScript syntax higlihting in VIntDev
    ... :: JScript files and highlighted the syntax. ... select the HTML Editor and set the editor to come up in Source View. ... Document to link script ... : function doThis() { ...
    (microsoft.public.scripting.jscript)
  • Re: looking for a decent IDE for VBScripting
    ... script editor" is serviceable. ... IDE sounds a little off-base to me, ... a text editor and a "run" ... I would like to suggest the scintilla ...
    (microsoft.public.scripting.vbscript)
  • Re: Cannot Set Word As HTML Editor For IE6??
    ... that the path you gave it is correct for your installation? ... Alan Edwards, MS MVP W95/98 Systems ... >option for my HTML editor. ... >way it was before I ran the script. ...
    (microsoft.public.windows.inetexplorer.ie6.setup)

Quantcast