It happens a lot, especially when working on legacy code, that you can’t figure out a “business logic” algorithm that isn’t already well documented. Sure, it’s in the code, but so are a million other things, and you can’t eyeball the part that does all the calculation. The client is asking for a change or a fix and you’re not sure where to start.
That’s when I think you can do three things at once: improve the overall structure, impose some unit testing, and solve the problem you were asked to. Refactoring does all of these. Continue reading “When you're stuck”
Does your Access database have sketchy column names with weird characters in them? Surround them with bracket characters so SQL will work.
Because it’s the beginning of the week, I’m again presenting more about programming .NET with an Access database.
Last week, I offered help with a confusing syntax error. Before that, I demonstrated the unique way Access handles JOIN. Today I have a tip on addressing poorly named columns in your code. Continue reading “Programming with Access? Know this about column names”
Today, it’s more about programming .NET with an Access database. Last time, I explained the unique way Access handles JOIN. This time, let’s talk about a syntax error that masquerades as a missing parameter.
Continue reading “Programming with Access? Know this about "No value given for one or more required parameters"”
Writing your own SQL statements against an Access database can fail in surprising ways. Here’s how to avoid one common problem: the three-way JOIN that won’t execute.
If you’ve ever implemented a small-scale WinForms .NET project with modest database needs, you’ve probably been tempted to keep it “simple” by using Microsoft Acess (.mdb) files.
Continue reading “Programming with Access? Know this about JOIN.”
If you’re inexperienced with traditional C-style null terminated strings, the std::string.c_str() method may yield puzzling results.
This question just came up on Stack Overflow. It reflects a pretty common misunderstanding of how C-style strings are represented by char pointers in both C and C++.
Greatly condensed, it goes:
- You read some data into a std:string object. You display the contents; it’s all there.
- You invoke c_str() on that std:string, and display its contents; it’s not all there.
Continue reading “A word about strings and pointers in C++”
How can you run tests on something where the “output” is the motion of a sensor arm, or the “input” is a stream of weather data?
I learned an interesting, although in retrospect somewhat obvious, technique from Michael Feathers’s great book, Working Effectively With Legacy Code.
Suppose you have a class that can’t be unit-tested in any automated way because it has side effects or requires user input. Or, in the case of my application, it drives hardware that I don’t actually have readily at hand. NUnit and the like provide input to methods and test the resulting output. How can you run tests on something where the “output” is the motion of a sensor arm, or the “input” is a stream of weather data?
The short answer is that you really can’t, but that shouldn’t stop you from setting up unit tests.
Continue reading “Mock me to my (inter)face”
Another late night at the Old Programmers’ Club. This time, Tony and The Smartest Guy I Know talk about how Microsoft ruined the static keyword.
Last night I regaled The Smartest Guy I Know, as well as drsweetie’s high school pal Tony, with tales of how Kids These Days Don’t Know Anything and Nobody Does Things Right. It was a scene to warm the bitter soul of any software curmudgeon.
“So there I was,” I began, “optimizing the heck out of an ASP.NET application…” And my audience groaned–although I’m still not sure whether it was because they know how the story simply had to end, or because I was the teller and they couldn’t be sure that it would ever end. Because my stories get to be like that sometimes.
Continue reading “At the Old Programmer's Club”
You never need to compare to true.
I spotted this in some ASP.NET today:
if (confirm("Are you sure?")==true)
You never need to compare something to true though:
if (confirm("Are you sure?"))
And the whole if-boolean-then-boolean construct can be refactored out:
return confirm("Are you sure?")
It’s less to maintain, less to look at, and simpler to understand. That is all.