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 +3367d 02h 24m
Berlin 9d 03h 24m
Parker's 9th birthday 134d 10h 49m
My next birthday 215d 14h 54m
Categories
Aviation (353) Baseball (110) Best Bars (9) Biking (44) Chicago (938) Cubs (197) Duke (133) Geography (341) Higher Ground (5) Jokes (284) Kitchen Sink (674) London (59) Parker (196) Daily (204) Photography (145) Politics (303) US (1110) World (261) Raleigh (21) Readings (8) Religion (66) San Francisco (93) Software (209) Blogs (79) Business (235) Cloud (90) Cool links (139) Security (101) Travel (244) Weather (718) Astronomy (91) Windows Azure (61) Work (93) Writing (10)
Links
Archive
<February 2015>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567
Full archive
Blogroll
About
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.
Legal
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: 4655
This Year: 41
This Month: 0
This Week: 0
Comments: 0