Posts tagged with 'F'
Welcome back to another "Weekly Concerns" (after skipping a week). This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.
- If you haven't seen Seth Petry-Johnson's Patterns of Effective Test Setup presentation yet, you should at least check out his slides.
- Source code for MS-DOS and Word for Windows is now available.
- You can play Missile Command with a YouTube video. Just go to any YouTube video, like this one, and type "1980".
- Mark Greenway and myself did an introductory presentation on WordPress with Azure through the MVP Mentor program. A recording of WordPress with Azure is now available.
If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.
Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.
- Tainted Love as played on 13 noisy floppy and 1 hard disk drives.
- ConduitJS is a "targeted AOP" framework for JavaScript
- Couldn't get enough Pete last week, eh? He wrote another blog post about Parameter Checking with Postsharp
- Check out this book on the Mikado Method of refactoring. I'm not familiar with it yet, but looks interesting.
- Using RealProxy for AOP
If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.
I just open-sourced a tool that I wrote that I've been using internally at Zimbra (previously Telligent) for almost a year. It's an ugly little tool that I wrote out of frustration, but I've gotten so much use and time savings out of it that I thought I would share it. It's called SQL Profiler Query Cleaner.
SQL Profiler is a great tool to show you exactly what SQL is being executed, along with the parameters. This is especially useful when debugging, because sometimes you aren't sure what SQL is being executed. However, often times I will find myself having to pull that SQL+parameters out of SQL Profiler and paste it into SQL Server Studio in order to analyze, tweak, debug, etc. However, notce the output of SQL Profiler (bottom part of the screenshot):
The SQL string is there, but there are escaped characters. The parameters and arguments are there, but they're first declared, then assigned, "doubling" the syntax. It executes fine in SQL Studio, but if there's a syntax error, you can't really pinpoint exactly where in the query the error is, because you have to unescape the strings, manipulate the parameters (in two spots), and it's just time-consuming if you're doing this a lot (which I was).
So, fire up Sql Profiler Query Cleaner, paste the SQL Profiler output into the top text box, click the "Clean" button, and the bottom text box will have a more SQL Studio friendly query. I pasted the query from the above screenshot, and this is the result:
Please let me know if you find this useful. My guess is that if you use SQL Profiler a lot, this tool will save you some time.
The principle of least surprise (sometimes known as the principle of least astonishment in more posh circles) is an axiom of design: typically UI design, but also software design. The idea is that some object, operation, device, etc, should be obvious and consistent with its name/appearance. A trivial example: a "left click" should be done by pushing the button farthest to the left on the mouse. To do otherwise would be quite surprising, and make for a bad experience. (That sounds shockingly simple, but it's just an example).
I was thinking about this when I was writing some validation code. I was thinking about a user selecting a U.S. State in a dropdown. On some forms, it's required for the user to select a State, on other forms it's optional.
I wrote a class to help me manage a list of States/Provinces like so:
Elsewhere, I wrote code to use the IsValidState method to check to see if the user, in fact, selected a valid state or not. The first time I did this, it was on a form where the field is required. So, if user doesn't select a state, then IsValidState wouldn't even get executed.
But, later on, I reused IsValidState on a form where the state field is optional. What happens when the state argument is null? A big fat exception, that's what. So, I changed the method:
Is that the correct decision? Or should IsValidState only be called when there's an actual value? I think I made the correct decision, because null isn't a State. Another decision that could be made is throwing an ArgumentException if the argument is null or empty. However, I don't think the correct decision was to leave the method the way it was.
So now let's enter the land of hypotheticals in order to think more about the principle of least surprise.
What if, instead of being a boolean function, IsValidState instead acted upon a StateArgs object being passed in (and its name was changed to ValidateState). Let's suppose there is some reason for this, and that part of the design is a given. Suppose there's a Value string property with the State and an IsValid boolean property. (ASP.NET Validators, specifically CustomValidators, work like this: the validation method get an "args" object, and you can act upon it by manipulating args.IsValid). What would the correct behavior be then if args.Value is null? Clearly, args.IsValid shouldn't be set to true. So, should it be set to false, or should it just be left unchanged?
In this circumstance, ValidateState is probably one method call in a series of validation method calls (probably with some polymorphism involved with the parameter instead of a specific StateArgs class). So it seems like the least surprising thing to do would be to not make a decision (option A in the above source code). Since ValidateState does not return a value, it's not required to make a decision.
With my expanded focus, I decided to bring back my weekly link collection under the "Weekly Concerns" banner. Once again, this is just an excuse to avoid the work of having to write a real post.
- "using you're type's good by Gary Bernhardt" - a lightning talk from CodeMash 2014. Not quite as good as Wat (from CodeMash 2012), but still a very good piece of entertainment for developers.
- A news report from 1981 about the internet. Did you know that in the future you may read your newspaper ON YOUR COMPUTER!? "We aren't going to lose a lot [of money]..." Oh, you poor fool.
- An article about refactoring that I think demonstrates "sawtooth code" well
- Some code on-screen in an episode of Airwolf had a bug in it. Why do I know this? Internet.
- I recently moved this site to Windows Azure. This is the first site on Azure I ever had to move out of the "free" plan (since I'm using a custom domain name). I find this calculator to be very helpful when estimating what I'll be paying.