Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Thomas Krantz
Sep 7, 2009
  2306
(0 votes)

EPiCodeSmells

My thoughts on some code smells I’ve come across. These three are the ones that tend to turn my stomach the most.

Here goes..

Class properties for easy access to MainBody, MainIntro etc.

I often see a bunch of these duplicated in all templates, often disguised in a “#region Properties”, an obvious hint that I am in for a treat..

        public string MainBody 
        { 
            get 
            { 
                if(IsValue("MainBody")) 
                    return (string) CurrentPage["MainBody"]; 

                return String.Empty; 
            } 
        }
I have even seen code snippets in Visual Studio being used to generate these. This indicates the lack of sensible base classes. And if you want strongly typed Episerver properties, there are better ways.

Hardcoded ids in Web.config

When poking around a new project, one of the first things I generally do, is open up Web.config. I scroll down to the appSettings-element, and if I find 10+ custom keys, I can smell the lack of Admin tabs and/or Settings page.

Usually goes something like:

    <add key="ContactFormPage" value="12312" />
    <add key="ContactFormPageEN" value="54312" />
    <add key="ProductModulePageTypeId" value="93" />
    <add key="ModuleContactPageTypeId" value="38,39" />
    <add key="ModulePageTypeId" value="3" />
    <add key="MyCoolPageTypeId" value="42" />
    <add key="CalendarEventPageType" value="11" />
    <add key="DivisionStartPageTypeId" value="46" />
    <add key="404PageId" value="78781" />
    <add key="FileNotFoundPageId" value="12333"/>
    <add key="GenericErrorPageId" value="543"/>

Episerver comes with a “Pagetype” property type. Use it.

The Utils-class

Everyone got them. At least some version of it, duplicated from one project to another, tweaked and refactored along the way. It usually contains the all familiar StripHtml(), Ellipse(), PreviewText(), MyGetPropertyWithFallbackValue().

Not really a smell perhaps, but I sort it into the DRY category.

Thoughts anyone? I am sure you have experienced your fair share of smells, perhaps worse than mine…?

Sep 07, 2009

Comments

Sep 21, 2010 10:32 AM

I was worried you had found some smelly bits on EPiCode (http://www.coderesort.com/p/epicode). :-)

As for smelly code in general, I think I have seen more than is healthy. I guess it comes with the territory, as many web devs don't think about architecture, code quality and reusability. Getting the job done quickly is first priority.

Also, many newbies start with web development (and EPiServer), and are more concerned about why the html designer in Visual Studio does not work as well as shown on stage at the last Microsoft gig they attended. Not hardcoding page id's :-)

Thomas Krantz
Thomas Krantz Sep 21, 2010 10:32 AM

Yes wasn't it a witty headline? ;-)

Well many times it doesn't matter if the web dev thinks about quality and architecture, the project manager who rules the world doesn't care about things like that.

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog