A Developer WeBLOG RSS 2.0

ALT .NET Meeting #3

Where:
Atlassian Sydney Office
185 Sussex St
Sydney, NSW
[Map]

When:
Tuesday, November 25th 2008
6.00pm - 8.30pm

Topic:
Hey! You! Get On To My Cloud - Application Development in the Clouds
OR/AND
Managing Lean and Agile In The Large Software Development -Best Practices for Large Scale Development

Guest Speaker:
Dave Thomas

Wednesday, November 19, 2008 11:43:33 AM UTC |  Comments [0]
ALT .NET

Code Snippet is a feature in Visual Studio that allows you to have a predefine code, which can be inserted anywhere in your code. It sorts of like a macro, where you can just write the macro name anywhere in your code file and then press the Tab button to replace it with the piece of code you've defined. This feature was first introduced in Visual Studio 2005.

I have to say that I love code snippet. It has saved me huge amount of time. Just about any line of code that I would repetitively write, I put them into a code snippet. One of the cool thing with code snippet is that, it is supported by intelisense. This means, you don't have to type the whole snipet name everytime you want to use it. Just type a the first few characters, select your snippet from intelisense, and then press Tab twice. There you go, you have instant code generation, without having to write any codes.

Code snipet is defined in an Xml document, which has to be named with .snippet extension (e.g. MySnippet.Snippet). Code snippet consists of 2 parts: the header part, and the snippet part. The Header part contains metadata of the snippet, things like the title, shortcut name, description, author, and the types of the snippet. The snippet part contains the actual code that you would like to define in the code snippet. The code snippet itself must be inside a CodeSnippets Xml Node. Here is an example of a code snippet file (The first code snippet is just a template, the second one is an example of a working snippet):

Once you have created your snippet file, you need to place that file inside the "My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippet" folder. Or, alternativelly you could use Visual Studio Snippet Manager to define a new folder to put all your snippet files (Tools -> Snippet Manager).

One cool thing that you can do with code snippet is to define parameters for your code snippet. This allows you to easily changes things inside your code snippet. Lets take the example snippet on the picture above as an example. Rather than hardcoding the string value ("FOO"), we could just create a parameter for that. If you have a snippet with parameter, once your snippet code is written out, the cursor will automatically highlight your parameter so that you can replace the value of your parameter straight away. Moreover if you have multiple parameters, you can use the Tab key to jump from one parameter to another parameter.

To define a parameter, you need to add a literal declaration inside your snippet. In your literal declaration, you need to define an ID for the snippet parameter, which can be used later on inside your snippet code. Lastly, to use a snippet parameter, in the snippet code, you must reference the paramater ID encapsulated with the dollar sign (e.g. $ID$). That's it, thats all you need to do. An ID is the minimum value that you need to have to create snippet parameter, but there are other things that you can define for your snippet parameter, such as: a default value for the parameter and a tooltip value for the parameter. Applying parameter to the snippet example, the final snippet looks like this:

Another cool thing that you can do with code snipet is that, Instead of plain inserting a code, you are able to surround a piece of code with your snippet code. To do this all you need to do is to define a snippet of type "SurroundsWith", and then you need to define the area to place the target code by using the $selected$ value. To use your surrounds with snippet, you have to select a piece of code that you want to surround, then press cntrl+K and cntrl+S, and select the snippet that you want to use. Please note that, you can not use the "surrounds with" snippet by using intellisense. Here's an example of a "SurroundWith" snippet (taken from the default "IF" snippet):

Thats it, I hope you find code snippet to be as usefull as I find it to be.

RWendi

Wednesday, November 05, 2008 8:59:09 AM UTC |  Comments [0]
c# | VS2008

One of my colleague came accross to this file which contains all the default shortcuts of Visual Studio 2008 (c#). I find it very usefull.

c# Visual Studio 2008 default keybindings/shortcuts: [MSDN]|[Download]

RWendi

Monday, November 03, 2008 9:33:44 AM UTC |  Comments [0]
c# | VS2008

To my definition, a Namespace is a container/place holder that defines a piece of logical unit in a software system. At the very basic, Im following this namespace naming convention of: CompanyName | ProductName | [TechnologyName] | SoftwareLayer. Technology name is something optional, thus im putting it inside a square bracket. The software layer part is what usually defines the kind of logics/classes that would go to the Namespace. For example:

  • RWendi.Foo.BLL: this is where I put the business logic layer of the Foo application
  • RWendi.Foo.Blob.DAL: this is where I put the data access logic layer of the blob component, of the Foo application
  • RWendi.Foo.Utility: this is where I put all the utility classes of the Foo application. Utility is not necessarily a software layer, but it is a self contained logical piece of the software, thus warrants a namespace on its own.
The fact that we have software layer at the end of the namespace, makes it easier to decide what logics need to be put into the namespace. but what happens if its the main namespace? What kind of logic would you put inside the RWendi.Foo namespace?

The way that I use the main namespace is usually as place where I put all the things that are related to the application in general, but not related to any of the software layer. Things like initialization logic, entry point logic, application wide events, and enumerations. Lately I had a side project to develop an API, and one of the thing that I realised is that you can not apply the same rule to APIs. An API doesn't necessarilly have an entry point, initialization logic, or even an event. I had problem figuring it out on how should I utilize the main Namespace of the API, what should I put inside the main Namespace of the API?

I then realised that the API main namespace should realy contain the API logic itself. If I think about it, "An API IS a business logic layer". If an API purpose is to provide an interface to another program, then the main API namespace should contain the classes necesssary to make a request to the API's program. If an API is responsible to provide some business logics, then the API main namespace should contain those business logic classes. Having accustomed to seperating business logic classes to another namespace realy blinded me this time, because it really doesnt make sense for an API to delegate the business logics classes to another namespace.

RWendi

Sunday, November 02, 2008 7:48:20 AM UTC |  Comments [0]
Programming

Was just upgrading my dasBlog to version 2.2, and it's gone a bit disastrous. My old blog entries are not shown at all. The files are still there, but for some reason, it does not want to read the old blog entries. Still investigating the problem...

UPDATE: Issue resolved, it turns out by posting this blog post it trigers the system to re-read the old blog entries. Thank god.

Sunday, November 02, 2008 7:16:13 AM UTC |  Comments [0]
dasBlog
All Content © 2010, RWendi