Notes from .net developer Group meeting

 

Tonight the triad developers guild met.  Brian Hitney from Microsoft presented on the “Visual Studio Debugger” and I figured I would not learn to much.  I was wrong; there were a number of great tips I picked up.  Great job Brian!  Brian presented a number of tips, but the *new ones* for me that others might also like to know are..

 

  • For a multi-threaded app, if you have a bunch of threads going, you can freeze them and show where they are in the debugger (outside the thread you are debugging) by checking “Show Threads in Source”. 

    image

  • Tracepoints are like breakpoints but without pausing execution. Nice for quick and dirty (and super temporary) tracing
  • Calling a method from the watch window bypassed breakpoints, while calling from the immediate window honors them
  • You can create compiler-level variables while debugging, and those variables are dereferenced using the pattern $[your variable name here]. 
    • These variables had a wide scope, so you could use them further up in the stack. I could almost see using this to swap out mock objects while debugging a highly sensitive piece of code that is difficult to *get to*
  • You can drag a segment of code into the watch window (I have traditionally used the shift+f9 [quick watch] window for this) to execute
  • You can use the “Make Object Id” command to effectively set a weak reference to a variable, allowing the developer to effectively widen the scope and lifetime.  Combine this with things like GC.GetGeneration(your variable) and you can track an objects generation in the garbage collector.  Kind of an edge case, and if you find yourself doing *that* you might check out a profiler tool instead.  Still, neat.

image

  • Microsoft released much of the .net source code and debug symbols a while back.  You can go into Tools > Options > debugging in visual studio and configure it to allow the developer to step right into .net framework code.
    • There is a tool called “NetMassDownloader” which can preemptively snag all the source, comments, debug symbols ahead of time rather that JIT-downloading it during debugging.
  • Mole for Visual Studio.   Very cool tool and I plan to use ASAP.  This is basically one honking visualizer on steroids.  Cool extra’s like “favorites”.  Great stuff.

 

Like I said, several great tidbits this evening.  Never fails, and proves the value in engaging in your local .net user groups.

linq, auto properties, all the goodies boost productivity

I’m working on a little side-project for a former co-worker.  Its a small project, and I’m working on the back-end using asp.net 3.5.  I don’t know if its Linq, or Linq-to-sql, or the automatic properties, or improved VS productivity tidbits (and enhanced intellisense), but I just find myself moving quickly with great productivity on projects like this. 

Case in point.  I had to snag some data out of the database in a flat manner, and present it in a grouped manner.  Instead of having to group the data up myself, I just used Linq’s GroupBy() support and formed my data into the shape I needed (this was to allow clean data-binding with nested DataLists without going to the db more than once).

Ok, I’m rambling, but while asp.net 3.5 was considerably smaller than 2.0 in size/scope, it just seems to fit right.  So, props to Microsoft.

(Don’t worry, we’ll have more than enough complaints when it comes to other things…. like Moss).

Silverlight worth digging into

I’ve gone through the basic tutorial from “The Gu” and done a little playing around with a few samples from MSDN Magazine.  I snagged another example off MS’s samples site, and after spending an hour or so commenting out and tweaking broken Xaml to get it to run, I realized….uh..time to read up on this subject.

So, I bought this book.  I think my interests are heavier around the deep support for animation and such, but I’d have to get waaaaay stronger in fundamental math concepts; something I’ve been kinda wanting to do anyhow (ex: Trig).  I believe this is where Silverlight (or the “F” word) can add value that is otherwise very tricky to pull off in the web.

We’ll see….

Fun with Func, lambdas and closures

I had a need to encapsulate a method and execute it in a loop (ideally by an external component) for rudimentary retry logic.  I further didn’t want to be confined to a specific method signature.  In other words, I wanted a class to be able to call a function generically without having to know the method signature but still have a consistent return type.

Turns out, it was pretty easy to pull off.  Define a Func<T> as your delegate for the routine you want to call.  Then, define another Func<T> that is assigned to a lambda (or you could use an anonymous method) which calls the Func<T> previously specified.  You’ve just created a closure, so now you can toss that little Gem off to some class that accepts the signature of the second Func<T> and loop around, executing that function over and over.  I haven’t cracked the code open yet in Reflector, but my understanding is this all gets boiled down to compiler slight of hand, creating types for all this, and I believe stack state is pushed onto the heap (along with the *this* pointer).

Example (toss in a console app):

class Program

    {

        private string id;

 

        static void Main(string[] args)

        {

            Program program = new Program();

            program.DoStuff();

 

            Program program2 = new Program();

            program2.DoStuff();

        }

 

        private void DoStuff()

        {

            this.id = Guid.NewGuid().ToString();

 

            Func<string, string> myFunction = this.Echo;

            Func<string> myClosure = () => myFunction(“Hey there!”);

 

            string[] messages = this.RunThreeTimes(myClosure).Split(“,”.ToCharArray());

 

            foreach (string message in messages)

            {

                Console.WriteLine(message);

            }

 

        }

 

        private string Echo(string message)

        {

            return string.Concat(message, this.id);

        }

 

        private string RunThreeTimes(Func<string> bundleOfJoy)

        {

            StringBuilder sb = new StringBuilder();

 

            for (int i = 0; i < 3; i++)

            {

                sb.Append(bundleOfJoy.Invoke() + “,”);

            }

 

            return sb.ToString().TrimEnd(“,”.ToCharArray());

 

        }

    }