Politics, Weather, Photography, and the Dog
Monday 21 April 2014

I don't know how this little snippet of code got into a project at work (despite the temptation to look at the file's history):

Search = Search.Replace("Search…", "");

// Perform a search that depends on the Search member being an empty string
// Display the list of things you find

First, I can't fathom why the original developer made the search method dependent on a hard-coded string.

Second, as soon as the first user hit this code after switching her user profile to display Japanese, the search failed.

The fix was crushingly simple:

var localizedSearchPrompt = GetLocalizedString("SearchPrompt");
Search = Search.Replace(localizedSearchPrompt, string.Empty);

(The GetLocalizedString method in this sample is actually a stub for the code that gets the string in the current user's language.)

The moral of the story is: avoid hard-coded strings, just like you've been taught since you started programming.

Monday 21 April 2014 15:31:25 CDT (UTC-05:00)  |  | Software | Work#
Search
On this page....
Head-scratching software bug
Countdowns
The Daily Parker +3302d 02h 11m
2015 33d 12h 02m
Parker's 9th birthday 199d 11h 02m
My next birthday 280d 15h 07m
Categories
Aviation (342) Baseball (110) Best Bars (7) Biking (44) Chicago (904) Cubs (197) Duke (132) Geography (334) Higher Ground (5) Jokes (284) Kitchen Sink (654) London (54) Parker (191) Daily (204) Photography (144) Politics (303) US (1086) World (253) Raleigh (21) Readings (8) Religion (66) San Francisco (88) Software (204) Blogs (75) Business (226) Cloud (90) Cool links (134) Security (98) Travel (219) Weather (694) Astronomy (86) Windows Azure (59) Work (74) Writing (8)
Links
Archive
<November 2014>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Full archive
Blogroll
About
David Braverman and Parker
David Braverman is a software developer in Chicago, and the creator of Weather Now. Parker is the most adorable dog on the planet, 80% of the time.
Legal
All content Copyright ©2014 David Braverman.
Creative Commons License
The Daily Parker by David Braverman is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License, excluding photographs, which may not be republished unless otherwise noted.
Admin Login
Sign In
Blog Stats
Total Posts: 4565
This Year: 463
This Month: 36
This Week: 7
Comments: 0