Visual Studio Power Tools

If you’re a fan of tools like I am then you’ll appreciate the wonder of the Visual Studio 2010 Productivity Power Tools! They’ve been out for a while but I just got around to installing them. So far I’m loving:

  1. HTML Copy. Now when I copy code from Visual Studio into other applications (like OneNote) the syntax coloring is preserved! Yippee!!
  2. Column Guides. I have mine set at 120 since that’s the recommended line length on my current team. Great to have a visual indicator of this! Just move the cursor to column 120, right click –> Guidelines –> Add Guideline and it’s there.
  3. CTRL+Click to go to definition.

How Ultrabooks Will Restore Traditional PC Dominance

The “Post PC” revolution is on the tip of every pundit’s tongue these days. So I’ve been thinking about how PCs can reclaim some of their former glory. Here’s a quick list of what I’ve come up with so far:

  1. Put every low-cost sensor into every ultraportable pc. Ambient light sensors, accelerometers, GPS, thermometers, barometers, front and rear-facing webcams, etc… The PC needs to be able to accept any input that a smartphone can accept and then some.
    1. With options for more sensitive/higher resolution versions of each of these sensors.
  2. Touch, touch, touch. Windows 8 will help in a big way. It should be easier to find a mobile PC with a floppy drive than it is to find a mobile PC WITHOUT touchscreen support.
  3. Cellular connectivity in addition to WiFi and Bluetooth. Ultrabooks should be able to use voice (GSM and CDMA) and data (3G, 4G) connections from the top US-based carriers without anything dongles sticking out of the chassis. I should be able to go to AT&T, Verizon or T-mobile, pick up a SIM card, pop it into my laptop and be instantly connected. Or pay $25 and have it installed.
    1. With options for supporting top international carrier standards.

The PC’s strong point has always been its general purpose nature. Smartphones and tablets are currently able to do things that cannot be done easily on a PC (e.g., an always one cellular data connection, GPS, etc…). Making these items standard would go a long way towards bridging that gap.

What do you think traditional PCs can do to reassert their dominance over the home computing landscape?

Environment Variables in FOR loops

Let’s say you want to run a program multiple times. The output of each execution should be stored in a separate file to allow for easy comparison. The output filename has useful information so it would be nice to simply append a counter to indicate which run a given output file is associated with. In other words run 1 produces output-1, run 2 produces output-2, …, run N produces output-N.

If you’ve ever tried this using .bat files on windows you might have come up with something along the lines of the following:

@echo off
set f=%1

for /l %%i in (1,1,5) do (
set nf=%f%-%%i

if not exist %nf% (
echo %nf% does not exist
) else (
echo %nf% does exist
)
)


Which surprisingly produces output along the lines of output-5, output-5, output-5, ….



By default the command interpreter CMD only evaluates environment variables (nf in this case) once. To evaluate environment variables more than once it is necessary to enable “delayed environment variable expansion".



This can be enabled when the CMD is started with /v:on. (e.g., cmd /v:on). Alternatively, it can be enabled via setlocal enabledelayedexpansion in an already running CMD prompt.



However, %nf% must replaced with !nf! to get the value of the variable based on the current iteration of the enclosing FOR loop.



So the corrected code is:



@echo off
set f=%1

setlocal enabledelayedexpansion

for /l %%i in (1,1,5) do (
REM set nf=!f!-%%i
set nf=%f%-%%i

if not exist !nf! (
echo !nf! does not exist
) else (
echo !nf! does exist
)
)

endlocal