Site: http://stevesmithblog.com/ Link: http://feeds.stevesmithblog.com/stevensmith
by ssmith via Steve Smith's Blog on 3/2/2010 9:41:45 PM
Yesterday I was looking at some old code and refactoring it to clean it up (in this case I wasn’t the original author, but I’ve written code just like this). The application in question was a simple process that had to run once per month, on demand, and so was coded up as an EXE application. As it ran, it provided updates on its progress, so it looked something like this: static void Main(string[] args) { Console.WriteLine("Starting Application @ " ...
[ read more ]
by ssmith via Steve Smith's Blog on 2/26/2010 10:35:04 PM
I just ran into a problem with SQLite and NHibernate, which was giving me this error message: The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. The strange thing was, it worked fine from within Visual Studio, but it died when I used my ClickToBuild.bat file, which calls msbuild and runs my tests from the command line. A bit of searching led me to a similar problem on StackOverflow, which produced the answer: Use the x64 binaries. ...
by ssmith via Steve Smith's Blog on 2/10/2010 5:57:00 PM
Building software applications is sometimes compared with building structures out of smaller components. The children’s toys, Legos (and their generic brethren), come to mind and in fact make for a good analogy. Given a set of components with varying characteristics (shape, color, etc, or in the case of software, objects with different behavior and state), it is possible to connect the components in order to create a larger structure, with (hopefully) more advanced capabilities. Th ...
by ssmith via Steve Smith's Blog on 12/18/2009 2:25:22 PM
I’m very pleased to see Microsoft respond to customer feedback requesting a little bit more time before the release of Visual Studio 2010. There has been concern with the current beta release that its performance is not where it needs to be, especially in certain specific scenarios. Microsoft is aware of these issues and has a number of fixes under way or already checked in, but the concern among the community was that there wouldn’t be time for another broad beta or RC release of V ...
by ssmith via Steve Smith's Blog on 10/22/2009 3:53:37 AM
Tonight at Hudson Software Craftsmanship, I paired with another group member and worked on the PotterKata for the first time. I’d seen NotMyself write about it a few days ago, which prompted me to suggest it for the group to work on (summary of the meeting here). Briefly, this kata is a fairly real-world exercise in that it has to do with business rules for a shopping cart that are non-linear. In this case, the rules are: One copy of any of the five books costs 8 EUR. If, howeve ...
by ssmith via Steve Smith's Blog on 9/6/2009 4:39:00 AM
The LINQ Aggregate() extension method uses a Func<int, int, int> to operate on items in a series. If you want to use it, for example, to return the product of each value with its successor, you can do something like this: Func<int, int, int> producter = (one, two) => one * two; var result = subString.ToCharArray().ToDigits().Aggregate(producter); Of course, you don’t need the intermediate value. You can simply use a lambda directly for the Aggregate ...
by ssmith via Steve Smith's Blog on 9/6/2009 3:53:00 AM
Euler problem 7 requires returning the 10001st prime number. It notes that the 6th prime number is 13 in the problem description. Having already done some work with iterators and various number generators, including a Primes generator for previous Euler problems, the base case given in the problem can be reduced to this NUnit test: public void SixthPrimeIs13() { Assert.AreEqual(13, NumberGenerator.Primes().Take(6).Last()); } Replacing the 6 with 1000 ...
by ssmith via Steve Smith's Blog on 8/27/2009 6:19:00 PM
Recently I’ve been doing some Project Euler problems as exercises to help improve my coding skills. We do this internally at NimblePros periodically and also at last weeks Hudson Software Craftsmanship meeting, which I co-run. In doing these problems, I’ve been trying to approach them both from a traditional C# 1.0 standpoint as well as using newer constructs such as lambda expressions, LINQ, and iterators. It’s amazing how much more flexible a design can be through the use of ...
by ssmith via Steve Smith's Blog on 8/26/2009 4:19:00 PM
One of my applications relies on a singleton pattern to create a single instance of a server which processes requests from many different ASP.NET handlers. It is created using pretty much standard Singleton code: public static Context CreateContext() { return CreateContext(new ConfigurationFileSettings()); } Recently, this server needed to be made aware of whether requests were coming into it via SSL or standard HTTP. The solution that was checked i ...
by ssmith via Steve Smith's Blog on 8/25/2009 4:00:15 PM
Recently I was reviewing some code and ran across this – can you spot the problem? var parameters = new List<SqlParameter> { new SqlParameter("@SomeID", someId), new SqlParameter("@SomeOtherID", someOtherId), new SqlParameter("@ServerDate", serverTime) }; string cacheKey = string.Format("ResultSetName-sid{0}-soid{1}-date{2}",
... [ read more ]
by ssmith via Steve Smith's Blog on 6/18/2009 2:48:47 AM
I’m working on a little application right now that provides some insight into the assemblies in use for a given application. One of the things that I want to be able to show is whether or not each assembly was built in Debug or Release mode. As you’re no doubt aware, running applications in production that were built in Debug mode can be a major performance problem (at a minimum – depending on what else you have turned on in Debug mode it could also be a security issue). So I did so ...
by ssmith via Steve Smith's Blog on 6/11/2009 7:50:00 PM
Sarah suggested Tuesday that I write a blog PostFormatter that only changed the format of blog posts created on days that were Fibonacci Sequence days (e.g. 1, 2, 3, 5, 8…). I’d hoped to code something like that up during my Ann Arbor talk last night but ended up not having the time, so just to show how easily this could be done, I threw something together today. First, this is for a demo application that I used in my talks this week – if you want to follow along, grab t ...
by ssmith via Steve Smith's Blog on 5/12/2009 4:30:27 PM
I’m wiring up the IoCControllerFactory from MVCContrib into an MVC application and I kept running into an issue where a request was coming in looking for a ContentController. The reason for this is that in my CSS file I have a property like this: background: transparent url(images/logo.gif) no-repeat scroll left top; which is in the Content folder. The resulting request for “/Content/images/logo.gif” was matching the default routing rule: routes.MapRoute( & ...
by ssmith via Steve Smith's Blog on 2/11/2009 9:42:28 PM
I’ve been working with Azure off and on since last summer, and like any new API or platform, there are hurdles involved with the learning curve. This is especially true for pre-release software that is rapidly changing and of course has neither official documentation nor much in the way of info on blogs or developer community sites like ASPAlliance.com. One of the ways I like to learn about projects these days is through testing. Ideally, the project will already have a suite o ...
by ssmith via Steve Smith's Blog on 2/11/2009 7:59:34 PM
When using ASP.NET MVC to post data that might contain HTML or other potentially “dangerous” data, the default behavior as of the Release Candidate is to throw an exception, preventing the posting of the data. This is a well-known feature of ASP.NET that was introduced several versions ago, and the typical way to avoid it (when necessary for the application’s function) is to add validateRequest=”false” either to the @Page attribute or to the <pages /> section in web.config. Not ...
by ssmith via Steve Smith's Blog on 2/9/2009 3:47:56 PM
Recently we’ve been separating our monolithic application into smaller systems which communicate via services. We’re using WCF for this communication, and one of the things that we’ve quickly noticed is that WCF is, for whatever reason, not compatible with the usual best practice of wrapping IDisposable objects with a using() {…} block. Personally, I don’t think resources should be marked IDisposable if you can’t simply use the using() statement. The issue with the case of WCF’ ...
by ssmith via Steve Smith's Blog on 12/10/2008 5:19:59 AM
The saga began here. Where I left off, I'd managed to create a new class for handling the storage of my creative files, called CreativeFileStore. This method took in an IFileSystem as a parameter to its constructor, which provides two benefits: Testability Flexibility - I can swap between WindowsFileSystem and AmazonS3FileSystem easily In the interest of keeping the individual posts at a reasonable size, I didn't include all the tests for the CreativeFileStore, but here's a summary: 1 ...
by ssmith via Steve Smith's Blog on 12/10/2008 12:34:01 AM
Still working on cleaning up some legacy ASP.NET code. Here's where we are: Part 1: Define problem and demonstrate IFileSystem basic version Part 2: Spike solution to support saving files in IFileSystem that works in both Amazon S3 and the Windows file system Part 3: Initial refactoring via TDD of big ugly method Now it's time to take the big step of pulling the main ugly method guts out into its own object. Since the main purpose of the method, GetImageOrFlashData(), is to store a ...
by ssmith via Steve Smith's Blog on 12/9/2008 8:06:25 PM
In part one I described the problem. In part two I worked out the details of how to save files in a platform-ignorant way by creating a spike solution. Now I'm looking back at my original ugly method from part one and extracting it into its own class that accepts an IFileSystem instance via constructor injection. Looking at the original method, it has a number of dependencies and issues. My next step is going to be to get it out of the untestable ASP.NET codebehind file and int ...
by ssmith via Steve Smith's Blog on 12/9/2008 3:20:54 AM
In my last post in this IFileSystem series, I described the problem I'm working on of removing a dependency on the System.IO Windows file system in my ASP.NET application. A bit of research on this subject revealed some help on making file uploads testable by ScottHa, but his technique still makes use of the SaveAs() method and ultimately ties the solution to the server file system. A similar post on creating Unit Test Friendly File Uploads was more helpful, in that it provided some ...
by ssmith via Steve Smith's Blog on 12/8/2008 6:08:14 PM
In the course of making my software more testable, I’ve attempted to eliminate a dependency on the file system (in this case, via System.IO) by creating an interface, IFileSystem. I just did a quick search for this term and came back with only one C# interface (in the first few results) that matches this, which is for CC.NET, and looks like this: My basic version of the interface is similar: public interface IFileSystem { bool FileExists(string path); vo ...
by ssmith via Steve Smith's Blog on 10/20/2008 4:45:00 PM
In the last year or so I've really seen the light on how to really write loosely-coupled code. I thought I knew something about this concept before - I mean, I knew loose coupling was good, generally speaking, and I knew data abstraction was one of the key ways to limit dependencies between classes. However, I didn't realize that I was unintentionally adding all kinds of coupling into my applications despite my best efforts to the contrary. Let's talk about some dependencies, i ...
by ssmith via Steve Smith's Blog on 9/25/2008 4:54:17 AM
This is a follow-up to my post about avoiding dependencies with design patterns. It left off with something like this as a Cart object that uses the Strategy pattern to avoid a direct dependency on SMTP emails. 1: public class Cart 2: { 3: private ISendEmail emailProvider; 4: //public Cart() 5: //{ 6: // emailProvider = new LiveSmtpMailer(); 7: //}
by ssmith via Steve Smith's Blog on 9/22/2008 1:39:00 PM
I've been asking for a recursive FindControl() method as a method off of System.Web.UI.Control for years but so far no luck. You find yourself needing these frequently when you work with composite controls, like most of the Login family of controls introduced with ASP.NET 2.0. In particular, LoginView, CreateUserWizard, and Login frequently require a technique like this to access their contents. I posted a simple version a while back; Michael Palermo updated it, and Aaron Robson post ...
by ssmith via Steve Smith's Blog on 9/19/2008 3:09:09 PM
I've been manually adding DotNetKicks icons to my posts recently to try and generate more buzz for them, but that gets old quickly, so about an hour ago I decided to figure out how to make this automatic. My current blog engine is Graffiti, which I really like, and after doing some searching for a pre-existing solution, I pinged ScottW on IM about the problem and he set me down the right path within seconds. The Problem DotNetKicks will display a dynamic image with a count of how many "kic ...
by ssmith via Steve Smith's Blog on 9/19/2008 3:34:02 AM
I gave a one day class to about 20 developers today introducing Microsoft .NET, C#, and ASP.NET. As it was only one day and there were no hands-on labs, coverage was necessarily cursory, but overall things went very well. In the course of discussing the Base Class Library and specifically the areas of logging and sending emails (System.Diagnostics and System.Net), I was careful to emphasize to the class that they should definitely avoid making direct calls to these namespaces' members for their ...
by ssmith via Steve Smith's Blog on 7/7/2008 1:57:59 PM
Oren has a post showing how he deals with time sensitive code in his unit tests. One thing that's interesting is that, like my previous post, deals with the System.Func<T> construct introduced in .NET 3.5. I see this convention more and more and it's really growing on me. I've dealt with timing issues in my own code using a convention similar to the one Ayende demonstrates, which is to create a singleton or static property for the system time, and consistently reference t ...
by ssmith via Steve Smith's Blog on 7/7/2008 1:03:12 PM
Karl Seguin has an interesting post about using System.Func to fight repetitive code blocks, which actually addresses a pain point I've had for quite some time but had never acted on to fix. Whenever one access the Cache or a similar statebag that might or might not contain the value sought after, it is important to check if the value exists first, and if it doesn't, go and retrieve it from wherever its authoritative repository is (typically the database). This can be done poorly, so ...
by ssmith via Steve Smith's Blog on 7/2/2008 4:00:44 PM
I'm strongly considering adopting the use of an IsNull extension method in my .NET 3.5 coding projects. A quick search to see what others have to say about this revealed a new web site dedicated to extension methods, which includes this IsNull method ready to go: pubic static bool IsNull(this object source){ return source == null;} The String class supports the IsNullOrEmpty() method now, but you have to pass it your instance yourself. This is another good candidate for Extension M ...
by ssmith via Steve Smith's Blog on 5/1/2008 2:00:00 PM
I interviewed a couple of college students earlier this week for internship positions with Lake Quincy Media, and one of them reminded me of my own college days when we were graded in part based on how well commented our code was. In school, comments are typically there as a "check the block" measure to ensure that the professor doesn't take off points for not having them, but in the real world comments can actually serve a good purpose. One of the things you learn with ...
by ssmith via Steve Smith's Blog on 1/8/2008 4:26:31 PM
Al Pascual wrote about some trends he noticed using Google Trend, with regard to different programming languages. It's an interesting tool, since it can be used to gauge general interest in particular keywords and search terms, as well as news, going back about 4 years. For instance, here's a comparison of Visual Basic and C# using common search terms for each (VB, VB.NET vs. C#, CSharp): Given just these search terms, it's clear that VB/VB.NET is on a downward trend, with C#/CSharp ...
by ssmith via Steve Smith's Blog on 8/7/2007 6:54:00 PM
We ran into this issue today: A LoginView control that has always worked just fine was failing to have any contents on a PostBack. Stepping through it and checking things in the Immediate Window confirmed that it had a Controls.Count of 0. Looking at it in ASP.NET Trace also showed that, after a postback, it had no controls below it in the control tree. This was a problem since it contained a DropDownList and a TextBox that we needed to save the contents of in a click handler, ...
by ssmith via Steve Smith's Blog on 7/13/2007 7:33:38 PM
I recently heard about a set of controls that is being made freely available via CodePlex with the goal of improving the usability and consistency of medical software applications. The Microsoft Health Common User Interface (CUI) includes a suite of rich controls and guidance for building user interfaces that follow a standard approach to user interface design. The CodePlex Project for MSCUI includes the controls library. The controls are freely available and open source, so th ...
by ssmith via Steve Smith's Blog on 6/27/2007 4:51:06 AM
I just finished reading Jon Galloway's post, The value of "good enough" technology, and it reminded me of something I repeat very often in my talks on improving performance and/or caching (which share some content as you may imagine). I wanted to emphasize one point a bit more succinctly than Jon did, and that is that in software development (and I imagine in any endeavor where resources are constrained): Going beyond merely good enough is wasted effort. What does this mean? It means ...
by ssmith via Steve Smith's Blog on 6/17/2007 5:12:00 AM
Plenty of others have written about this so I'll keep it brief. I needed to sort some objects based on a string property. Some quick searching led me to this post which got me close to what I wanted. My final code was this:myThings.Sort(delegate(Thing x, Thing y) { return String.Compare(x.Name,y.Name); }); myThings is a List<Thing> collection. String.Compare done in this fashion will sort them alphabetically - reverse its parameters to sort in reverse. Share thi ...
by ssmith via Steve Smith's Blog on 4/10/2007 7:42:55 PM
As part of my automated build and test process, I wanted to be able to confirm that my third party components were the proper version and, more importantly, that they were fully licensed. For some components, I can create a new instance of the control or component and test its IsLicensed property. For others, the assembly itself is different for evaluation versus professional versions, and another approach is required. In the first case, the code required to test if the control ...
by ssmith via Steve Smith's Blog on 10/2/2006 9:52:32 PM
CSharpFeeds is a simple community site dedicated to keeping up with the latest goings-on in the C# world, while eliminating the noise and personal/social posts from the various C# blogs out there. This task involves individually touching each post to approve or reject it as on-topic, and while this is not a terribly arduous process, we could use some help. If you are a C# guru and would like to devote a few minutes (literally, like maybe 5–10 minutes) a day (or even a week) to ...
by ssmith via Steve Smith's Blog on 9/1/2006 2:08:02 PM
Frans Bouma, creator of LLBLGen, MVP, and all around very smart guy, wrote yesterday about the ‘myth’ that caching inside an Object-Relational (O/R) mapper makes queries run faster or makes the O/R mapper more efficient. I think he’s missing a few key usage scenarios (and, what’s more, I think he generally has a dislike of caching for whatever reason, which may bias his opinion), which I’d like to examine here. First, let me look at his definition of a cache, ...
by ssmith via Steve Smith's Blog on 8/24/2006 1:49:00 AM
There's an example in Professional ASP.NET 2.0 that shows how to add a few profile items to a CreateUserWizard. Unfortunately, it doesn't work in certain cases, specifically when the profile item in question is set to allowAnonymous="false". When that happens, you will receive this error:"This property cannot be set for anonymous users."One fix is to simply set the allowAnonymous flag to true, but if it's not something you want anonymous users to be ab ...
by ssmith via Steve Smith's Blog on 7/31/2006 8:06:39 PM
Today CSharpFeeds officially goes live. This is a pet project of mine and Gregg Stark’s based on Serge’s VBFeeds.com site and its source code (thanks to Serge for letting me see the source!). VBFeeds is a great place to find just VB information from the top VB people, moderated so that it doesn’t include posts about going on vacation or other personal posts. C# Feeds seeks to do the exact same thing, but for C# content, rather than VB. If there’s a C# feed we should be pu ...
by ssmith via Steve Smith's Blog on 7/20/2006 2:39:19 PM
Murach’s C# 2005 is one of many books I’ve picked up since .NET 2.0/VS2005 went gold last November. I have to say, I really love the layout of Murach’s line of books. The book would make an ideal textbook for a training class, but outside of a training environment it is still a great learning tool. In addition to great technical material, each chapter also includes practice exercises. Joe Stagner recently blogged about the book, too, saying: But ...
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.