Subj : Re: Is well written code a rare species ? To : comp.programming From : Giannis Papadopoulos Date : Sat Aug 13 2005 12:28 pm Phlip wrote: >>>>Here is something to think about: http://thedailywtf.com/ . > > > Alan Balmer wrote: > > >>Looks to me as if the entire site is dedicated to bad programming >>practices. Read top to bottom. > > > switch (state) > { > case Enumerations.PageState.Edit: > //Load Page Data > LoadPageData(); > break; > case Enumerations.PageState.Update: > //Load Page Data > LoadPageData(); > break; > case Enumerations.PageState.Add: > //Load Page Data > LoadPageData(); > break; > default: > //Load Page Data > LoadPageData(); > } > > Poetry! Especially the comments! > > Now let's guess how it got that way. Charitably. The programmer started with > something different in each branch: > > case Enumerations.PageState.Edit: > //Load Page Data > LoadPageData("Edit"); > break; > > Then the programmer upgraded LoadPageData to not need the string, and took > it out: > > case Enumerations.PageState.Edit: > //Load Page Data > LoadPageData(); > break; > > Now without the culture and tests to support strict Refactoring, the > programmer is stuck with code half one design and half another. Because it > works the risk of even taking the switch statement out is greater than just > leaving it in. Maybe someone will need it, some day. > > Like I said, this is the most charitable assessment. The least is someone > needs a new career... > After all, a good compiler would kill the switch and just call LoadPageData(). However, it is not a good programming practice and someone ought to take the risk to remove it... -- one's freedom stops where other's begin Giannis Papadopoulos http://dop.users.uth.gr/ University of Thessaly Computer & Communications Engineering dept. .