Geeks With Blogs
Johnny Kauffman Deriding bad software so you don't have to!

Johnny, the Endangered Keyboard-Driven Windows User

Some of my proudest, obscure Windows tricks are losing their relevance. I know I’m not alone.

Keyboard shortcuts are going the way of the dodo. I used to induce fearful awe by slapping Ctrl+Shift+Esc in front of the lowly, pedestrian Windows users. No windows key on the keyboard? No problem: Ctrl+Esc. No menu key on the keyboard: Shift+F10. I am also firmly planted in the habit of closing windows with the Alt+Space menu (Alt+Space, C); and I harbor a brooding, slow-growing list of programs that fail to support this correctly (that means you, Paint.NET).

Every time a new version of windows comes out, the support for some of these minor time-saving habits get pared out. Will I complain publicly? Nope, I know my old ways should be axed to conserve precious design energy. In fact, I disapprove of fierce un-intuitiveness for the sake of alleged productivity. Like vim, for example. If you approach a program after being away for 5 years, having to recall encyclopedic knowledge is a flaw. The RTFM disciples have lost.

Anyway, some of the items in my arsenal of goofy time-saving tricks are still relevant today. I wanted to draw attention to one that’s stood the test of time.

Remember Batch Files?

Yes, it’s true, batch files are fading faster than the world of print. But they're not dead yet.

I still run into some situations where I opt to use batch files. They are still relevant for build processes, or just various development workflow tools. Sure, there’s powershell, but there’s that stupid Set-ExecutionPolicy speed bump standing in your way; can you really spare the time to A) hunt down that setting on all machines affected and/or B) make futile efforts to convince your coworkers/boss that the hassle was worth it?

When possible, I prefer the batch file wild card. And whenever I return to batch files, I end up researching some of the unintuitive aspects such as parameters, quote handling, and ERRORLEVEL. But I never have to remember to use “REM” for comment lines, because there’s a cleaner way to do them!

Double Colon For Eye-Friendly Comments

Here is a very simple batch file, with pretty much minimal content:

@ECHO OFF

SETLOCAL

REM This is a comment

ECHO This batch file doesn’t do much

If you code on a daily basis, this may be more suitable to your eyes:

@ECHO OFF

SETLOCAL

:: This is a comment

ECHO This batch file doesn’t do much

Works great! I imagine I find it preferable due to the similarity to comments in other situations: // or ;  or #

I’ve often make visual pseudo-line breaks in my code, and this colon-based syntax works wonders:

@ECHO OFF

SETLOCAL

:: Do stuff

ECHO Doing Stuff

::::::::::::::::::::::::::::

:: Do more stuff

ECHO This batch file doesn’t do much

Not only is it more readable, but there’s a slight performance benefit. The batch file engine sees this as an invalid line label and immediately reads the following line. Use that fact to your advantage if this trick leads you into heated nerd debate.

Two Pitfalls to Avoid

Be aware of that there are a couple situations where this hack will fail you. It most likely won’t be a problem unless you’re getting really sophisticated with your batch files.

Pitfall #1: Inline comments

@ECHO OFF

SETLOCAL

IF EXIST C:\SomeFile.txt GOTO END ::This will fail

:END

Unfortunately, this fails. You can only have whitespace to the left of your comments.

Pitfall #2: Code Blocks

@ECHO OFF

SETLOCAL

IF EXIST C:\SomeFile.txt (

        :: This will fail

        ECHO HELLO

)

Code blocks, such as if statements and for loops, cannot contain these comments. This is ultimately due to the fact that entire code blocks are processed as a single line.

I originally learned this from Rob van der Woude’s site. He goes into more depth about the behavior of the pitfalls as well, if you are interested in further details.

I hope this trick earns you serious geek rep!

Posted on Thursday, April 12, 2012 9:07 AM | Back to top


Comments on this post: Old School Wizardry Tip: Batch File Comments

# pretty funny Johnny
Requesting Gravatar...
Pretty funny; to paraphrase this article;
"I disapprove of difficult to remember hacks and wasted programming time backwardly supporting and remembering them, BUT here's a good hack."
"Oh and by the way, the hack contains two land-mine exceptions you are likely never to remember till you spend hours debugging code, eventually to learn the problem is your comment method."
So long and thanks for all the fish!
Left by wschloss on Aug 10, 2015 5:10 AM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Batch files are still important for the smooth running of the operating system. For me it sounds like old school stuff but I am confused with the coding part. I usually easy title loans MD prepare it ion a notepad so that it is easy to modify it.
Left by Thomas Greg on Nov 30, 2015 8:35 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Also, there are few more points which corrupt your MS excel data files such software conflict, natural disaster, etc.
192.168.l.l
Left by oftware on Jul 28, 2016 7:39 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Hi there tim
Left by louis on Jan 03, 2017 9:43 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
These tips can be very much helpful to people who are new to computer and hate using mouse the more of any instructions. According to bestessay.org articles a Computer professional must and should know about all the keys in the keyboard and what magic those keys can do in reality. Use shortcuts will help us to save lot of time while working on computer.
Left by kimberly on Jan 04, 2017 12:36 AM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Everyone can get basical tips and methods for interesting methods and useful points always with this review of help4assignment.co.uk site. Thanks for updating and giving us with a lot of better and wonderful points always.
Left by fents on Feb 03, 2017 7:21 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Good post. I’d like to write like this too – taking time and real hard work to make a great article…thanks though.I'm common rail come from sensor .
Left by KOOLSE on Apr 09, 2017 7:54 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Great post with lots of useful information also check https://thewarthunders.com/
Left by mark on May 25, 2017 8:56 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
great tips also check (We are happy to announce the release of Update 1.69 'Regia Aeronautica', which unlocks the Italy as War Thunder's sixth nation, initially offering a formidable .) thewarthunder hacks and cheats
Left by mark on May 25, 2017 8:58 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
wonderful post with well written article also check <a href="https://thewineitems.com/best-wine-openers/> the wine items
Left by Justin on May 25, 2017 9:02 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
wonderful post with well written article also check <a href="https://thewineitems.com/best-wine-openers/> the wine items
Left by Justin on May 25, 2017 9:03 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Just a smile and the rain is gone Can hardly believe it, yeah. There's an angel standing next to me. Reaching for my heart Just a smile and there's no way back .Can hardly believe it, yeah But there's an angel calling me. Reaching for my heart I know that I'll be okay now. This time, it's real I lay my love on you It's all I wanna do Every time I breathe I feel brand new You open up my heart Show me all your love and walk right through As I lay my love on you.
dumb ways to die
fireboy and watergirl 4
Left by chelsie anayas on Jul 16, 2017 3:03 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
It is for the first time I am getting to know about the various shortcuts that can be used. This is a very good piece of information for all the computer users. I think this can make the works far simpler than the usual ways. server rack cabinet
Left by lionel on Aug 01, 2017 10:44 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Bored with white walls? Searching for a way to decorate your area in accredited manner and/or display information about your work? If you operate a business with various services, a custom printed wallpaper may be just the thing that you want to present whatever you offer to a customer and to market your services and products also and <br />
chicago wall decals</p> Il USA!
Left by amadrilo09v on Sep 25, 2017 1:08 AM

# download settings windows 10
Requesting Gravatar...
If User wants to sync settings in windows 10, then
download settings windows 10 you must login through Microsoft account as synchronization totally depends on this process and with the same Microsoft account user can log in your device.
Left by Vivek on Oct 05, 2017 9:50 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
Understanding keyboard short cuts will definitely help you to reduce the time consumed for various activities. I have heard about this batch files before and thank you so much for sharing its importance once again. It was very useful information for the computer operators.Complete Care Health Center Altadena
Left by danette on Oct 26, 2017 11:56 PM

# re: Old School Wizardry Tip: Batch File Comments
Requesting Gravatar...
good post
Left by peter on Dec 07, 2017 10:16 PM

Your comment:
 (will show your gravatar)


Copyright © jkauffman | Powered by: GeeksWithBlogs.net