Scott Hanselman

Hanselminutes Podcast 196 - .NET 4 CLR, Framework and Language Chat with Jason Olson

February 04, 2010 Comment on this post [1] Posted in ASP.NET | BCL | DLR | Learning .NET | Podcast
Sponsored By

image My one-hundred-and-ninety-sixth podcast is up. Jason Olson works (or worked, as you'll hear) for Microsoft in DPE. In this episode he takes Scott a little deeper into some of the new features in .NET 4, including security, CLR changes, C# 4 and VB 10 improvements and the new Task Parallel Library.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Check out their UI Suite of controls for ASP.NET. It's very hardcore stuff. One of the things I appreciate aboutTelerik is their commitment tocompleteness. For example, they have a page about their Right-to-Left support while some vendors have zero support, or don't bother testing. They also are committed to XHTML compliance and publish their roadmap. It's nice when your controls vendor is very transparent.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 195 - Open Source, Microsoft and The WiX Project with Rob Mensching

February 04, 2010 Comment on this post [1] Posted in Deployment | Open Source | Podcast
Sponsored By

WiX Project Logo My one-hundred-and-ninety-fifth podcast is up. The WiX Project was the first big Open Source project out of Microsoft over 10 years ago! Scott talks to project lead Rob Mensching about how the WiX Installer project got started. How much trouble did he have with Microsoft bosses and Legal? What's next for WiX?

Warning, Rob talks fast, so you want want to slow this one down a smidge. ;)

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Check out their UI Suite of controls for ASP.NET. It's very hardcore stuff. One of the things I appreciate aboutTelerik is their commitment tocompleteness. For example, they have a page about their Right-to-Left support while some vendors have zero support, or don't bother testing. They also are committed to XHTML compliance and publish their roadmap. It's nice when your controls vendor is very transparent.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The Weekly Source Code 48 - DynamicQueryable makes custom LINQ expressions easier

January 27, 2010 Comment on this post [23] Posted in ASP.NET | ASP.NET Dynamic Data | Open Source | Programming | Source Code
Sponsored By

NOTE: An alternative title to this post might be: "The Weekly Source Code 48: Making The Weekly Source Code 47 Suck Incrementally Less."

NOTE: This isn't a language feature! This works on both C# and VB!

Last week I wrote a post about Dynamic Linq Query Generation in order to solve a kind of meta-programming problem. I had a site that used ASP.NET Dynamic Data and I wanted to do a LINQ query against some data. However, because I was creating a template that didn't know enough at compile time to write a proper LINQ query that could, well, compile, I needed to creating my LINQ dynamically.

Be sure to hang in here with me, the awesome happens at the end.

I was trying to generate effectively this, at runtime

Items.Select(row => row.Property).Distinct.OrderBy(colvalue => colvalue)

And I succeeded with Tatham Oddie's help in doing it this sub-optimal way:

protected void Page_Init(object sender, EventArgs e) {
var items = Column.Table.GetQuery();
var entityParam = Expression.Parameter(Column.Table.EntityType, "row");

// row => row.Property
var columnLambda = Expression.Lambda(Expression.Property(entityParam, Column.EntityTypeProperty), entityParam);

// Items.Select(row => row.Property)
var selectCall = Expression.Call(typeof(Queryable), "Select", new Type[] { items.ElementType, columnLambda.Body.Type }, items.Expression, columnLambda);

// Items.Select(row => row.Property).Distinct
var distinctCall = Expression.Call(typeof(Queryable), "Distinct", new Type[] { Column.EntityTypeProperty.PropertyType }, selectCall);


// colvalue => colvalue
var sortParam = Expression.Parameter(Column.EntityTypeProperty.PropertyType, "sortValue");
var columnResultLambda = Expression.Lambda(sortParam, sortParam);

// Items.Select(row => row.Property).Distinct.OrderBy(colvalue => colvalue)
var ordercall = Expression.Call(typeof(Queryable), "OrderBy",
new Type[] { Column.EntityTypeProperty.PropertyType, columnResultLambda.Body.Type },
distinctCall, columnResultLambda);

var result = items.Provider.CreateQuery(ordercall);

foreach (var item in result) {
if (item != null) DropDownList1.Items.Add(item.ToString());
}
}

"Sub-optimal" is a programmer euphemism for crappy, hard to read, code that works. But what price my immortal soul?

Fortunately, Marcin from the ASP.NET team decided to come out of his apparent blogging vow of silence (lasting 18 months, no less) to save me.

Marcin points out that there's a sample from 2006 released under the Ms-PL (how is anyone supposed to know this?) called DynamicQueryable. You actually have this on your hard drive NOW. It's under  Samples\1033\CSharpSamples.zip\LinqSamples\DynamicQuery\DynamicQuery in your VS install directory.

In fact, His Gu-ness blogged about this in January of 2008 giving this VB example:

Dim Northwind As new NorthwindDataContext
Dim query = From p In Northwind.Products
Where p.CategoryID = 2 And UnitPrice > 3
Order By p.SupplierID
Select p
GridView1.DataSource = query
GridView1.DataBind()

But using the DynamicQuery library you can express the same thing like this, allowing for more dynamism. (Is that a word?)

Dim Northwind As new NorthwindDataContext
Dim query = Northwind.Products
.Where("CategoryID=2 And p.UnitPrice>3")
.OrderBy("SupplierID")
GridView1.DataSource = query
GridView1.DataBind()

Again, this works great when you don't know every input ahead of time. Marcin says:

DynamicQueryable is quite powerful and includes the following

  • Dynamic string-based querying of any LINQ provider (late-bound versions of Where, Select, OrderBy, Take, Skip, GroupBy, Any, and Count extension methods)
  • String-based mini expression language (like the “it” identifier in the sample below), including complex conditional statements and all operators
  • Dynamic creation of classes for projections

Now Marcin was able to rewrite my pile of Expression crap above into this luscious four line snippet. The DynamicQueryable magic is the "var result =" line.

protected void Page_Init(object sender, EventArgs e) {
var items = Column.Table.GetQuery();

var result = items.Select(Column.EntityTypeProperty.Name).Distinct().OrderBy("it");

foreach (var item in result) {
if (item != null) DropDownList1.Items.Add(item.ToString());
}
}

ScottGu also points to Joseph and Ben Albahari, authors of the C# 3.0 In a Nutshell book and their incredibly deep post on building type-safe predicate methods. Their PredicateBuilder is free in the LINQKit extension library and can really help out when you get even deeper into this topic.

Oh, and seriously, stop what you're doing now and go download LINQPad, the Albahari's most wonderful gift to us all. Then, thank them, and tell them how awesome they are.

Enjoy!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes on 9 - Follow up, 6 months later, On Managing People with Chris Sells

January 21, 2010 Comment on this post [6] Posted in Microsoft | Musings
Sponsored By
STO Ninja Logo - A square with a little Ninja Dude insdeSix months ago when my role changed a bit, I took Chris Sells to lunch at our local food court (where the lady at the Indian Restaurant always shakes the big piece of chicken off her serving spoon before she dishes my plate, but I'm not bitter) to talk about being a successful manager at Microsoft.

You might watch that short video from August of 2009 first, if you haven't seen it, before you watch this follow up.

I've led teams of developers on projects, but never done the whole HR thing in a large hierarchy. When I was Chief Architect at Corillian (about 450 people) I reported to the CTO but the VP of Engineering handled the human resources aspects of management and I focused on technology and strategy.

Chris leads a team at Microsoft and seems to get a lot done, so I figured it'd be a good idea. Check out our FIRST video interview from the August 2009 lunch here, then watch this FOLLOWUP Lunch from yesterday (about six months after the first) where I at first admit defeat, then go back into being in denial, then I leave to redouble my efforts. Enjoy the Wisdom of Chris Sells as he attempts to set me straight.

"Developers at Microsoft write code. Program Managers at Microsoft delete email.*"

Part 2 - Follow up with Chris Sells on Managing People - January 2010

 image

Part 1 - Chris Sells on Managing People - August 2009

Enjoy!

* Joke. We also move email into folders and schedule meetings.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

How many PCs in the world have the .NET Framework installed?

January 20, 2010 Comment on this post [43] Posted in ASP.NET | Learning .NET | Microsoft | Win7 | Windows Client | WPF
Sponsored By

image I did a second .NET Framework features informal poll recently, and as with all .NET related polls the question comes up: How many PCs have the .NET Framework on it?

If you're a company that is considering creating a client application using .NET (not Silverlight, but the .NET Framework) you'd probably like to know if your end-user needs to install something extra to use your app.

So I started asking questions. We've said things here and there about the pervasiveness of the .NET Framework but I wanted to get the final word (at the time of this writing) and put it somewhere easy to fine.

After some digging, here's what I've got:

  • Well over 90% of the PCs in the world have some version of the .NET Framework installed.
  • Over 65% of Windows PCs in the world have .NET 3.5 SP1 installed.

This is a lot higher than I thought, and it's pretty cool.

The .NET Framework is smaller than you'd think (that's why I wrote SmallestDotNet). The very small .NET 4 Client Profile makes it easier (both speed and download size) to put .NET on a machine.

I think these numbers will help folks who might be considering using .NET for a client application.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.