November 05, 2007

 Visual Studio 2008 and .Net 3.5 due this month

This has been making the rounds for about a week now, but Visual Studio 2008 and .Net 3.4 is expected to be released this month (November 2007).
More info below:
http://blogs.msdn.com/somasegar/archive/2007/11/05/teched-developer-in-europe.aspx
http://msdn2.microsoft.com/en-us/vstudio/products/default.aspx
Also there is a rumor that the Microsoft ASP.Net MVC framework will also be released REAL SOON (meaning: when they feel like it, but probably after the Visual Studio 2008 launch -- and they will probably change the name).
For those of you who don't know: the Asp.Net MVC Framework is a MonoRail/Ruby On Rails-esk web development framework for Asp.Net. It does not use WinForms at all. This actually has a lot of people really excited right now. Phil Haack and Rob Conery both left their current jobs for Microsoft just so they could help work on this.
Haack must be the single greatest last name for a developer....
Scott Hanselman (now a blue badge Microsofty) has two videos from the ALT.NET conference last month with Scott Guthrie and himself.
http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx

Labels: ,

 July 28, 2007

 C# Parital Methods

Update: Orcas Beta 2 is out, and I found a problem in my syntax. Now fixed.

I was just looking through the Orcas Beta 1, and I saw something I have been waiting to talk about...Partial Methods!

This allows you to create a method sub in a partial class so you can provide the implementation in another partial class.

A case where I would use this: in code generation. You generate a data object as a partial class. Now say you want to customize the constructor a bit more. Current you have to use inheritance to do that -- but then you have to remember to use the inherited class and not the generated calss. But with partial methods you can use the main class and provide that logic. Also, if the partial method is not implemented in the other partial class, it is taken out by the compiler. Nice.

A second use: logging. You can stub out methods where you would like logging to occur, but you don't want the partial class to have to deal with the implementation of logging, making it easier to switch out later.

I hope you see why I am excited about this enhancement.

A couple of caveats though,
  1. the method must return void (or a sub for you VB folks).
  2. out parameters are not allowed -- but parameters are allowed in general.
  3. You are not allowed access to internal/private members
  4. They can only be defined and implemented in a partial class.

Below is a stub implementation:

// my generated class in file1.cs
public partial class Class1
{
// a partial method
partial void CalledByInit();

public void Init()
{
CalledByInit();
}

}

// my implementation class in file2.cs
public partial class Class1
{
public void CalledByInit()
{
// do my stuff here
}
}

Now why is this better than:
1. just declaring a delegate in the middle of your class?
2. passing in the code as a predicate parameter?

The answer:
1. A delegate can be assigned by anyone, and potentially have multiple implementations. That isn't always good. The partial method can only have one implementation and only by other partial class.
2. aesthetically that makes a really ugly call, plus it requires that the caller have intimate knowledge of the workings of the method that it shouldn't have to have. Now you can localize that knowledge in one place.

Again, thing about the main use case for the partial method: it should be used in conjunction with code generators. If any of you have used SubSonic, Typed Datasets, NHibernate, or other technologies, right now you are using a mixture of inheritance and partial classes. With this you might be able to drop the inherited class all together. And frankly, I'm for anything that reduces the number of classes lying around a project.

If you are interested in other new features in C# 3.0 I found a nice Power Point from Raj that you can check out.

Partial Methods are mentioned on LukeH's blog.
And they are talked about on the VB Team blog.

Labels: , ,

 July 18, 2007

 Where are the DSLs?

DSL is a Domain Specific Language. It took me a couple of years to really wrap my head around what the term means. Now I have a bad understanding -- but where are the languages?

First off, in my understanding of a DSL, it might not be a proper definition. Frankly, I don't care if the language is a full on language, with it's own syntax and control structures, or just a set of very specific libraries that add classes and methods for easily reading what is going on inside of an existing language -- like C# or VB.NET.

Personally, I like the second one. I would take the inspiration from SubSonic and NHiberate. Heck, throw in NUnit if you want. The nice thing about using these as your examples is that you know things are easily extendable.

There are a couple that I am thinking of right now. I've been playing around with MSBuild and NANT lately. Those two tools have convinced me that XML sucks as a language format. How do you define a loop in XML? You can't do it in any terse format I can tell you that. XML is for data, not logic. That is why JavaScript doesn't look like HTML.

So no, I dont buy XML as a language. Personally, I have a hard time seeing through all of the angle bracket -- really, I do. They just seem to create a lot of unnecessary noise to me. Readability stinks, which hurts the overall expressiveness of the language -- not to mention aesthetics -- and maintainability is also terrible. Not a whole lot of syntax highlighters for xml these days. Debuggability: None. (is debuggability a word?) Either it works or it doesn't. If it doesn't...may the force be with you.

Anyway, back to the build scripts example. Basically, even if you have sample build scripts to work off of, it will easily waist one day of a developer's life to get a build script off the ground. Just to get started. Then countless more hours keeping the stupid thing up to date.

Why don't we have a build script DSL? Some already do exist, Ruby Rake is one. I'm considering learning it. I would like a C# based one, but I'll take Ruby if I have to.

Another use that I have thought of often has to do with ETL. Now I find I'm not alone. Ayande has recently been bitten by the bug. Which is good. Because with his given track record he might just be able to do it. Would you rather deal with Integration Services GUI or a language specifically designed for that purpose.

Bear in mind, these examples break down at one crucial point: threading. Both of the examples mentioned, ETL and Build Scripts, can benefit heavily from working in parallel. And that is one area that our current languages don't help us with a whole lot yet. It is easy to tell Integration Services to load a bunch of tables at the same time in the GUI -- that is a lot more work in C#.

Now it can all be mocked with the Unit of Work pattern so everything can be batched together. That would hide the complexity from the user of the language at the very least. But that still leaves a lot of complexity behind the scenes.

Which leads me to one of the new great hopes coming from Microsoft sometime in the future: PLINQ. Aka: Parallel LINQ. LINQ is all about building a better FOR loop. But it is still iterating over a list one item at a time. PLINQ takes things that next crucial step: multi-threading the iteration. And all without changing the syntax of LINQ. Now that is flippen cool. Unfortunately, I have heard no release date for PLINQ, and it probably wont come out with .NET 3.5 at all.

Anyway, those are my thoughts. I could go on, but I need to get back to work.

Labels: , , , ,

 June 13, 2007

 Visual Studio Shortcuts: Collapsing and Expanding text

OK, here are some shortcuts I recently rediscovered. These are in response to me suddenly finding a lot of code collapsed in Visual Studio so only the definitions were visible.

All of these shortcuts are found in the Visual Studio menu Edit->Outlining

Ctrl-M, Ctrl-M: Toggle Outlining Expansion
This one is useful if you have a single function you want to view or hide
Ctrl-M, Ctrl-L: Toggle All Outlining Expansion
Use this to view or hide an entire file
Ctrl-M, Ctrl-O: Collapse to Definitions

Labels:

 April 27, 2007

 Debugging an ASP.NET Web Site with SSL

Here is another fun one, and a follow up to my last post.

We are developing a ASP.NET Web Site that needs security. So we add a SSL Certificate to IIS and go. But, debugging with that pesky "https" prefix is a little harder.

The problem is that when you debug an ASP.NET Web Site you are using Cassini as you web server by default. You can go to Project->Properties->Start Options and tell Visual Studio.Net to launch with a "Custom Web Server" -- but that only works if you are using NT Authentication. We not.

So by default, you cannot debug as ASP.NET Web Site with an SSL certificate in use. Unless you know of a back door. (If I was using sound effects, I would have a drum role right here).

First you should know there are two types of web projects: ASP.NET Web Site and ASP.NET Web Application. The ASP.NET Web Site is new to .Net 2.0 and there are a number of differences between the two project types. You can look up most of them later, I'm only interested in one difference.

In the ASP.NET Web Application, when you go to Project->Properties->Web tab, you can specify to debug with the IIS Web server. You can even tell it which Url to use. So if your url is normally "http://localhost/MyWebApp" you can change it to "https://localhost/MyWebApp" and viola!, you are debugging a secure web site!

OK, but our current web application is not a ASP.NET Web Application, it is a ASP.NET Web Site, and I don't get that option -- but I still need to debug the web site with the certificate. Now I'm getting to the back door.

First note: to do this, your existing application must be a Web Application in IIS.

First off, don't change your project type, leave your existing web application as is, no changes. Create a new ASP.NET Web Application, call it DebuggableWebProject (or something like that). It should be created with a Default.aspx page. Make the changes I specified to the properties pages I specified up above. Also register the web site with IIS; if using IIS7, both web site must be part of the same application pool. The run the web site from Visual Studio.Net in debug mode.

Next, from your new web site in Visaul Studio.Net, open one of the code files (either .cs or a .vb). Set a break point somewhere obvious. Then open up your web site in IE/Firefox using the SSL address (https://localhost/MyWebApp/...) and hit a page that should go thru the code you set the breakpoint in and the breakpoint should catch.

That is basically it. You create a second web project to debug your existing web project. That is your back door. It is a little strange, but it works fine. It even allows you to debug a secure web service call.

Anyway, I found this by accident and I hope it helps someone else along the way. Also note: I am using IIS7 Visual Studio.Net 2005 and have not tested this with IIS6 or any other version of Visual Studio.NET. But it does work in both Integrated and Classic mode application pools in IIS7.

kick it on DotNetKicks.com

Labels: , ,

 April 26, 2007

 Using secure WebServices

One of my projects these days is developing a WinForms application that talks to a server via web services. Pretty standard stuff.

I finally got to the "Secure web services" task. No problem, also pretty standard stuff. And it is...if you can find the info.

First step: Secure your web service with an SSL certificate. If you are developing on Vista and using IIS7 -- congratulations, you get this for half price. Go see ScottGu's article titled: Tip/Trick: Enabling SSL on IIS 7.0 Using Self-Signed Certificates

5 minutes later -- step one complete.

Step two: check my application to see if everything still works.

5 minutes later -- utter failure!

The app blows up all over the place. I act like this is unexpected, but it isn't. You can't make a change like that without a few casualties. When you sign onto a web site with a certificate you are usually asked if it is OK to accept said certificate. But I aint writing a web browser, I just want to accept the certificate (if there is one) OK Google, don't fail me now...

Anyway, after some searching I found a nice post by some guy named Jan at http://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx
where he talks about the problem.

I go to implement it and find out the method calls he is using are obsolete as of .Net 2.0.
The old method to use was System.Net.ServicePointManager.CertificatePolicy.
The new method to use is System.Net.ServicePointManager.ServerCertificateValidationCallback

By the time I had found that I had, once again, given up on Google and gone straight to MSDN Forums. Actually, I was using MSDN's search feature -- but luckily it also searches the forums.

So anyway, if you are looking to accept a cert on your client app here is some code for you.

// add this to your code before you make your web service call.
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslError)
{
bool validationResult = true;
return validationResult;
};

BTW, has everyone noticed that you can now add information to MSDN? Very cool. I added this code snippet to the MSDN documentation -- just in case they don't read my blog.


kick it on DotNetKicks.com

Labels: , ,

 April 25, 2007

 ReSharper 2.5.2 is out

I missed this one for two days before seeing it.

JetBrains has released a new version of their Visual Stuido.Net add-in ReSharper with a health bug fix list.

It is a great tool, but if you dont have it and can't afford it, do check out their unit testing addin called UnitRun. It is free and well worth the download.

Labels: ,

 April 19, 2007

 Visual Studio "Orcas" and .NET FX 3.5 Beta1 shipped!

Visual Studio "Orcas" and .NET FX 3.5 Beta1 shipped!


You can read about it on Soma's blog.

Or go right to the MSDN page.

I'm sure there will be more on this later.

Labels: ,

 March 27, 2007

 ReSharper UnitRun

I'm all in favor of good tools when I can find them, even better when they are free (as this one appears to be).


But JetBrains has released ReSharper UnitRun for down.
http://www.jetbrains.com/unitrun/

If you already use ReSharper you know how good of a tool this is already.
If you don't user ReSharper, this is one of the best features in it (next to automatic code profiling).

So, if you are doing Test Driving development, check it out, it is worth the download.

Labels: ,

 March 23, 2007

 PLinq out of the bag

First off, a definition: PLINQ is Parallel LINQ. It allows you to run LINQ commands in parallel with minimal effort.

I didn't know this was out of NDA yet, but I just saw some links on MSDN's C# Developer Center.

PLINQ is being discussed in the wild!

I first heard about this at Microsoft's MVP Summit in a talk that Anders Hejlsberg was giving. It was probably one of two of the coolest things I saw at the MVP Summit (and the other will have to wait a while longer before I talk about it here).

Anyway, here are a few more links I've found on PLINQ:
http://themechanicalbride.blogspot.com/2007/03/dreaming-of-plinq.html
http://www.bluebytesoftware.com/blog/PermaLink,guid,81ca9c00-b43e-4860-b96b-4fd2bd735c9f.aspx
http://www.eweek.com/article2/0,1759,2009167,00.asp?kc=EWRSS03119TX1K0000594

I will be posting more about this later.

Labels: , ,

 March 22, 2007

 Visual Studio.Net Short-cut: Format Document

OK, here is another nice short-cut: Format Document

Ctrl-k, Ctrl-d

Same as last time, this is a cord. You have to hit both in series.

There is another way to do this, btw. In C#, find the last '}', delete it, and re-type it.

And because I can't seem to just blog on short-cut at a time...

Surround With Snippets:
Ctrl-k, Ctrl-s

This brings up the list of snippets that can surround the current code with another code block. Ex. Try-Finally, While, Foreach, etc. Note: this even works with Resharper installed.

Labels:

 March 21, 2007

 Visual Studio.Net tool I didn't know about

One of those things I have long believed is there is potential for really cool things to be hidden in the Visual Studio.Net IDE and I wont know about them.

I found out it was very true last week. Someone introduced me to "Code Definition Window" (shortcut Ctrl-\, Ctrl-d).

You probably already know about the right-click option Go to Definition. This does that one better. It is a tool window that displays the definition of whatever your cursor is on in a read only window.

It is kind of like the second code window you always wanted.

Labels:

 Vistual Studio.NET shortcuts of the day

I got this neat handout from Microsoft the other day with a "complete" list of Visual Studio.NET shortcut commands. And I am all in favor of not having to reach for the mouse.

So here are my two favorite Refactoring shortcuts:
First a note of warning, these command are chords. Meaning, you hit the first command, and then the second command to get it to work. This is actually kind of nice, all of the refactoring commands are grouped under a Ctrl-r. So to do a Refactor.Rename, you hit Ctrl-r, then Ctrl-r again.

Anyway, here is the list:

Ctrl-r, Ctrl-r: Rename

Ctrl-r, Ctrl-e: Encapsulate Field (turn a private variable into a public property)

Ctrl-r, Ctrl-i: Create an interface for the current class

Ctrl-r, Ctrl-m: Extract Method

Four is enough for one blog post I think. Any more than that and I would overwhelm you with them. So, learn these and I will post more later.

Labels: