Are you a Maker or a Manager?

Paul Graham writes very useful stuff.  I respect his mind. Read his Maker’s Schedule, Manager’s Schedule essay for what I think is one of the smartest descriptions of the classic problem all programmers face. Spread this meme in your organization. Are you a Maker or a Manager? Both are useful, but they are very different…

1

Stopwatch on Interlocked.Increment(ref x) vs. lock (y) { x++; }

Given 10 million iterations: object y = new object(); const int iterations = 10000000; Which is faster, InterlockedIncrement: stopWatch = Stopwatch.StartNew(); for (int i = 0; i < iterations; i++) { Interlocked.Increment(ref x); } stopWatch.Stop(); Console.WriteLine("Interlocked took " + stopWatch.ElapsedMilliseconds); Or lock: stopWatch = Stopwatch.StartNew(); for (int i = 0; i < iterations; i++) {…

5

A simple and totally thread-safe implementation of IDisposable

A simple and totally thread-safe implementation of IDisposable, with improved semantics over the Dispose() / Dispose(bool disposing) reference implementation.  Now updated, slightly, after a consult with someone much smarter than me, who suggested a slight improvement: use Thread.VolatileRead in the IsUndisposed method. Instructions: Override DisposeResources in derived classes.  When this method is called, always release…

1

An invariant version of the same…

An invariant version of the same… /// <summary> /// Extends StringBuilder so that it has an AppendFormatLineInvariant method. /// </summary> /// <param name="value">The StringBuilder being extended.</param> /// <param name="format">A composite format string.</param> /// <param name="args">An object array that contains zero or more objects to format.</param> /// <returns>The StringBuilder.</returns> public static StringBuilder AppendFormatLineInvariant(this StringBuilder value, string…

0

A missing method from StringBuilder…

StringBuilder is so useful.  Does it all.  But it’s missing a method.  Here it is: /// <summary> /// Extends StringBuilder so that it has an AppendFormatLine method. /// </summary> /// <param name="value">The StringBuilder being extended.</param> /// <param name="format">A composite format string.</param> /// <param name="args">An object array that contains zero or more objects to format.</param> ///…

0

Useful extension method for the object type…

Here’s a useful extension method for the object type: /// <summary> /// Extends object to have a ValidateArgumentNotNull method. /// </summary> /// <remarks> /// Validates that an object is not null. If the object is null, /// ArgumentNullException will be thrown. /// </remarks> /// <param name="value">The object being extended.</param> /// <param name="argumentmName">The argument name.</param> public…

2