Session: Best Practices with the Microsoft Visual C# 3.0 Language Features
Originally,
I had planned to attend the session Providing Load Balancing,
Application-Level Failover, and Centralized Configuration Management
with Windows Communication Foundation Services and Microsoft .NET
Applications (say that five times fast). However, Jay had really
recommended Mads Torgersen as a knowledgeable presenter. So, I decided
to check the session out.
Like others
before, Mads was a stay-in-the-IDE kind of presenter: he started with a
blank class file and began coding away his examples, at least for most
of his presentation.
Mads summarized C# 3.0 as:
- A move from imperative to declarative programming
- A paradigm shift from "how" thinking to "what" thinking
- and...LINQ
One
of the first features Mads talked about is Auto-Implement properties.
This is just a time saving convention. Traditionally, when we have
coded properties, we've always had to code a private member to store
the value of the property: a "backing field" as he called it. With C#
3.0, all you need to do is:
public string X {get; set;}
One gotcha Mads mentioned was that you must have both a getter and setter.
Another feature he mentioned was implicitly typed locals. Where once we coded this:
List<x> y = new List<x>();
Now, we can do this:
var y = new List<x>();
Next
was object and collection initializers. This feature lets you reduce
lines of code by setting properties of an object inline with the object
initialization. Thus, where once we had to do this:
Customer x = new Customer();
x.ID = "SomeId";
Now, we can do this:
Customer x = new Customer{ ID="SomeId" };
C#
3.0 also brings us Extension Methods. Extension methods are a way of
tacking on you own methods to a pre-existing object. Here's an example
of an extension method I wrote:
public static class SomeExtensions
{
public static string ReverseMe(this string reverse)
{
char[] rev = reverse.ToCharArray();
Array.Reverse(rev);
return (new string(rev));
}
}
To
use this method, then, all you have to do is call the ReverseMe method:
MyString.ReverseMe(). The reverse of MyString will be returned.
Lambda expressions is the next evolution of the delegate story. Where once we did something like this:
delegate (Customer c) { return c.City == "London"; }
Now, we can shorten that syntax to this:
( c => c.City == "London" )
LINQ
is obviously one of the most popular features of C# 3.0, so Mads spent
some time talking about how LINQ helps integrate our queries in with
the rest of our code. The last item I have jotted down in my notes is
Expression Trees. Expression trees are something like lambda
expressions that make use of the new Expression<T> type.
Session: N-Tier Development with Microsoft Visual Studio 2008 and Windows Communication Foundation
Here
was another session I attended presented by
Rocky Lhotka. This time, unlike the "N-Tier"
session I attended on the
first day, Rocky really did
work toward the goal of physically separating out the layers of an
application.
He started with the good 'ol DataSet. Did you know you can actually
separate the DataSet and its adapter into separate assemblies? Rocky
showed us how. Who knew we could actually achieve some level of
separation of concerns with the dataset?
Next up was
Windows Communication Foundation (WCF). Rocky proceeded to
walk through an example of passing strongly typed datasets via WCF.
These types must be installed on both the client and server.
Rocky then dove into a discussion of the
DataContract. He
contrasted the
DataContract attribute
with the
Serializable attribute:
the DataContract attribute adopts an "opt-in" approach while the
Serializable attribute adopts an "opt-out" approach. The "opt-in"
approach requires that you explicitly decorate all the members of your
class that you want to serialize over the wire. You do this with the
DataMember attribute.
The danger here is that if you have a large domain object, you may miss
a member. On the other hand, the "opt-out" approach of the
Serializable attribute assumes that all members of your domain object
should be serialized unless you explicitly state not to serialize a
particular member. This approach could be deemed safer--at least from
the absent-minded developer.
The last topic Rocky covered was the serialization engines of WCF. The
Data Contract Serializer
(DCS), "does not preserve the graph shape." I can't remember exactly
what Rocky meant by that, but it sounds bad--I vaguely recall that this
reality could play havoc with deserialization efforts on the part of
the client or server. Apparently, the DCS includes a constructor
overload where you can force the serializer to preserve the object
graph shape, but that can apparently get sticky.
He then moved on to the
Net Data Contract Serializer
(NDCS). The NDCS has the ability to serialize more complicated domain
objects, but, if I recall correctly, it comes at the sacrifice of
interoperability.
Session: Windows Presentation Foundation-Based UI: What We've Learned So Far and What's Still to Come
The session was presented by Dr. Gil Hupert-Graff of
Beyond UX. This was another one of those touchy-feely
type presentations--or maybe my design skills are so poor that I don't
know a good design presentation when I see one. At any rate, the good
doctor walked through a few demos of applications his company built for
clients--applications with a UI/WPF/wiz-bang emphasis. He then went
into his company's experimentation with the intersection of design and
development--where the scope of the designer ends and the developer's
begin.
Expression Blend
makes this intersection even more interesting because it can be both a
design and a development tool at the same time (of course, it also
serves as a tool equally hated by most designers and developers). Gil
discussed how his team has used story boards to layout a UI and then
used a combination of Photoshop and Blend to make the story board a
reality. He also laid out some interesting workflows of when and where
the designer does work and when and where the developer picks up the
remaining tasks.
Session: Jump in the Car and Race to the Airport
Well, I had to cut out a little early to make my flight. Overall, the
TechEd experience was a good one and going back over all my notes was a
good refresher--a tough task, to be sure, but a useful one. I'm
looking forward to getting the DVDs and, hopefully, all the demo code.
I'm also looking forward to finishing building out my new machine
(inspired by
this and
this), so I can really start digging into WPF and Silverlight2, among other
technologies.