I like the web.[configuration].config replacement technique that is now available in Visual Studio, and for most files, you can now get this functionality with another plugin called SlowCheetah. However, SlowCheetah can't work with plain old .txt files like robots.txt. If you're like me, you really just need to swap out some robots.txt file that says "index my site" with another that says "don't index, you never saw this staging server". In this case, the solution is simple enough -- Pre-Build Event. Do the follow:

1) Right-click on your project and select "Properties".

2) Select "Build Events". Here is where we are going to add a single magic line.

 

3) Here is where we are going to add a single magic line which copies one of my versions to the root as robots.txt:

copy $(ProjectDir)Content\robots_txt\robots.$(ConfigurationName).txt $(ProjectDir)robots.txt /Y

Note that I am storing my different robots.[ConfigurationName].txt versions in /Content/robots_txt - you can put this anywhere that make sense in your project just change the first argument of copy command.

 

4) That's it! Change your configuration and then build the solution. You should see the different robots.txt file in your solution.

The Programmer Gene

26 Oct 2011 In: Life, Programming, Musings

My wife and I recently did a personal genetic test using 23andMe.com. There was a wealth of information about disease probabilities, family history, and some "trait" information that has been determined by studies that compare certain types of people to other people. Way at the bottom of the traits list was this interesting one: "Avoidance of Errors". From 23andMe.com:

"Learning involves a range of behaviors and skills. These include developing a tendency to prefer rewarded (positively reinforced) choices while avoiding those that are either punished or negatively reinforced. Past studies have shown that the neurotransmitter dopamine is involved in such trial-and-error learning; that means variations in genes related to dopamine signaling may also affect a person's ability to learn."

The German study that found this was able to show that some people's brains reward them when they take paths that avoid errors, while others do not. And, as I know from basic college psychology, when your brain gives you dopamine for certain things, it is actually changing your brain pathways and in turn changing your behavior.

Programmers encounter errors every day, sometimes hundreds of them. In any given day I write some code, complie, look at the error list, fix, compile, fix, and on and on. It doesn't bother me in the slightest that 99 times I see error and one time I see no errors. Contrast that to my wife, who has the error avoidance gene. She works with people, and she manages a clinical research study. Errors with people, and errors with measurement are bad. She should avoid them. Of course errors in code are bad as well, and I strive to release code that is error free and loathe every time a bug ends up in production, it gives me a sick-to-my-stomach feeling actually.

After thinking it through I'm reminded of an experience in college. I went to an undergrad welcome event for computer science majors and met a lot of young would-be computer people. One stood out, we'll call him Eric, who was so certain of how his college career would pan out and how he'd move along to an internship with one of 3 companies he had already pre-selected. I couldn't decide if I admired this guy, or if I thought he was just full of it. He did have some programming under his belt from high school, and my high school didn't offer any real programming classes so all I had was what hacking I had done myself.

I ended up seeing Eric again in the first programming class everyone had to take, the "weeder" class that thins out the impacted major. Fast forward to the first major programming assignment, due 9.a.m Saturday morning. EVERYONE, the entire class, is tired and frantically figuring out how to pass all the test cases in the basement of a large concrete building at 3.am. I was sitting next to Eric, trying to figure out test case #15 and having no luck. I had what I thought would work, but was getting maybe a dozen compile errors or warnings as I made my way towards the final working progress. I leaned over to him, 

Me: "Hey, how's it going?"

Eric: "Good good, almost done I think."

Me: "Really? Wow, that's awesome. " (I couldn't believe it. I'd be there until the sun came up turning it in just before the 9.am deadline like most).

Me: "Can I ask you a question about #15? I think I'm doing it as it says, but I keep getting this compile error: 'Blah blah'. Are you getting that too?"

Him: "Oh, I'm writing it all out first, then I'm going to turn on the errors."

Me: "Oh, ok, nevermind then."

I think I just guessed he was that good, that he could write the whole thing out free form and with all the pieces in place it'd work. He didn't want to see the errors, they were really bothering him and hindering him from proceeding along.  A couple hours later (4 or 5 am) I was down to probably half the errors and warnings from before, curious how he was doing. 

Me: "Making some progress?"

Eric: "Yup, almost done. I'm about to compile with the errors and warnings turned on."

He went to the command line, compiled -- 187 errors & warnings. Eric's mouth dropped. You could tell, it was game over and he knew it. Having avoided seeing the errors all week, he now had too many to resolve. He hadn't assembled the program layer by layer against the compiler errors the way I had. He looked over and said "I'm going to work on this from my room and fix these before 9". He packed up and left. Needless to say, he dropped the class. I then saw him a year later, he had changed his major and was happy doing something else.

I thought of this when I saw the genetic trait analysis. If your brain is fighting you every time you see an error, you're not going to like programming (maybe you'd be a good QA person though?). When I was a kid I used to take toys apart, and see how they worked, sometimes they'd go back together, sometimes not. It didn't bother me too much. Making circuits on a breadboard, if I crossed some wires and fried an LED or motor, no biggie. I picked up programming as early as elementary school using Logo, without the internet to look up solutions, so you can imagine how many errors I'd see there. If your brain is wired to treat you to avoid seeing those errors, you're not going to like programming. If an error is just another feedback, like a hint, or like a bowling alley rubber bumper, then you're the programmer type.

What do you think? Can someone be error-avoiding and be a programmer?