-
-
Recursively follow all of the links in Brad Abrams article The Bum Rap of foreach and you will get a great education in both iteration and the evils and joys of micro-optimization. Regarding optimization, see "Rule #1" in The Rules of Optimization.
-
-
These string rotator methods appeared in a chain of recent posts on the DOTNET-CLR list. I recorded them here because they may prove useful.
A substring approach:
public static string RotateLeftSubstring
(string s, int start, int length, int amount)
{
// Allow amount to be negative (as far as -length)
amount = (length+amount) % length;
return
s.Substring(0, start)+
s.Substring(start + amount, length-amount) +
s.Substring(start, amount) +
s.Substring(start + length, s.Length - (start+length) );
}
A StringBuilder approach:
public static string Rotate(string s, int start, int length, int amount) {
StringBuilder sb = new StringBuilder(s);
for (int i = 0; i < length; ++i) {
sb[start + i] = s[start + ((i + amount) % length + length) % length];
}
return sb.ToString();
}
-
-
I just tried out two new free tools that provide metrics for .NET projects and recommend both of them to anyone who wants a better picture of their .NET code. The tools are:
* NDepend
* devMetrics
Both tools are relatively easy to use and they quickly produce a wealth of information about your assemblies.
A commentor just reminded me that I should also point to the
Code analysis - Standards verifiers category at Madgeek's SharpToolbox site. That category lists quite a number of metrics tools.
-
-
Speaking of
using the Singleton pattern in C#,
have a look at
Design Patterns potential hazards
on Fabrice's weblog
and follow the links to the articles he recommends. Also, have a gander at
.Net singleton pattern multi-threading issue...
by Chris Johnson.
An old friend (and ex co-worker) just sent me another great link to an
IBM Developer Works
article with advice on how to
Use your singletons wisely.
MSDN has
Implementing Singleton in C#,
as pointed out by
Luciano Evaristo Guerche
who was recently cited by
Scott Watermasysk. A comment in Luciano's post also points to
Implementing the Singleton Pattern in C#.
Gee, I guess that's enough cross-posting about the Singleton for now! These articles contain a lot of information on something that seems so simple on the calm surface but has monsters lurking in the depths.
All in all, design patterns are great but you need to use them intelligently and with attention to your intended purpose. Perhaps you do not need to worry about threading issues; perhaps you do. The main thing is to ask the right questions when you do the design.