Site: http://msmvps.com/blogs/jon.skeet/archive/category/1668.aspx Link: http://msmvps.com/blogs/jon.skeet/rss.aspx?CategoryID=1668
by skeet via Jon Skeet's Coding Blog : C# on 3/31/2008 3:16:29 PM
Resources: Book's web site (includes various tools such as LINQPad) Amazon Errata Introduction The original C# in a Nutshell was the book I cut my C# teeth on, so to speak. Basically I read it (well, the bits which weren't just reproductions of MSDN - gone in this edition, thankfully), played around in Visual Studio, and then started to answer questions on the C# newsgroup. (That's a great way of learning useful things, by the way - find another person's problem which sounds l ...
[ read more ]
by skeet via Jon Skeet's Coding Blog : C# on 3/21/2008 8:30:15 AM
Resources Book's web site Amazon page Errata Introduction This is a tough review to write. We already know I'm biased due to being in some way in competition with Andrew Stellman and Jennifer Greene (the authors), but I'm also not a huge fan of the Head First series in general. It doesn't coincide with how I like to learn. I feel patronised by the pictures and crosswords rather than drawn into them, etc. However, I'm very aware that it's really popular - lots of people ...
by skeet via Jon Skeet's Coding Blog : C# on 3/17/2008 12:40:04 AM
Introduction Let me make one thing very clear before anything else: this is a preview. Bruce Eckel has made the preview of what appears to be part of a bigger book available free from his website. The book is by Bruce Eckel and Jamie King, and the preview available (1.0 at the time of writing) covers the following topics: Extension methods Implicitly typed local variables Automatic properties Implicitly-typed arrays Object initializers Collection initializers Anonymous types Lambda expre ...
by skeet via Jon Skeet's Coding Blog : C# on 3/15/2008 11:02:29 PM
(I'm giving up with the numbering now, unless anyone particularly wants me to keep it up. What was originally going to be a limited series appears to be growing without end...) As Chris Nahr pointed out in my previous post, my earlier idea about staged initialization was very half-baked. As he's prompted me to think further about it, I've come up with another idea. It's slightly more baked, although there are lots of different possibilities and open questions. Let's take a st ...
by skeet via Jon Skeet's Coding Blog : C# on 3/2/2008 7:54:44 PM
Iterator blocks have an interesting property: they defer execution. When the method (or property) is called, none of your code is executed - it only starts running when MoveNext() is first called. Deferred execution is a great thing in many ways, but it's a pain when it comes to parameter checking. If you check parameters within an iterator block, you've effectively left a timebomb - the error will be potentially reported a long way from the original source of the problem. (Side-note: th ...
by skeet via Jon Skeet's Coding Blog : C# on 3/2/2008 7:05:27 PM
Hopefully most readers are familiar with the yield break; statement. Usually, if it appears at the end of a method its a no-op which can be removed with no change in behaviour. For instance: public IEnumerable<int> Range1 (int start, int count) { for (int i=0; i < count; i++) { yield return start+i;   ...
by skeet via Jon Skeet's Coding Blog : C# on 2/28/2008 12:32:18 AM
When talking about LINQ recently, I doodled an implementation of OrderBy on a whiteboard. Now, I know the real OrderBy method has to support ThenBy which makes life slightly tougher, but let's suppose for a moment that it didn't. Let's further suppose that we don't mind O(n2) efficiency, but we do want to abide by the restriction that the sort should be stable. Here's one implementation: public static IEnumerable<TSource> OrderBy<TSource,TKey> &nb ...
by skeet via Jon Skeet's Coding Blog : C# on 2/26/2008 8:16:28 PM
I've been thinking about ranges again, particularly after catching a book error just in time, and looking at Marc's generic complex type. It struck me that my previous attempts were all very well, and demonstrated parallelisation quite neatly, but weren't very LINQy. In particular, they certainly didn't use LINQ for the tricky part in the same way that Luke Hoban's ray tracer does. The thing is, working out the "value" of a particular point in the Mandelbrot set vis ...
by skeet via Jon Skeet's Coding Blog : C# on 2/21/2008 10:19:59 PM
Just taking a quick break from proof-reading to post a thought I had yesterday. Visual LINQ uses ToString() to convert an expression tree's body into readable text. In some cases it works brilliantly, reproducing the original source code exactly - but in other cases it's far from useful. For instance, from this expression tree representation: (Convert(word.get_Chars(0)) = 113) I suspect you wouldn't have guessed that the original code was: word[0] == 'q' Personally I don ...
by skeet via Jon Skeet's Coding Blog : C# on 2/20/2008 1:22:44 AM
Critical link (in case you can't find it): Source Code DownloadUpdate: Dmitry Lyalin has put together a screencast of Visual LINQ in action - it gives a much better idea of what it's like than static pictures do. There's music, but no speech - so you won't be missing any important information if you mute it. I was going to save this until it was rather more polished, but I've just started reading the first proofs of C# in Depth, so it's unlikely I'll have much t ...
by skeet via Jon Skeet's Coding Blog : C# on 2/11/2008 11:45:31 PM
As per previous posts, I've been thinking a fair amount about how much it's reasonable to keep progressing a language. Not only have thoughts about C# 4 provoked this, but also a few other sources: Don Box on Ted Neward on Java (yes, two separate links - but view both) Don again on the "doneness" of XML The Channel9 video of Erik Meijer, Gilad Bracha and Mads Torgersen The video is very well worth watching in its entirety - even though I wouldn't pretend to understand ev ...
by skeet via Jon Skeet's Coding Blog : C# on 2/10/2008 10:01:25 PM
The final part of this little series is the one where I suggest my own ideas for C# 4, beyond those I've already indicated my approval for in earlier posts. Before I talk about individual features, however, I'd like to put forward a manifesto which could perhaps help the decision-making process. I hasten to add that I haven't run all the previous parts through this manifesto to make sure that I've been consistent, but all of these thoughts have been running around in my head for ...
by skeet via Jon Skeet's Coding Blog : C# on 2/8/2008 11:31:32 PM
Ian Griffiths mailed me about macros, and explained how LISP macros were very different to C/C++ macros, working at a language level instead of at a text level. I won't pretend to understand all about what would be possible and what wouldn't, but Ian gave a good example: query expressions in C# 3. Instead of being part of the language itself, they could apparently have been written as macros, if C# supported them. Then if you wanted to have similar support for different forms of expressi ...
by skeet via Jon Skeet's Coding Blog : C# on 2/7/2008 11:11:37 PM
Microsoft haven't committed to anything in C# 4 yet. However, there have been hints about what they've been considering in Eric Lippert's blog, and more than hints in Charlie Calvert's blog. There's not a lot to go on yet, but: Immutability support Most of Eric's posts about immutability have so far been about immutable data structures. However, the first post in the series did mention that they're playing around with immutability from the point of view of potential l ...
by skeet via Jon Skeet's Coding Blog : C# on 2/7/2008 9:01:32 PM
There has been a fair amount of speculation online about what should be in C# 4. I've taken the list below from a few posts, primarily those by Ayende and Jeremy Miller. I've deliberately left out the ideas that Microsoft have mentioned that they're at least considering - they'll come in the next post. Mixins I suspect everyone has a different idea of what these mean, but I'll say what I'd like. I want to be able to implement an interface by proxying all calls (other than ...
by skeet via Jon Skeet's Coding Blog : C# on 2/5/2008 11:32:22 PM
This came up a little while in a newsgroup question, and Marc Gravell and I worked out a solution between us. I've finally included it in MiscUtil (although not released it yet - there's a lot of stuff ready to go when we've finalised namespaces and updated the website etc) but I thought I'd share it here. How often have you written code to do something like counting word frequencies, or grouping items into lists? I know a lot of this can be solved with LINQ if you're using . ...
by skeet via Jon Skeet's Coding Blog : C# on 2/5/2008 7:45:13 PM
Everyone else is speculating about what's going to be in C# 4 (and various possibilities are coming out of MS), so I thought it would be wise to start my own series of wishlist posts before I miss the boat completely. In this first post, I'm not going to look at the future at all - I'm going to look at mistakes of the past. When I say "mistake" I of course mean "things I would have done differently had I been a language designer with 20/20 hindsight". Of course, t ...
by skeet via Jon Skeet's Coding Blog : C# on 1/26/2008 1:25:53 AM
In my book, I present an example of a Range<T> class do demonstrate iterator blocks. The range allows you to iterate over each element within it in the obvious fashion. There's an abstract base class, and then a couple of concrete classes derived from that - enough to show the pattern. The base class is abstract because there's a single abstract method, GetNextValue, which is required to take a current value and return the next one in the sequence. How this occurs depends on the ty ...
by skeet via Jon Skeet's Coding Blog : C# on 1/8/2008 11:21:41 PM
I've just seen LINQ to Objects described as the LINQ provider for "in-memory collections" again. It's a fairly frequent occurrence, and I may have done it myself on occasion. It doesn't do LINQ to Objects justice. An example I've used in a few places is a query which runs over log files. Something along the lines of: var query = from file in Directory.GetFiles(@"c:\logs", "*.log") fro ...
by skeet via Jon Skeet's Coding Blog : C# on 1/4/2008 11:42:00 PM
Marc Gravell and I have now implemented a lot of LINQ standard query operators on the "push" model of IDataProducer as opposed to the "pull" model of IEnumerable. My good friend Douglas Leeder (who doesn't use C#) has been with me this weekend, and through explaining the "big picture" to him in various ways, and taking his feedback, I think I've now got a good way of communicating it. Voting. It's a "real life analogy" which is always dangerous ...
by skeet via Jon Skeet's Coding Blog : C# on 12/13/2007 12:16:31 AM
Reading through chapter 2 (see, I'm being good) a new thought about return type covariance occurred to me. This is odd in itself, because I thought I'd exhausted my own supply of ideas around variance (which isn't the same as knowing everything about it, of course - it just means I don't expect to have anything new to say). Just as a reminder, in C# 1 delegates were completely invariant - in order to create a delegate instance from a method group, for instance, the signature had ...
by skeet via Jon Skeet's Coding Blog : C# on 12/4/2007 11:08:17 PM
A little while ago, I wrote about my silly project to test Parallel LINQ - a Mandelbrot generator. In the last week, two things have happened to make this more of a reality. Firstly, the December CTP of Parallel FX has been released. Secondly, my old laptop died, "forcing" me to get a new laptop, which just happens to have a dual core processor. So, it should just be a case of running it, right? Well, not quite. First let's have a look at the query expression again, in its serial f ...
by skeet via Jon Skeet's Coding Blog : C# on 11/29/2007 1:00:37 AM
Last night's blog post provoked a flurry of emails between myself and Marc Gravell. Looking back, trying to base the pipeline on a pseudo-asynchronous version of IEnumerable<T> was a mistake. We've now got a much more attractive interface to write extensions against: public interface IDataProducer<T>{ event Action<T> DataProduced; event Action EndOfData;} Why is this so much better? A few ...
by skeet via Jon Skeet's Coding Blog : C# on 11/28/2007 1:05:16 AM
Update: I've got a new and simpler design now. I'm leaving this in for historical interest, but please see the entry about the new design for more recent information. This post is going to be hard to write, simply because I can't remember ever writing quite such bizarre code before. When I find something difficult to keep in my own head, explaining it to others is somewhat daunting, especially when blogging is so much more restrictive than face-to-face discussion. Oh, and you'll ...
by skeet via Jon Skeet's Coding Blog : C# on 11/2/2007 12:25:42 AM
As mentioned in my previous post, I've been putting together the code samples for C# in Depth. Now, these are spread across several projects in a few solutions. They're referred to in the book as things like "Listing 6.2" but I've given the files "real" names in the projects. When you run any project with multiple executable listings in it, the project offers you options of which listing to run, showing both the type name and the listing, which is embedded using S ...
by skeet via Jon Skeet's Coding Blog : C# on 10/3/2007 8:12:04 PM
I've been writing about LINQ recently, and in particular I've written a small amount about Parallel LINQ. (Don't get excited - it's only about a page, just to mention it as a sort of "meta-provider" for LINQ.) I was wondering what to use to demonstrate it - what general task can we perform which could take a lot of CPU? Well, I used to be quite into fractals, and I've written Mandelbrot set generators in various languages. I hadn't done it in C# before now, ho ...
by skeet via Jon Skeet's Coding Blog : C# on 6/15/2007 5:38:42 AM
Were you aware that you could overload == to return types other than boolean? I certainly wasn't until I started reading through the lifted operators part of the C# 2 specification. It's quite bizarre - here it is in action: using System; class Test { public static string operator== (Test t1, Test t2) { return "Fish?"; } public static string operator!= (Test t1, Test t2) { return "Not a fish?"; } static void Main() ...
by skeet via Jon Skeet's Coding Blog : C# on 5/9/2007 10:44:53 AM
Recently (May 2007) there's been a debate on the microsoft.public.dotnet.framework newsgroup about the memory model, non-volatile variables, the Interlocked class, and how they all interact. Consider the following program: Update! I screwed up the code, making all of the combinations possible accidentally. The new code is now in the post - the first few comments are based on the original code. using System; using System.Threading; class Program { int x; int y; void Ru ...
by skeet via Jon Skeet's Coding Blog : C# on 4/16/2007 9:01:03 PM
It seems that the CCR I'd been waiting for is now out, and has been for a while. Unfortunately, as far as I can tell it's only available as part of the Microsoft Robotics Studio. It falls under the same licence as the Robotics Studio, and can be used in commercial apps (for a fee, I believe) - but why on earth isn't it available as a standalone download with a simple free licence? Robotics Studio 1.0 is a nearly 50MB download, which is absurd if you're only after the CCR. It's relatively li ...
by skeet via Jon Skeet's Coding Blog : C# on 3/27/2007 8:41:40 PM
A while ago, I wrote a blog entry about how Eclipse and Visual Studio 2005 stacked up against each other. Some of my quibbles with Visual Studio 2005 were due to my ignorance, but some were significant (from my point of view) missing features. Well, since then many people have recommended that I take a look at ReSharper. I requested a 30 day eval licence (as well as requesting a full free MVP licence by email - those people at JetBrains are very nice, thank you very much!) installed it, and afte ...
by skeet via Jon Skeet's Coding Blog : C# on 2/28/2007 3:51:21 PM
No, don't leave yet! This isn't another article about non-deterministic finalization, RAII etc. That's what we almost always think of when someone mentions the object life-cycle, but I'm actually interested in the other end of the cycle - the "near birth" end. We often take it as read that when an object's constructor has completed successfully, the object should be ready to use. However, frameworks and technologies like Spring and XAML often make it easier to create an object and then populate ...
by skeet via Jon Skeet's Coding Blog : C# on 2/28/2007 10:38:00 AM
(Disclaimer: I'm 99% sure I've heard someone smarter than me talking about this before, so it's definitely not original. I thought it worth pursuing though.) One of the things I love about Java and C# over C/C++ is the lack of .h files. Getting everything in the right place, only doing the right things in the right files, and coping with bits being included twice etc is a complete pain, particularly if you only do it every so often rather than it being part of your everyday life. Unfortunately, ...
by skeet via Jon Skeet's Coding Blog : C# on 2/27/2007 8:46:00 PM
(Warning: I've just looked up "mix-in" on Wikipedia and their definition isn't quite what I'm used to. Apologies if I'm using the wrong terminology. What I think of as a mix-in is a proxy object which is used to do a lot of the work the class doing the mixing says it does, but preferably with language/platform support.) I've blogged before about my mixed feelings about inheritance. It's very useful at times, but the penalty is usually very high, and if you're going to write a class to be deriv ...
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.