![]() |
|
Spaces home red hot place ProfileFriendsBlogMore ![]() | ![]() |
red hot place |
|||||||||||||
|
July 04 Extension Methods and LINQI know very little about the new features of C# 3.0 and LINQ. I’ve been playing around with it a little bit and was puzzled by how it all works. This is probably old news for a lot of people, but it’s all new to me. For instance, let’s take the simplest possible query:
Trying to compile, I got this compiler error:
You might get this error if you’re missing some references (as the error message says). I was getting it due to some other external issue. But in trying to fix/investigate the issue, I first tried to figure out what exactly the compiler was doing behind the scenes. The method ‘Where’ isn’t available on IEnumerable or Array, so it seemed like a valid error. What was I missing? I couldn’t find any good information online as to how the compiler actually takes the LINQ syntax and generates code that resembles something more IL-ish. There are plenty of sample queries online, but I couldn’t find any good site that really explains how it all works. So after a bunch of digging I managed to piece together that the compiler actually translates the above query to something like this:
Interesting. That kind of explains where the error message is coming from. But still, I couldn’t for the life of me figure out how the heck this worked. There’s no ‘AsQueryable’ method on Array or IEnumerable, or ‘Where’ on IQueryable either. Where are these methods coming from? It turns out that the compiler further translates the query to something like this:
How the heck?! Where did the Queryable class come from? Apparently there is this new concept of “extension methods” in C#. You can add methods to existing types without creating a new derived type, or recompiling, or modifying the original type. Wow!! Far out!
System.Linq has a static class ‘Queryable’ that does exactly this; it extends IEnumerable and IQueryable<T>.
All you have to do is add the directive “using System.Linq;” to take advantage of this functionality. Check out the rules on how to implement a custom extension method. And now it all makes sense. Very cool! May 22 Entertain the Cat
It's pretty cool to see what people can do (or dream of doing) with the things you've built. I've been trolling the Live Mesh forums on and off, and so far, my absolute favourite thread has been one entitled "Entertain the cat" (reproduced here).
I especially love how Bleak Morn's post is the Proposed Answer. May 06 Hello, World!Mike Zintel's got an excellent post on the history of the computing world, entitled "Why Sync?" It's an engaging read. I'm struggling to properly excerpt. Go read the whole thing. May 04 yang on yahoo!
I've never followed Yahoo! much, though I just read Jerry Yang's memo to Yahoo! staff. Apparently he's never heard of the 'Shift' key. Does anybody else feel that it's incredibly hard to read? It turns out this is old news, but I just noticed. Yuck! At least Ballmer can write intelligibly, even if he does prance around on stage like a monkey. April 23 ‘Live Mesh’ Unveiled!Finally! In April 2006, I decided to leave my job on Messenger Server to join a completely new start-up team within Microsoft. It was a pretty big change for me, as I went from a well established team with millions of users, to being one of the first three developers on a team with nothing but a dream of what was to be. I couldn’t talk about what the team’s charter was, as it was all under wraps, even internally within the company. My business card had the somewhat cryptic team name. Exactly two years and three weeks later, we are finally launching a Tech Preview and I can finally talk about (some of) the stuff I’ve been working on for the past two years. What a relief! I can’t believe it’s been such a long time. I won’t talk about what I think Live Mesh is yet. You’ll find a great deal of information on the Team Blog, as well as videos on Channel 9 this week (Ray's interview is a good one). I can’t do justice to what Mesh is by excerpting, so please go read our GM Amit’s post. It gives a good idea as to what exactly Mesh is. We’re only launching a Tech Preview at the moment, so there’s a limited number of invites. Hopefully you’re well connected enough to get someone to share with you. If you’re already provisioned in the system, feel free to share stuff with me by inviting me to a “LiveFolder.” I’d love to see what people are using Mesh for! April 16 RevampedSo 2⅔ years after creating this blog on a whim, I have decided that I should finally update the colour theme and layout. Though I liked the red and black contrast with the flame background, I realize that it made for horrible reading on the eyes. (If you missed it, it kind of looked like this, except the fonts were smaller.) It was pretty fugly. I can't say that I really cared, since I could count my audience on one hand, and most of them were reading in a feed reader anyway. I've picked another one of the default Spaces themes that's a little easier on the eyes, and tweaked it ever so slightly. Of course, I've kept the flames as my profile image too. What do you think? I'll probably continue tweaking over the next several weeks (like adding a module or two). I hear rolling thunder. April 09 Date TimeI do many more things than batch scripts all day, and someday (soon) I'll blog about some of that stuff, but for now, this will have to suffice. I had several lines of batch code I created several years ago that created a unique filename from the current date/time with the help of two environment variables:
So the code I had:
gave a nice:
which would allow you to sort files by filename in chronological order. It worked quite well and I had used it for years. Recently though, I started seeing some weird behaviour from some people.
This left me scratching my head for a while, until I asked one of these people to run the following on their machine:
Gosh darn those locale settings! It's not enough to handle just this specific case, as in Canada for instance, dates are written DD/MM/YYYY as opposed to the US's MM/DD/YYYY. So I went online and found all sorts of strange ways to figure out the format of the date. The best way I read of, to get locale was by crawling through the registry. I wasn't particularly motivated to do this, so left it at that. Fortunately this particular script got deprecated in favour of new one I wrote that didn't require date/time uniqueness. Saved! March 21 Progressive DotsI just found out about this (thanks to Live Search!) from a fellow Canadian's blog entry "batch file snippets" and it's got me super excited. Haven't you ever found it annoying that you can't print to a line without a newline (carriage return/line feed) in a batch script? (At least, I didn't know how to.) Well, now you can! For instance:
would give you:
as opposed to a progressive:
So what you actually want is:
Don't tell me that's not cool! How does it work? The '/p' option given to set is asking for user input:
The key is that it prompts for input *on the same line*! And by redirecting the NUL device into it, you get an immediate return. How absolutely clever. I love it! March 18 To Sync, or not to Synch?I tend to nitpick. I have a bit of OCD when it comes to grammar and spelling. I cringe when people use "it's" instead of "its" or "your" instead of "you're".* I find it distasteful that people allow themselves to butcher a language (though I suppose non-native speakers can be given a bye). So it's not surprising that I have fairly strong feelings about the abbreviation for the word "synchronize" (or "synchronise", as you prefer). It really bothers me when people write "synch". I realize that both "sync" and "synch" are commonly accepted abbreviations; however the latter irks me to no end. Why? I read "synch" as rhyming with "lynch". I realize that there are words that end with -ch with a hard 'k' sound (say, "loch"), but how many words end with -ynch (or -inch) with a hard 'k' sound?! If you're going to cut a word in half, at least have the decency to do it so that it follows general conventions of pronunciation. I do also realize that languages are a fluid subject that are influenced by many factors. (I hate the impact texting has had on the language--'IMO'.) Here's an interesting tidbit from The American Heritage Book of English Usage:
[ Interestingly enough, I don't really like using the abbreviation in the present participle as in, like "syncing". I tend to write "sync'ing" to denote the abbreviation, though I recognize that this is definitely my own oddity. ] * NB. Some smart aleck will point out that periods and commas go inside the quotation marks. I, for one, despise this notation, and as this is apparently only a US custom and not generally followed in the UK or Canada, I take the liberty not to do so for my own edification.
|
||||||||||||
|
|