Subj : Re: Is well written code a rare species ? To : comp.programming From : Joe Butler Date : Sat Aug 13 2005 12:45 pm I, honestly, wouldn't be bothered if I saw that code in something I was maintaining or collaborating on. (We're assuming that the code is correct in its logic and not a cut-paste error where it was the intention to edit each case.) We can see that there are 3 page states that might have specific handling, the comments are a bit redundant, but at least break up the code in colour syntax highlighters. So, really, it wouldn't bother me in the slightest. There are far worse examples of bad code. My experience is that well-written code is rare. By well-written code I mean code that doesn't frustrate anyone else who has to modify or work with it. I've experienced a few coders that are very selfish and will save themselves an hour's work by not introducing a straighforward way to interface with their code - even though it now means that the rest of the team each have to spend an hour trying to figure out how to correctly use their classes/modules/functions. This is a case of the example given elsewhere were the fastest coders are rewarded - no one bothers to measure how much the fastest coders actually slow down the rest of the team. The fastest coders, in my experience, are also the ones that will deny the presence of bugs in their code and don't bother to handle boundary conditions and other rare cases correctly - presumably this is because bug hunting would delay their current module's completion date. I've experienced a programmer that never bothered to handle errors (which made his code nice and neat to look at) - if an error occured while using his code, it was always our fault. Errors were passed to the caller by wrapping the whole thing up with a "throw everything". So, we were all supposed to know, somehow, what exceptions would occur and then how to handle them. I'm beginning to wonder if that programmer was a bit autistic - he'd adhere religiously to the 80 column programming 'standard' that got introduced by the mangler for some arbitary and ill-considered reason but would produce entire files with just one single line comment in them. P.S. I'm not the author the code below - but I'd happily take credit for it. (The only thing I'd have done differently is put a 'break' in the default case, and I'd probably have a line break after each case statement.) "Phlip" wrote in message news:fo9Le.629$UA1.603@newssvr30.news.prodigy.com... > >>> 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... > > -- > Phlip > http://www.greencheese.org/ZeekLand <-- NOT a blog!!! > > .