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 +3177d 01h 27m
My next birthday 40d 10h 03m
Parker's 9th birthday 324d 11h 46m
Categories
Aviation (318) Baseball (104) Best Bars (4) Biking (43) Chicago (861) Cubs (192) Duke (132) Geography (309) Higher Ground (5) Jokes (282) Kitchen Sink (609) London (39) Parker (185) Daily (204) Photography (139) Politics (302) US (1049) World (239) Raleigh (20) Readings (8) Religion (62) San Francisco (83) Software (196) Blogs (71) Business (221) Cloud (88) Cool links (128) Security (98) Travel (162) Weather (669) Astronomy (76) Windows Azure (58) Work (37) Writing (8)
Links
Archive
<July 2014>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
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: 4396
This Year: 294
This Month: 33
This Week: 6
Comments: 0