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#
On this page....
Head-scratching software bug
The Daily Parker +3611d 19h 20m
Whiskey Fest 26d 14h 23m
My next birthday 336d 03h 47m
Parker's 10th birthday 255d 17h 53m
Aviation (380) Baseball (114) Best Bars (10) Biking (46) Chicago (1038) Cubs (199) Duke (134) Geography (384) Higher Ground (5) Jokes (284) Kitchen Sink (742) London (86) Parker (207) Daily (204) Photography (171) Politics (312) US (1181) World (296) Raleigh (21) Readings (8) Religion (69) San Francisco (96) Software (235) Blogs (93) Business (261) Cloud (95) Cool links (157) Security (111) Travel (302) Weather (780) Astronomy (108) Windows Azure (65) Work (112) Writing (15)
<October 2015>
Full archive
David Braverman and Parker
David Braverman is the Chief Technology Officer of Holden International in Chicago, and the creator of Weather Now. Parker is the most adorable dog on the planet, 80% of the time.
All content Copyright ©2015 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: 4982
This Year: 368
This Month: 4
This Week: 0
Comments: 0