Software Geek

March 2, 2008

Whole Lotta Book: Programming WPF

Filed under: Software


Since the start of 2002, I’ve had at least one book project on the go. So it’s with some relief that for the first time in over half a decade, I am officially not writing a book: I finally have a copy of my fourth book, the second edition of Programming WPF , co-written by Chris Sells and me.

How different is the second edition from the first? I think the little pictures at the tops of the book spines tell their own story:

http://www.interact-sw.co.uk/images/BookSpines.jpg

If you prefer numbers to pictures, the 1st edition’s highest page number is 430, while the 2nd edition goes up to 835*. In other words, it’s almost double the size.

Moreover, all the content from the first edition was thoroughly revised, partly due to changes between beta 1 and the released version of WPF, but also because I’ve acquired rather more real life experience with WPF in between the two editions. That combined with the fact that I wrote a slightly higher proportion of the total book this time round (it was about half and half last time) meant that this second edition was a much bigger project than writing the first edition, even though we wrote that from scratch!

I’m reliably informed that Amazon US are shipping it right now. Their web site certainly claims to have it in stock. (Amazon UK doesn’t yet, but presumably will do very soon.)

If you read our book, I hope you enjoy it.

*In case you’re wondering why Amazon is quoting 86 (more…)

Natural Sorting in C#

Filed under: Software


Jeff Atwood recently posted about natural sorting. This is all about making sure that strings that contain numbers sort numerically. I’m slightly surprised to see that he wants to call it alphabetical sorting. Surely by definition, alphabetical sorting is defined by, well, the alphabet. This is an issue about numbers, not letters.

Anyway, he says he tried and gave up on a succinct C# version. He suggests that it will take 40+ lines of code. I believe that’s misleading, because as far as I can tell, the Python versions are only able to be so succinct because Python already appears to know how to sort an array. Both examples he shows rely on this. In.NET, collections aren’t intrinsically sortable. Let’s sort that:

/// <summary>
/// Compares two sequences.
/// </summary>
/// <typeparam name=”T”>Type of item in the sequences.</typeparam>
/// <remarks>
/// Compares elements from the two input sequences in turn. If we
/// run out of list before finding unequal elements, then the shorter
/// list is deemed to be the lesser list.
/// </remarks>
public class EnumerableComparer<T> : IComparer<IEnumerable<T>>
{
 /// <summary>
 /// Create a sequence comparer using the default comparer for T.
 /// </summary>
 public EnumerableComparer()
 {
 comp = Comparer<T>.Default;
 }
	
 /// <summary>
 /// Create a sequence comparer, using the specified item comparer
 /// for T.
 /// </summary>
 /// <param name=”comparer”>Comparer for comparing each pair of
 /// items from the sequences.</param>
 public EnumerableComparer(IComparer<T> comparer)
 {
 comp = comparer;
 }
	
 /// <summary>
 /// Object used for comparing each element.
 /// </summary>
 private IComparer<T> comp;
	
 /// <summary>
 /// Compare two sequences of T.
 /// </summary>
 /// <param name=”x”>First sequence.</param>
 /// <param name=”y”>Second sequence.</param>
 public int Compare(IEnumerable<T> x, IEnumerable<T> y)
 {
 using (IEnumerator<T> leftIt = x.GetEnumerator())
 using (IEnumerator<T> rightIt = y.GetEnumerator())
 {
 while (true)
 {
 bool left = leftIt.MoveNext();
 bool right = rightIt.MoveNext();
	
 if (!(left || right)) return 0;
	
 if (!left) return -1;
 if (!right) return 1;
	
 int itemResult = comp.Compare(leftIt.Current, rightIt.Current);
 if (itemResult != 0) return itemResult;
 }
 }
 }
}
	

(more…)

Updated Finalization and Hosting

Filed under: Software

My original posts on Finalization and Hosting had some hokey XXXXX markers in place of content, where that content hadn’t already been disclosed in some form.  Now that the Visual Studio 2005 Community Preview is available, I’ve gone back to those two posts and replaced the XXXXX markers with real text.

Also, it’s obviously been a while since my last post.  I started writing something this weekend, but the weather here has been spectacular and I was compelled to go outside and play.  I’ll try to have something in the next couple of weeks.

 


http://blogs.msdn.com/cbrumme/archive/2004/04/26/120609.aspx

Debugging an InvalidCastException

Filed under: Software

First, obviously, find the two types for which the cast failed and verify that they are the same type or otherwise castable.

Next, if the type was just deserialized, also verify that its assembly successfully loaded in the target appdomain.

If everything seems fine, check to see if the assemblies for those two types are loaded from different locations and in the same appdomain. (The actual cast is done in just one appdomain, even if the exception happens when passing a type between two appdomains.) Even if the bits of those assemblies are totally identical, if they are loaded from different paths, they will be considered different, so their types will be considered different. (See Comparing Already-Loaded Assemblies.)

Live Help Server: Jerry Messenger is Jabber/XMPP Live Chat Server for a website.

A quick way to check for that is to examine the loaded module window of a debugger to see if that assembly was loaded multiple times. If it was, break on module loads to get the callstack for the unexpected load. If that’s inconvenient, try getting the Fusion log.

Usually, the problem is that:

  1. The assembly is available in the GAC (or the ApplicationBase) and loaded there by static reference (something was compiled against that assembly).
  2. It has also been loaded dynamically by path, from another path (LoadFrom(), LoadFile(), etc.).
  3. Then, the code tries to cast the type from (2) to the corresponding type from (1).

To fix this, once you find the offending caller, you will need to either cause the two types to be (more…)

Sometimes, it’s the small things..

Filed under: Software


I’m a Firefox guy. The only reason I use it instead of IE is that it feels faster. Seriously.

I find it incredibly annoying that the only websites I frequent that require IE are those run by Microsoft. I’ve nothing against IE (I’ve never had the malware problems), but these websites disrupt whatever I’m doing. Most times I’ll just avoid the site. A good example is the MSN Video portion of MSN. Occasionally I’ll click a link leading to a video, at which point I’m told that I can’t watch it in anything but IE. This is odd since 1/2 of the emails I get link to funny videos on websites that do let me watch them in my browser of choice. Instead of launching IE and watching the (advertiser-supported) MSN Videos I simply move on. I’ve got too much stuff to do to be inconvenienced by this.

Which is why I was pleasantly surprised by the following error message. The site doesn’t support Firefox — but they’re working on correcting it. It’s a problem, and they’re fixing it. Bravo!


http://weblogs.asp.net/jkey/archive/2006/04/30/444551.aspx

From C# to Java: Part 2

Filed under: Software

As I mentioned in part 1, it has been almost ten years since
I last wrote any real Java code.  That was apparently long enough for me to
repress some of the more painful memories.  For example, I had completely
forgotten about how the following code works:

String a = new
String(
"foo");
String b = new String("foo");
if (a == b)
{
      // this will
never happen

}

Softwre Development for small and middle size companies. World-class software applications.

In C#, when you use the == operator on strings, you get what
you expect.  In Java, == merely tells you if the two strings are the very same
object, not whether the two strings are the same.

Tangent:  Operator Overloading

More broadly, going back to Java makes me realize just how much
I appreciate operator overloading in C#. 

I’m not saying that I think operator overloading is really useful
for my own classes.  Mostly I think it’s a way of empowering programmers to
create bad code.  I’ll admit I use operator overloading just a little bit in
Sawdust to support easy manipulation of 3D points and vectors, but I could live
without it.

(more…)

A quick update on me.

Filed under: Software


It’s been over two years since I blogged.  Although I remain happily (perhaps even ecstatically) working at Microsoft, I left the CLR team and the Developer Division about a year ago.  I’m now on an incubation team, exploring evolution and revolution in operating systems.  This is a fascinating area that includes devices, concurrency, scheduling, security, distribution, application model, programming model and even some aspects of user interaction (where I am totally out of my depth).  And, as you might expect with my background, our effort also includes managed programming.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

Anyway, this blog will remain available indefinitely.  It continues to be useful for certain technical details which are unavailable elsewhere.

 

In the meantime, if any readers are interested in working on a deep systems incubation with me and a team of truly outstanding developers, please send me email (cbrumme).  We are holding to some very high standards for this effort in terms of insight, experience and hard work.  But if you are like me, I am confident you will find it a dream opportunity.

(more…)

History of Lambda-Calculus and Combinatory logic

Filed under: Software

F. Cardone and J. R. Hindley. History of Lambda-Calculus and Combinatory logic. To appear as a chapter in Volume 5 of the Handbook of the History of Logic.

From the introduction:

Seen in outline, the history of LC and CL splits into three main periods: first, several years of intensive and very fruitful study in the 1920s and ’30s; next, a middle period of nearly 30 years of relative quiet; then in the late 1960s an upsurge of activity stimulated by developments in higher-order function theory, by connections
with programming languages, and by new technical discoveries. The fruits of the first period included the first-ever proof that predicate logic is undecidable. The results of the second attracted very little non-specialist interest, but included completeness, cut-elimination and standardization theorems (for example) that found many uses later. The achievements of the third, from the 1960s onward, included constructions and analyses of models, development of polymorphic type systems, deep analyses of the reduction process, and many others probably well known to the reader. The high level of activity of this period continues today.

Beware: This is a long paper (but less than you might expect it to be by looking at the page count: about half the pages are dedicated to the bibliography).

In the announcement on the TYPES Forum the authors invited comments, suggestions and additional information on the topics of the paper, namely the development of lambda-calculi and combinatory logic from the prehistory (Frege, Peano and Russell) to the end of 20th century.
http://lambda-the-ultimate.org/node/2679

I can’t believe I’m becoming an Apple Fanboy

Filed under: Software

I ordered a MacBook Air site unseen. That’s a first for me.

As I write this I’m about to go workout and it dawns on me that I’m on my 3rd generation of Apple IPod. I started with the original, switched to a bigger version (to back up all my pics and show off my kids to my friends) and then for the holidays, got myself and wife an ITouch.

Goodbye Ipod. With the new $20 dollar software that I downloaded yesterday, my ITouch gives me music, pictures and now email, calendar and a very cool basic GPS system that leverages the WiFi available. Touchtyping is still impossible for me on it, so it wont ever replace my phone for texting or primary mobile email, but its definitely encroaching on its territory. Solve the keyboard problem for fat fingered typists and I might even buy an IPhone.

I like the ITouch enough that I just sent an email to the Mavs IT head to see how we fans with ITouchs (and Wifi devices like Nokia among others) could leverage WiFi in the American Airlines Center before , during and after Mavs games, HDNet Fights and other events…

After many PC years, I’ve crossed over. Me the fanboy.

Permalink  | Email this  | Linking Blogs  | Comments

http://www.blogmaverick.com/2008/01/22/i-cant-believe-im-becoming-an-apple-fanboy/

Great ASP.NET AJAX Web Portal Starter Kit: dropthings.com

Filed under: Software

I  was very excited to see that Omar AL Zabir , co-founder & CTO Pageflakes has created a very cool AJAX based Web portal http://dropthings.com.  And even more excited to see he has posted all the code in an open source way!   Now you can build your own Ajax portal fun! 

Dropthings is a open source Web 2.0 Ajax Portal that shows the power of several.NET Framework 3.5 technologies.  It supports widget based modularized website, drag and drop personalization of content and an open API for widgets.  It is the sample featured in the book, Building a Web 2.0 Portal with ASP.NET 3.5 and you can use it as a personal portal, a group website, a public portal or as a dashboard for an enterprise that aggregates services from different systems.

Download Dropthings

Visit the Codeplex Project

See it Live!

Cool Features

  • Aggregation of content from external sources e.g. Flickr, Weather, Horoscope, and any type of RSS
  • Highly decoupled Widget Architecture
  • Homepage personalization using drag & drop
  • Absolutely zero postback in the entire website
  • Themes
  • Full feature supported for anonymous users
  • Open API for widget development

 

Technologies he shows off…

  • ASP.NET 3.5
  • An advanced REST call handler for asynchronous, transactional, cache friendly web methods
  • Content Proxy for bridging content from external domain
  • Themes
  • Personalization
  • Membership and Profile provider
  • Anonymous Identification Provider
  • Data binding using Linq
  • Data Access Layer built using Linq
  • Business layer built using Windows Workflow Foundation

http://blogs.msdn.com/brada/archive/2008/02/13/great-asp-net-ajax-web-portal-starter-kit-dropthings-com.aspx

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com