Code Snippets in Visual Studio C# Express

I know I said earlier that I would talk about the features in the upcoming Visual Studio 2005, but a certain something has occupied my time for the last few months. Right before I left for Brazil I downloaded some of the express editions that microsoft posted. I’ve only installed the C# edition, so far. At first I was skeptical about these express editions, but it seems to be pretty good so far.

I started playing with the new framework and the IDE (can we call it that, still?). Right now, it’s just the equivalent of doodling, but I do have some project ideas. My framework play has so far only been with System.IO. There are some nifty improvements in that namespace, and they’re not even that flashy. I wanted to look at what some of the new properties spit out, so I whipped up a quick Console App. One of the things I type a lot when debugging(yeah, yeah unit tests, I know) is

Console.WriteLine(”Some string {0}”, someobject.Property);

My fingers can fly across the keyboard when I type that. Sometimes they fly too fast and I start off with “COnsole,” and then intellisense doesn’t show up, etc. Is there a way to reduce typing? With VS 2005, there is! Yay! The folks at MS have setup a lot of the “code-based RAD” features as code snippets: refactoring, expansions, surround with.

Code snippets are XML files that contain templates for the particular expansion you want. For instance, if you type foreach and then press Tab the expansion will show up like so:

So I tried my hand at creating a new one for Console.WriteLine(). If you click Tools > Code Snippet Manager, you get an almost useless dialog that shows you where the expansions can be found. It installs two directories by default:

  • [Program Files]\Visual Studio 8\VC#\Expansions\1033\Expansions
  • [My Documents]\Visual Studio\Whidbey\CodeSnippets\Code Snippets\VC#\My Code Snippets

Something like those anyway. The first is where the default ones are kept. The second is a path that isn’t created by VS, you have to do it. Once you create it, though you can dump your expansions in there, and the IDE should find them. The reason they don’t create it has something to do with this being beta stuff.

To create mine, I just copied one at random from the first path into the second path, renamed it and edited the xml. This is what I got:

<CodeSnippet Format="1.0.0">
  <Header>
    <Title>Console.WriteLine</Title>
    <Shortcut>writeline</Shortcut>
    <Description>Expansion for Console.WriteLine</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
      <SnippetType>SurroundsWith</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Code Language="csharp" Format="CData">Console.WriteLine("{0}", $selected$ );
        $end$
    </Code>
  </Snippet>
</CodeSnippet>

As you can see, it’s a very simple expansion. The real work is in Snippet tag, I think. (I did this without google or documentation, so I can only guess at meanings and that’s bad.) There you can see the code that I put in. The ‘$selected$’ placeholder is for any selected text, so you can surround a selection with this particular code. I’m not sure what ‘$end$’ does, but I speculate it’s telling the IDE that it’s reached the end of the CDATA section. One thing I found is that $selected$ has to be separated from the rest of text by whitespace: “$selected$)” would fail; but “$selected$ )” wouldn’t.

Easy, eh? Now in the IDE, I can type writeline (note the Shortcut tag above), hit Tab and out pops Console.WriteLine(). Very cool and very powerful. I have a feeling I’ll be using this a lot. I also have a hunch that templates for whole files are based on this (I’m pretty sure I read that somewhere). I’ll look into that and maybe come back with something more formal and more detailed. Here’s a link to the xml file for Console.WriteLine().

Home Sweet Home

I arrived back in Victoria on Monday afternoon after an awesome time in Rio de Janeiro. The three days we (all the Canadians, with the exception of the judge) spent there were very different than the days in Sao Paulo and Foz do Iguacu. There were no schedules or timings or tasks; just sitting on the beach and admiring the scenery. Rio was very different from Sao Paulo. It was cleaner, warmer and prettier.

Our hotel was right on Copacabana beach. We also went to Ipanema and Le Blon. The highlight of the trip was hang-gliding and para-gliding. We did that the second day there. Since I’m totally afraid of heights, I was really nervous about going. I had signed up for hang-gliding originally. To launch the glider, you have to run off a ramp on a perfectly good mountain to get enough speed to go. I saw a few people do it and I don’t know if I could muster the nerve to do that. Turns out I didn’t have to worry about it. Because I’m such a big mofo, the hang-gliding flight path would have been a diagonal line from the mountain to the beach. Para-gliding was better for my size Iwas told, so I did that. I had the owner of the company jump with me. (All of the us went tandem, with an expert.) He did a very good job of relaxing me, without me even knowing it. Para-gliding takeoff entails running down the mountain for a while, a much easier proposition. Ruy, my tandem jumper (pronounced Hooie), told me that the takeoff was the most important thing. I nodded.

When we were finally lined up to take off, he told me to start walking. Walk faster. Walk Jason. Then we were in the air. He said we had a really good takeoff, so I got a special bonus 360 turn right after we took off. The descent was really slow, slower than I was expecting. The view was amazing. But the landing? Not so much. I completely bailed on the landing and got my front covered in mud. I still have orange mud on my sneakers from the trip. It was still really cool, though.

The rest of the tour sucked because it was raining the whole time. We didn’t get to see Christ the Redeemer because of the weather, so that was disappointing. But the whole trip was super sweet. I consider myself very luck to have had the opportunity. I have one more post on Imagine Cup: my final thoughts, and ways to improve it for next year; and then I’m going to close the topic.

Imagine Cup Day 6 – Vive La France

Adios, Foz do Iguacu

We’re back in Sao Paulo now. The final day in Foz do Iguacu, yesterday, was a mix of tourist events and travelling. In the morning, we went on a boat ride to see the falls. We got all wet and took pictures. Then we went to a bird park to see all kinds of crazy birds. I took all the pictures in my camera there. I’m debating whether to buy another for the rest of the trip, since everyone else has a digital camera.

Anyway, after that, we checked out, and flew out of Foz do Iguacu and arrived in Sao Paulo around 6pm at a different airport right in the middle of town. On the bus ride to the hotel, we saw planes taxiing on the runway above us. The bus ride was kinda scary. There are some really poor parts of town that we saw on the way here. Houses with walls made up of several boards, for instance. We even saw a man with a cart being pulled by a mule. To contrast with that, we arrived at the hotel and checked in. This is the best hotel I have ever been in. It’s about $600 Cdn to stay for a night.

No rest for the wicked

After we had checked in, we all met in the lobby and finally got to see some true Brazillian stuff, that’s not touristy. We went to a neighbourhood called Itaim and ate at a restaurant called Corleonne (it was based on The Godfather). Very different, not knowing the language and talking to the waiter thru signs and our terrible Portugeuse. The food was really good. Then we went to a bar/club across the street and drank some more. We got in around 1am.

And the winner is…

Today, the MS conference started. We sat in on the keynote talk where they announced the winners. The final competition announced was the Software Design. As soon as we found out that we weren’t going to enter the finals, I started rooting for the French. They were all very friendly and great guys as well. And they won! Congratulations to France for your great idea and great application. Their idea was a home management system that works thru the electrical system, not wireless. Pretty neat idea.

Now, we have to present our applications to the people at the conference and each other. I’m not all that motivated to do that, but it might be fun.

This might be the last entry, or the second-to-last. After tomorrow, we’ll be going dark and paying our own way in Rio de Janeiro.

Imagine Cup Day 4 – Imagined Cup 2004

They announced the finalists. We weren´t one of them. When I realized that we weren´t going to be in the finals, I was disappointed; but by the time I left the room where we heard the announcements, I didn´t really care. Winning would have been nice. But that´s not the real prize. The real prize is getting to meet people from all over the world, and partying with them. I no longer have to look at them as competitors, but as colleagues and friends. I´ve met far more people since the announcement than before it. There might have been a bit more bitterness in my teammates, but I think since we´ve had time to reflect, we´re all OK. We took some time to vent with Ben and each other. So I wish the finalist teams good luck in the competition.

Did the exception that I had prevent us from moving on? I´m not sure I want to know. I don´t think it did. Our problem, I think, was that we didn´t relate the problem well enough to the judges. They were from all over the world: amateur sports could be very different where they come from, so they may not be able to see the importance of our app to the market. We´ll present to the Canadian judge in Sao Paulo and see what he thinks. I´ll also see what feedback I can get on our app from the judges that saw us.

Imagine Cup Day 3 and 4 – The Competition

Day 3 started early. Most of the Canadians were up bright and early after our late night, including me, of course 🙂 All the teams went on a tour of Foz do Iguacu (the falls). These were really impressive. Bigger, by far, than Niagara. Very beautiful, and well preserved: there are very few buildings around unlike Niagara. Our tour guide, Luciano, was very entertaining, great sense of humour. We see him tomorrow, Day 5, for a boat tour as well.

It Starts…

When we got back from the falls, we had a giant Kool-Aid binge session from the organizers at Microsoft. They said we were all family and we´re all winners; eye-rolling stuff, but necessary. Then we had lunch and a quick briefing on the format for the competition. After that we all had naps or something. It seems so far away but it was only a day ago. After a break, we got down to practicing our Lightning Round presentation, a 10-minute presentation that describes the application at a high level. We had our MS ADE (not sure what that stands for), Ben Watson, help us with some pointers. Mike, our presenter, did a few practice rounds, and we were ready to go. We presented twice to two different sets of judges, because of the format for the competition. The first time we presented, one of the judges slept through the whole thing. We asked around afterwards, and it turns out he was sleeping for a lot of them. Other than that the judges looked totally bored with the presentations; I don´t think it was because we gave a boring presentation either. Mike delivered the presentation very well. My guess is jet lag and seeing so many of them without relent.

The second one went even better. Mike was excellent, and the judges were awake, but still looked bored. The Lightning Round wasn´t scored, and only served as an intro to the application. In between the two presentations, we worked on our main demo, the scored demo on Day 4, with Ben and worked out the main format. Then we had a late dinner, and a showing of the movies for the Rendering and Short Film competitions. They were a lot of fun, and very good. Canada has an entry in the Short Film competition as well. After that was over, we went to our room to practice the demo and finalize the format. We were getting snappy at each other because of the stress. We really had to work hard to get it into the time we were given, 15 minutes. We finally got there around one in the morning and quickly went to sleep 

Day 4 – The main competition

Another early start; this time, because we were presenting at 830. We got all setup at our booth around 7am and waited. Then 830 rolled around we presented to our judges. This went really smoothly. We answered the questions they gave us really well. The demos all worked. I thought we did a great job.

After that, we all went to have some much-needed naps 🙂 After lunch we presented again to the other judges for a wildcard spot (explaining the format of the competition is too much typing 🙂 I´m sure you can find it on the web.) This one didn´t go very good. And I´m the grade-A moron that was responsible. We had a prepared tournament to present with and so I had to open it to show scheduling. But then I got an unexpected error. Uh oh. So I closed down and tried again. Error. Gasp. Read the error this time. For the first part of the demo, I created a tournament with a name that I had already used. The Open Tournament dialog couldn´t handle it. Shit. I couldn´t show the scheduler this way. Tyler was pretty sharp and started talking about some more features for the web, while Mike and I tried to fix it. What a dummy, I was thinking to myself. We couldn´t delete the tournament from the database (it´s really constrained). Damn. How do I get it to work? Aha. I can rename it in the database and it´ll be fine. The rest of the presentation went on while I did the fix. So the order got screwed up and we lost about 45 seconds while I tried to fix it, but the judges all had poker faces, so I don´t know how much it cost us. We fielded the questions really well, though. I still feel really stupid, but things happen. Everyone else said it wasn´t a big deal, but I still hate screwing up like that. I hope it doesn´t jeopardize us going onward, if we would have been chosen otherwise.

After that, we got to go shopping at some tourist shop. Lots of hand-crafted things that were a lot of money. I managed to find some cool things for the family, though. Our team was the only one allowed to do this, too. It was kind of a covert thing. The organizers are really worried about us getting stabbed or something. They sent along one of the logistics people to translate for us and advise us. He was grateful too, since he didn´t have to deal with the hassles of the tournament for an hour and a half.

Now, I´m waiting for them to announce the finalists. They announce the twelve finalists in about an hour from now. If we are chosen, we present once more after dinner to yet more judges that we have not seen before. The winner is announced on the 6th of July in Sao Paulo. So after tonight, there is no more competition. Wish us luck.