LINQ's relationship to the new language features

Tue, July 31, 2007, 03:43 AM under Orcas | VisualStudio | LINQ
If you are interested in understanding the relationship of the new C#3 and VB9 features to LINQ, then watch my 20' screencast and let me know there if you have any questions (unlike other videos, I advise you not to speed it up, because I speak very fast as it is ;)).

System.Core.dll minor changes in Beta 2

Mon, July 30, 2007, 04:28 PM under dotNET | Orcas
System.Core.dll (one of the new 3.5 assemblies) has tons of types as you'll recall, so I thought I'd see if anything changed between Beta 1 and Beta 2.

First, do not panic when you open up System.Linq namespace and you do not see the Func delegates. They are still in the assembly but they moved to the System namespace and they also have new friend delegates with various overloads called Action, which are the equivalent of Func but with no return type (all of those changes make perfect sense if you ask me).

The System.Management namespace (with the 20 types inside it) has been renamed to System.Management.Instrumentation. Do not confuse this with the separate, same named assembly that is part of Fx 3.5.

There have also been some small changes to the System.Expressions namespace so revisit your code if you were using those (typically for writing your own LINQ provider).

Finally, the BigInteger is still marked as internal so I personally am giving up hope of seeing it make a come back...

Version and location changes in Beta 2

Mon, July 30, 2007, 02:10 AM under Orcas | VisualStudio
With Visual Studio 2008 Beta 2 some (good) changes were made to the location and versions of the .NET 3.5 assemblies, which previously were quite inconsistent (two additions were also made and I updated the previous post with those).

The .NET folder under Windows (C:\Windows\Microsoft.NET\Framework\) does not include a build number in its name now, it is just "v3.5" (with Beta 1 it was "v3.5.20404"). If you had explicit references to that location (e.g. in code, config files etc) you will have to change them.

The file versions of the v3.5 assemblies is now 3.5 (that was not the case previously for all of them). They still differ slightly between them on the build number but at least most[1] of them are now in the same place and you can see that in the following partial screenshot of "c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\"


Now with Beta 2, the assembly version numbers are more consistent with each other (and different to the file versions of course). You can see those using your favourite disassembler, or simply via the VS references dialog:


As a reminder, to understand what each one of these assemblies offers, see my blog entry on the green bits.

[1] In the 3rd paragraph above I wrote "mostly" because there is one assembly that is not in that same place: System.DirectoryServices.AccountManagement.dll is one level up in the folder hierarchy (!). So to reference this one you have to browse explicitly to that path from the VS references dialog. Its file version number is consistent with the rest (3.5.20706.1) and its assembly version is 3.5.0.0

Organize Usings in VS2008

Sun, July 29, 2007, 12:06 PM under Orcas | VisualStudio
In my demos you will never find superfluous using statements at the top of code files. When I am trying to explain some new API, I want it to be very clear what namespaces are being used. I have seen many other presenters that leave in there every namespace under the sun and it always annoys me. The other thing I try and do is remove references to assemblies that I am not using (for the same reasons). In fact, I used to do both of these even in real projects; even though there are zero performance implications for either, it just felt cleaner to me.

Now with VS2008 the manual process of removing namespaces is taken care for you. Simply right click in a code file and you see a new option as shown here:


Great! I am not so sure about sorting though. It sorts alphabetically and perhaps that is a good idea now that I think of it, but I am used to sorting my namespaces by length from shortest to longest so a nice triangle is visually formed (yes, I am weird, I know). More seriously, I usually just leave the last namespace I imported appear at the bottom of the list...

The sad thing is that this feature only takes care of using statements and NOT of assembly references as hinted in my opening paragraph. The ironic thing is that while this is a new C#-only feature, in VB (even with VS2005) you can indeed remove unused assembly references from the project properties. If only the two teams talked to each other and both decided to implement the other's complementary feature...

Open Beta 1 solutions with Beta 2

Sun, July 29, 2007, 10:11 AM under Orcas | VisualStudio
One of the annoying things on my machine after installing Beta 2 was that my existing Beta 1 solutions would not open by double clicking on them. I could open them from within Visual Studio and I could open project files by double clicking on them, but not sln files created with Beta 1.

If anybody else is facing this, my solution (pun not intended) was to open the solution file in Notepad and change the second line from:
# Visual Studio Codename Orcas
to
# Visual Studio 2008

If only everything was this simple...

Allow app to host WPF add-in

Sat, July 28, 2007, 03:03 AM under dotNET | Orcas
I noticed a new green assembly has been added to Beta 2 of .NET Framework 3.5: System.Windows.Presentation.dll.

Curiocity got me digging and it appears that it adds some infrastructure support in order for the Managed AddIn Framework (MAF) to work with WPF apps... FYI, also mentioned here.

VS2008 Installation experience

Fri, July 27, 2007, 03:49 AM under Orcas | VisualStudio
Before installing anything these days, I always explicitly run Windows Update. The last thing I want is for an update to kick off in the middle of an install. I encourage you to do the same!

My first attempt to install Beta 2 Professional edition was to be optimistic and install it over Beta 1 on my Vista machine. This dream ended as soon as I run the setup:

So I went to the "Programs and Features" page in control panel and removed "Visual Studio Codename Orcas", which removed a whole bunch of other related things. I then run the setup again and life was good:


After clicking "Install" on the dialog above, the first item that the setup tries to install is .NET Framework 3.5. This took absolute ages on my machine (over 10 minutes). Midway through it was obvious that it had invoked Windows Update because Windows Update gave me the message that it wanted to restart my machine. I thought I'd play it safe (and advise you to do the same) so I selected "Postpone for 4 hours" on that dialog. I then waited and eventually the VS2008 setup informed me that a reboot was required. Of course, I accepted that one. After Vista rebooted the setup continued automatically with no intervention on my part. Apparently, some people (without admin accounts) have to start it manually again so your mileage may vary.

So what was the Windows Update thing that was invoked by the setup, especially since I had manually run windows update before? That is the Service Pack 1 for v2.0 and v3.0 of the .NET Framework (fyi, explanation of red bits). The setup knows where to go and look for them and right now they appear as hotfixes: KB929300 and KB110806.

After that, the rest was as smooth as peanut butter (the smooth variety, not the chunky one).

LINQ to DataSet

Thu, July 26, 2007, 06:52 PM under Orcas
Another LINQ implementation that will ship with Fx 3.5 is LINQ to DataSet (not to be confused with LINQ to SQL).

LINQ to DataSet is about offering a strongly typed in-memory query language for DataSets - it is not for creation of DataSets or for smoothly updating the back end. So, if you are already using DataSets in your applications (inc. mobile applications), keep on reading.

If you tried LINQ to DataSet before Beta 2, then you had to reference System.Data.Entity.dll. This assembly is where the new Entity model lives, which will not ship at the same time as VS2008, but instead will ship soon after. Since LINQ to DataSet will ship with VS2008, its implementation had to be relocated. Its new home is System.Data.DataSetExtensions.dll (and it has a bunch of new types and members compared to the pre-Beta2 implementation!).

In this new assembly you will find a single namespace (System.Data) that contains a total of 9 types. Of these 9 types, 6 are used by the infrastructure and are not intended by direct explicit use by you. I have captured these 6 in this class diagram here. Now, think about what you need in order to use the LINQ syntax with the DataSet... not much really. Since DataSet is an in-memory object, the existing implementation of LINQ to Objects is heavily leveraged. However, in order to make things as friendly as possible, some helper intermediate types are used when we compose our queries and when generating strongly typed datasets – as application developers we don't have to worry about them. These intermediaries is what the previous class diagram shows.

When typing your LINQ queries, you have to sometimes convert from the types that the DataSet uses (e.g. a strongly typed DataTable) to types that LINQ likes using (e.g. IEnumerable). Combine that point with the fact that your queries are likely to be at the DataRow or DataTable level and you realise that what you need is some extension methods to help. That is what the remainder 3 types in the assembly are there for, and you should familiarise yourself with those extension methods to make the best of LINQ to DataSet. Use the following class diagram as food for thought before delving into the code:

For example, calling AsEnumerable on a DataTable makes it fit and compile under the query pattern. For example, calling AsDataView on the results of a query, gives you something you can databind a grid with, make changes and then use for updating the back end (a bit of a roundabout way, but it works). For example, rather than use strings and casting and have to deal with nulls at runtime, you can use Field to do the casting for you and convert to a nullable type. See the following quick example that assumes you have a dataset with data and a datagridview on a form:
var results = 
from o in dataSet1.Tables[0].AsEnumerable()
where o.Field<string>("City" ) == "Hove"
select o;

dataGridView1.DataSource = results.AsDataView();

For more background on LINQ to DataSet, see this 3-part series written on the ADO.NET blog back in February: Part one, part two and part three.

There is also a recorded webcast from May which you can view on-demand here. The first 3 minutes are good for setting the scene of why LINQ-enabling the DataSet is important. The following 17' is a generic intro to LINQ so if you are familiar already feel free to skip. From the 20th to the 40th minute are 3 demos where you can see it in action. I'd suggest stop watching after that (i.e. miss the 4th demo) because the feature it shows is not implemented like that in Beta 2 and later. To get the 3 aforementioned demos, visit Erick's blog (and stay tuned there for updates to the LINQ to DataSet story).

VS2008 Beta 2 with go live license

Thu, July 26, 2007, 02:23 PM under Orcas | VisualStudio
The moment we've all been waiting for: Visual Studio 2008 Beta 2 hits the streets so get it now

This one has a go-live license associated with it which means that the team are confident about the quality of the product and also about the final feature set. Apparently, you will be able to go smoothly from this version to the RTM version later this year. All changes between this one and the RTM version will be documented, they say. What I can tell you from personal experience is that this build is very solid and has not malfunctioned on me once in the last X days that I've been running it.

You have no reason to wait any longer, go download it and start using it for your existing v2.0/v3.0 projects and later consider taking advantage of the new v3.5 features. Remember, VS2008 has everything in the box :-)

Our survey says... Mix:UK 07

Wed, July 25, 2007, 08:15 AM under Events
After the huge MIX event held in Las Vegas in May, dozens of great RE-MIX events followed around the world. In almost all of them, the content from the main MIX event was taken and delivered via mostly some local speakers presenting the existing material. You didn't need me to tell you that, the title of those events gives it away: RE-MIX.

Here in the UK we opted for a different approach. We waited (and waited) and found the perfect time to hold our 2-day MIX event: September 11 and 12. The reason we waited is that we wanted to have some fantastic announcements to make in addition to whatever took place in Vegas (and we do have some cool announcements in that timeframe!) and also we wanted to create new original content. That also explains that we are not RE-delivering content and the actual title of our event is Mix:UK

Today we opened registration. Spaces truly are limited (I think we missed a trick there by not finding a larger venue) so, for opportunities such as seeing Scott Guthrie delivering a few sessions, REGISTER NOW.

Also, the NxtGenUG boys would like you to fill in a free quick survey for the 'Swaggily fortunes' game taking place at Mix:UK – attending is not a prerequisite for completing the survey. You may even win a prize just by answering a few questions and remember that the answer to question 6 is Daniel Moth, go fill it in.

Facebook from .NET

Tue, July 24, 2007, 03:20 PM under MobileAndEmbedded | Links
It looks like the world has gone crazy with this Facebook thingy. I have zero time for real socialising let alone for online socializing so I have ignored the whole thing. By "ignored", I mean I have acted on invitations (meaning I had to create my space or whatever it is called) and other things that come into my email inbox, but I have not customised anything or initiated connections/invitations or even uploaded a photo. So why am I talking about it here?

It turns out that there is a .NET API for Facebook! It also looks like supreme device developer and all around top geezer, The Foot, has started porting it to support the .NET Compact Framework. Check out his blog post for more (which follows on from this one that includes screenshots).

Class Designer for C++ in VS2008

Mon, July 23, 2007, 01:54 PM under Orcas | VisualStudio
One of my top 3 favourite features when VS2005 came out was Class Designer (blogged about it 3 years ago). With VS2008, I cannot say there are major enhancements for the Class Designer, but now it is partially supported for C++ projects as well. The team is asking for your feedback so go give it while it's hot.

Vista ComboBox

Fri, July 20, 2007, 05:30 AM under Windows | Vista
Over time I've talked about XP and Vista textbox cue banners (and even implemented a version for Windows Mobile), but I hadn't realised they can be used for Vista combo boxes as well! The clue came via Kenny's MSDN mag article (includes many other features for the C++ Vista developer).

So all I had to do was the simple translation to managed code, which involves one line of code (assuming you have a combobox on your form with a few items to select and none set as selected):
SendMessage(comboBox1.Handle, 0x1703, 0, "Choose"); //CB_SETCUEBANNER

From left to right in the image above: Before the API call, before the call and the drop down open, After the API call, after the call with the drop down open. Of course once you select a real value from the combobox you do not see the cue banner (e.g. "Choose") again.

FYI, I actually found that any value for the two ComboBox properties DropDownStyle and FlatStyle worked, and the ones in the image above are DropDownList and System respectively.

Duck Typing

Thu, July 19, 2007, 03:15 PM under Links
Not sure how this term managed to escape me up to now, but it did. Simple stuff like this fascinate me. From wikipedia:
"In computer science, duck typing is a principle of dynamic typing in which an object's interface and attributes determine valid semantics, rather than having the language enforce rules regarding inheritance or require type casting."

Found via Krzysztof where he discusses Duck Notation.

WISP Lite in WM6

Wed, July 18, 2007, 04:33 AM under MobileAndEmbedded
A little known brand new feature in Windows Mobile 6 is the ability to do inking using the same technology as for the Tablet PC (Windows Ink Service Platform). Luis talks about it on the WM blog with a code example. One of the commenters of that blog post asked for a managed version (I don't blame him; in this day and age what was the WM dev team thinking?!). To get a managed version (and a bit more info on the API) go to Alex's blog and look for the hidden links.

Sidebar shortcuts

Tue, July 17, 2007, 06:36 AM under Windows | Vista
You know of course that WindowsKey+D shows the desktop and this includes hiding the Sidebar. If you want to show the desktop but still have the Sidebar (and any floating gadgets) visible then hit Win+M. If at any point you need to bring on top the Sidebar and gadgets regardless of what other windows are showing, hit Win+Spacebar.

Now the new ones I only learnt this week (shame on me I know): Win+G will cycle through the gadgets and while a gadget is selected, Shift+F10 will bring up the context menu. Am I missing any other relevant shortcuts?

Windows Mobile Security for devs

Mon, July 16, 2007, 04:41 PM under MobileAndEmbedded
Via David I found this WM security blog post and via that I found this old but great WM security article.

After you consume the info above (and most of my trusted mobile dev readers will already know that stuff) then you are left craving for a pretty and concise diagram that illustrates the flow of an app's execution on Windows Mobile. I hope your craving is satisfied with the following (thanks Mark!):

At some future point you should expect to see the diagram linked somewhere from this excellent page of security resources for Device Projects.

Contacts.Net

Mon, July 16, 2007, 04:26 AM under Windows | Vista
It looks like the number of managed wrappers to the 7000 new native APIs that Windows Vista introduced is growing. I recently discovered a library that wraps the COM API for working with Vista's Contacts. To download it (inc. the source code) and for other relevant links, please visit the codeplex project.

Found via uberdemo.

Web development for Mobile

Fri, July 13, 2007, 09:06 AM under MobileAndEmbedded
Occasionally I get people asking me about developing web apps that are accessible from Windows Mobile. Every time I explain how with something as powerful as the .NET Compact Framework, they should be writing smart clients on the device that can also work in offline mode, cache data and offer a richer user experience. These apps can then access their server as needed either via web services or via some kind of SQL synchronization mechanism if that is what they are using on their backend. Some people insist though on offering a suboptimal solution to their customers so what answer do we have for those? Head over to Thom's blog to explore Mobile Web Development with ASP.NET.

A related question I hear is "what capabilities does Pocket Internet Explorer (PIE) offer?". Well, it is not called that anymore, it is IE Mobile and there is a homonymous blog. Visit their blog for tons of useful info, including the standards support in IE Mobile.

Finally, one of the co-authors of my book wrote in the distant past a book on mobile web dev that you may be interested in.

PS: Might as well link to my answer for the often asked question about Silverlight for Mobile.

What do I plan to do over the next 6 months to become a better developer

Fri, July 13, 2007, 04:29 AM under Career
After not doing memes for over 2 years, I broke my rule last December and yesterday; today I notice another one where I got tagged (thanks Raymond). So, this is the last meme I am doing for the rest of the year. Now I must tell you what I plan to do over the next 6 months to become a better developer (the format seems to be random so I'll take a wordy lengthy approach).

Well, I've never been involved in a large team project (>20 people), but I have delivered multiple projects (through multiple versions) where the team ranged from 1 to 12 people so I have drawn some conclusions for small projects (at most 100K loc) including the following 3 facts:

1. You do not need formal education or certifications to be a good developer; you just need a logical mind and a genuine interest in the field (and to be lucky enough to work on a handful of projects with talented people that are interested in mentoring you).

2. No matter what process/methodology/best practises/etc you use, the bottom line is that good talented people with a clear vision will deliver good results; the rest simply will struggle.
Another variation of striving for those things is when a talented good developer thinks he can improve others by sharing his knowledge via a methodology, when actually if his team has talent they'll get it right and if they don't then the rules won't help them either. Funny how the people touting a methodology are the ones that can make things work even without it..

3. If you don't understand the technical platform you are working with then you are probably going to be doing things in a suboptimal way and trying to fit old patterns to new paradigms.

Your mileage will vary of course, depending on how long you've been in the industry and the kind of projects you have worked on. I am certainly not projecting the above assertions on you, simply stating that for me personally, they hold true as facts. Moving on (hopefully without pissing too many people off ;)...


Considering points 1 and 2 above, I made the decision a little while back that I am as good/bad a developer as I was at that point and that I was not going to drastically improve/deteriorate from an algorithmic/design/management/performance point of view as years go by. Combining this decision with point 3 above, I decided that the only thing I need to do to stay at the level that I am today, is to keep abreast of all the new technologies that get thrown out from the various vendors. A long time ago (when funnily enough I was a Java developer) I decided to choose and commit to one vendor only: Microsoft.

To bring this blog post back to the meme and in conclusion, my personal choice as a developer is: Stay current with everything new on the Microsoft platform. That is what I've been doing for the last 6 months and this is what I am going to do for the next 6 months.

As to which bits of the Microsoft offerings I specifically focus on, well that varies and this blog is my documentation/sharing vehicle for some of the bits I play with... There is a pattern as to the things that interest me and you can infer that from the Categories on the left of this page. Hope this helps and stay tuned via one of the subscribe options also on the left :-)

In the spirit of the meme, I wonder what these guys' professional plans look like over their next 6 months:
[ Ian, Kenny, Mitch, Phil ] you are IT!

Off Topic: 8 random things about me

Thu, July 12, 2007, 05:51 AM under Random
This meme is very similar to the one from last year, but what the heck... Eileen tagged me so here goes:
1. Born in Germany (Rinteln), grew up in Greece (Thessaloniki), live in UK (Hove).
2. Football team I support: Manchester United. Team I supported in Greece: PAOK.
3. Lost my father when I was a baby.
4. As a child I was (very briefly) a boy scout.
5. As a kid I was a massive Bruce Lee fan. When I visited Seattle for the first time, my must see place was Bruce Lee's grave (with Brandon beside him).
6. I trained in Tae Kwon Do (combined with Okinawa) up to red belt. My teacher was the teacher and father of the recent Greek Olympic medallist (Nikolaidis).
7. As a teenager I was a huge The Doors fan. When I went to Paris for the first time, my must see place was Jim Morrison's grave.
8. Last Sunday I saw old head-bangers Metallica at Wembley (ears still buzzing, neck still hurts)... This was in Microsoft's executive box ;-)

I was very tempted to kill this meme here, but instead I'll tag 8 people as mandated (not the same ones as last time) so they can list their own 8 random things about them:
Craig, Eric, Loke Uei, Martin, Mike, Neil, Nick, Steve.

Parallel LINQ

Mon, July 9, 2007, 09:43 AM under ParallelComputing | LINQ | Links
Having done a lot of real world work with threading in the .NET Framework including working with the numerous limitations of NETCF v1.0 (inc. implementing the BackgroundWorker for it), I read with interest Sam's parallel computing blog post to see what links there would be in there and I wasn't disappointed. Check it out if you are new to threading in the managed world. That reminded me about a related topic that I keep mentioning at the end of my LINQ presentations and that I've been meaning to blog about in response to Tim's question: Parallel LINQ (PLINQ).

One of the numerous benefits of LINQ is the move to declarative programming, which has side benefits over and beyond the obvious ones. By writing code that tells the engine what it is that we want it to do rather than how to go about it, we open new possibilities where the engine can take our intent and split/execute it on multiple threads/cores (since ultimately it is responsible on the how). While most devs "get" that, it may sound a bit woolly to others, so here are some links/info about PLINQ.

I believe the first mention of PLINQ is in this eWeek article (August 2006). Joe Duffy announced his involvement (September 2006) and then followed it up with more info and a slide deck (January 2007). Bart watched a presentation on the topic and spills the beans on the AsParallel extension method which he follows with a NON-Plinq code example (April 2007). Finally, watch a real 5' demo by Luca from Tech Ed [between 51:26-56:40] (May 2007).

Of course, it is early days and PLINQ will not ship with VS2008 (or even as part of the wider Orcas-wave) but you get the idea... The earlier you start taking advantage of LINQ, the earlier you'll be able to take advantage of PLINQ when it eventually ships ;)

MSDN Flash newsletter

Wed, July 4, 2007, 03:11 PM under Links
If you are a developer on the Microsoft platform you should subscribe to the bi-weekly MSDN Flash newsletter to keep up to date with the latest news. The newsletter is available in the US and most other countries translate it to their own language so you can subscribe to a localised version if you wish. Check your local MSDN website. In the UK we have had our own version for a very long time and a couple of months ago I took over as the editor. After soliciting feedback from numerous people in the community we have streamlined the UK MSDN Flash newsletter to make it much more digestible and very easy to scan for info relevant to you. I also personally ensure that the content is aimed squarely at developers with no other noise.

If you are a developer in the UK, I urge you to subscribe to the MSDN Flash (you can unsubscribe from the same place at any time and your email isn't used anywhere else). Even if you are outside the UK, 3 out of the 5 sections are still useful ;)

For a taste of what you've been missing go check out the latest issue. Let me know what you think and I am also interested in what you like in other developer newsletters that you may subscribe to!

33

Mon, July 2, 2007, 06:14 AM under Personal
Rather than a deceitful title like last year, this time it tells the truth. I am 33 today (and noticed a few grey hairs on the sides above my ears... wisdom at last :)).