trailing spaces in code snips - pls neutralize with prejudic

May 28, 2013 at 21:39:15
Specs: Windows Xp klunker, various (16+ computers)
Hey, Justin, since you're basking in the spotlight (ha ha!) While you're at it, could you-all clip all trailing spaces from posts? There is absolutely no reason to retain them, that I can think of, but many people "cut/paste" from posts and pick up garbage spaces (mostly applicable to batch, but...). I try to "rtrim" my posts, but maybe I forget. I posted this instead of PM so other people could comment yea or nay. Just now had to deal with this, but it's happened in the past also.

See More: trailing spaces in code snips - pls neutralize with prejudic

Report •

#1
May 28, 2013 at 23:20:06
Yes Justin and after you've removed all the superfluous spaces from every posting you should box them up and donate them to charity. RME (Rolling my eyes)

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

#2
May 29, 2013 at 06:52:38
nbrane,

This isn't that difficult to do, but it may have some unintended consequences (for example, making it impossible to put any trailing spaces in postings). Is this something you see a lot? Can you give me a few examples of it messing up postings that you've seen recently?

Thanks,
Justin


Report •

#3
May 29, 2013 at 14:31:27
Yeah an example would be nice. It seems kind of 'nit-picky' to be bothered by a few extra spaces in a posting unless it's really blatant.

The only thing I've noticed is some posters seem to be using a text editor without word wrap causing their responses to not make an exact fit when pasted to the computing.net reply box. But it's never bothered me.

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

Related Solutions

#4
May 29, 2013 at 21:08:16
@dave: note I said "RTRIM", not "ALLTRIM". I just wish the ends of the lines would be the ends of the lines, and not just appear to be.
Here's the post in question:
http://www.computing.net/answers/pr...
(I pmailed the OP with the reason the compares were failing. He, or I, had unintentionally left spaces trailing the ends of the lines.)
Anyway, not a big issue, just a suggestion. It really only applys to batch, that I know of.
ps:
"(for example, making it impossible to put any trailing spaces in postings)." Isn't that what
this                      
is for?
And, to counter your challenge, please explain what possible value trailing spaces on any line of code (or text) can have? Unless it's some obscure word-wrap issue that I'm clueless about. I'm not trying to be "nit-picky", just making a suggestion to help keep these kinds of problems from recurring.
pps: just remembered, we worked on this problem via pmail, so here's the exchange:
(PM from OP):
Here is the the exact code that I'm using to test the batch script that you have been helping with.

set tlimit=__________9900
pushd "C:\Users\Scott\Desktop\Recorded TV\XML\"
for %%a in (*.xml) do (
for /f "tokens=*" %%z in ('cscript TimeDiff.vbs "%%~ta" "%date:~4% %time:~0,8%"') do (
rem echo file: %%a, age in seconds: [%%z]
set f=%%z
:: just using 14 for now.
set f=!f:~-14!
echo file: %%a age in seconds: [!f!]
if "!f!" lss "%tlimit%" (
echo **** [%%z] [%tlimit%] %%a to be processed...
del "C:\Users\Scott\Desktop\Recorded TV\%%~na.log"
del "C:\Users\Scott\Desktop\Recorded TV\%%~na.txt"
move "C:\Users\Scott\Desktop\Recorded TV\%%~na.wtv" "C:\Users\Scott\Desktop\Analyzed"
move "C:\Users\Scott\Desktop\Recorded TV\%%~na.edl" "C:\Users\Scott\Desktop\Analyzed"
move "C:\Users\Scott\Desktop\Recorded TV\XML\%%a" "C:\Users\Scott\Desktop\Analyzed"
)
)
)


(my reply:)
I believe it is trailing spaces, specifically in lines 6 and 8:

0) @echo off & setlocal enabledelayedexpansion
1) set tlimit=__________9900
2) pushd "C:\Users\Scott\Desktop\Recorded TV\XML\"
3) for %%a in (*.xml) do (
4) for /f "tokens=*" %%z in ('cscript TimeDiff.vbs "%%~ta" "%date:~4% %1) time:~0,8%"') do (
5) rem echo file: %%a, age in seconds: [%%z]
6) set f=%%z
7) :: just using 14 for now.
8) set f=!f:~-14!
echo file: %%a age in seconds: [!f!]


Make SURE there are no spaces at the ends of those two lines. This was neither of our faults, blame it on the forum, i guess. I'm going to make a suggestion to Justin to see if they can "right-trim" all posts. There is no possible way that a post needs trailing spaces. This has happened before.
Let me know if this helps.

end of exchange
he was trying to compare two numeric values, but one value had the trailing spaces, and the other did not, so the IF compare was failing every time. Alright, I'm done.


Report •

#5
May 29, 2013 at 22:59:13
I see what you mean. I was thinking about pure text responses and not programming lines.

Maybe it would be helpful to have an 'end of line' character for text responses that the user would understand needed to be removed if he pasted the solution into his own work. That way if he also copied and pasted trailing spaces the EOL character would show where the line was supposed to end and the user could delete anything after that.

A Start of Line character might be helpful too if there was any additional confusion. As long as the user understood the characters weren't part of the program, how they were used and needed to be removed before running it I think it would work.

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

#6
May 29, 2013 at 23:25:50
Yeh, that would work, if posters were aware of it. That's my concern, that most posters (especially in batch) are just not ready for that degree of discretion. Anyway, I'm not "ranting", just giving food for thought. Some kind of EOL marker would be good if it were understood, it's the understanding/interp that might foul that gear. Justin said that an "RTRIM" op would not be too difficult. Anyway, just thought I'd give some "front-line" reports.

Report •

#7
May 30, 2013 at 00:25:35
If something like that was done the specifics would have to be stated on the Programming forum page, maybe more than once. But I suppose some people would still miss that and then wonder why the program isn't working for them. Well, that's something contributors to that forum can work out.

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

#8
May 30, 2013 at 06:59:03
nbrane,

I misunderstood you, I thought you meant trim all what spaces at the very end of every posting, not at the end of each line.

What you are suggesting could still be done. However, it would be more difficult. Also, I can envision even more unintended consequences... anytime you start playing around with postings that users make, strange things can happen.

I think it would be better to try to understand how those spaces get there and maybe address that. If the user is inserting a trailing space himself into the textbox, then it needs to be reflected, as that is his problem. I could envision someone saying, "Why does this code not work" when us removing trailing spaces from the original he pastes fixes it. If, through copying and pasting it into the textbox, a trailing space is added, then we need to figure out why.

Justin


Report •

#9
May 30, 2013 at 18:22:52
I agree Justin, if we can figure out where they're creeping in, then they can be dealt with some other way. It might have to do with the auto-word-wrap. I don't type in a space at the end of any line that I'm aware of. (I used to use "hard returns" when I first started, now I just let the junk wrap itself silly.) I'll just shut up and try to see what's going on. If I learn something, I'll of course let you know.
ps: reviewed your last post, and I understand it better: by removing the offensive trailing spaces, the problem is solved, but without really getting to the root of it. What would be really sweet would be some kind of indicator, such as slight foreground/background shading adjustment that would show the trailing spaces, sort of along the lines of what Dave said, but passive and not active. But I know those kinds of fine-tuning can be more trouble than they're worth because half the time they don't work anyway. ttyl
Ttyl

Report •

#10
May 30, 2013 at 19:19:05
nbrane,

Yeah, lets keep thinking on it. If and when you see where they are sneaking in, let me know!

Justin


Report •

#11
June 5, 2013 at 09:47:19
Trailing whitespace is trivial IMO and is trivial to fix. All it takes is a simple regex. If done correctly, that's 1 line of code.

There are bigger fish to fry. I find the lack of "code tags" which would not only retain the formatting much like the pre tags, but also encapsulate the code in its own scrolling box. This is a very common feature in all other forums that I work with. Another missing feature is the quote tags to allow us to cleanly quote portions of prior comments.

Since this thread was kicked off due to a perceived issue with posting batch code, I must ask why the authors of the posted code don't make use of the pre tags. And even when they do, why the lack of proper whitespace (indentation and line breaks)?


Report •

#12
June 5, 2013 at 14:25:44
I think what you mean by "Another missing feature is the quote tags to allow us to cleanly quote portions of prior comments" was discussed briefly in this thread a few years ago:

http://www.computing.net/answers/th...

starting at about post # 145. I hope that was enough to disuage Justin from including that irritating, unnecessary feature. After all it's so easy to just do a copy and paste and enclose that in quotes if you want to include a comment from a previous posting--like I did with your sentence above.

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

#13
June 5, 2013 at 17:30:42
I'm not suggesting nor advocating using the quote tags to quote entire posts like is typically done in email threads, which is what the logic of your rebuttal suggests. That would be absurd.

The usage of the quote tags I suggest is just as valid as using the current selection of tags. The advantage of the quote tags would be 1) it could/would clearly indicate who you're quoting, which is helpful when there are multiple users posting especially in longer threads, 2) it separates the quote from your response by a physical separation and/or uses a different font, which IMO adds clarity/readability.

Since you didn't rebut my suggestion of the code tags, I assume that you agree with me on that point.


Report •

#14
June 5, 2013 at 19:41:30
I have no opinion on code tags. As I mentioned above, that's for the programming forum contributors to work out. The last real programming I did was FORTRAN and BASIC. Not much call for that anymore.

As far as quote tags, the problem is that having that feature encourages people to use it--almost always unnecessarily. Post after post after post contains the same:

>>hey look
>>this is being echoed for the 37th time in this thread!!!
>>Yipee!!!

It doesn't help to distinguish who you're quoting as the reader will still need to scroll up to refresh their memory. If separating the quote from the response is necessary well, just hit ENTER once or twice.

And using different fonts for clarity?

We already have that!

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

#15
June 5, 2013 at 20:53:11
"As far as quote tags, the problem is that having that feature encourages people to use it--almost always unnecessarily."

If that's true, then the same absurd claim could be made of the pre tag, and the bold tag, and the italics tag, which I've never seen to be used "almost always unnecessarily". And your "post after post" example is absurd.

"It [the quote tag] doesn't help to distinguish who you're quoting as the reader"

I must assume you don't work with very many forums. Most of the ones I work with have a quote tag that can include as part of its quote header/caption the user that you're quoting. That simple capability must beyond the capabilities of this forum software and outside of your experience.

Regarding the fonts, you manually need to add those tags rather than having the quote tags set a default font that is changeable and so far I haven't found any documentation on this site indicating the available formatting options. That type of info should be easily and clearly available, which it isn't.

Having or not having the quote tag is a minor issue, but it's one example where IMO, this site falls short compared to others that I use.


Report •

#16
June 5, 2013 at 21:02:09
An example of a site that has better quality and ease of use of formatting options is: forums.devshed.com

Report •

#17
June 5, 2013 at 22:08:59
Yeah I don't work with very many forums. I have, you know, a life. But I have been here awhile and while searching for solutions I've come across a lot of incessantly repetitive quoting on other sites. Sorry I can't provide examples but I never kept track of them. But I'll probably come across some before this thread is closed.

Note that you had no problem quoting me in a way that anyone reading it will understand and not find confusing, even with the stone-age techniques you were forced to use.

They're always making changes here and I suppose it'd be OK if it was easier to swap fonts and the like. It seems unnecessary but I guess there are people who are bothered by any online activity that takes more than a single mouse click. But no echoing/quote tags.

DAVEINCAPS - Made with REAL high fructose corn syrup.


Report •

Ask Question