code-smell

Large number of variables inside a container class

Does anyone have any suggestions as to how to go about designing a container class, in C#, that has upwards of thirty variables contained within it? I have written it out as a set of variables, as there are a few different types, eg string or DateTime, however I am thinking that it would perhaps be better to house them all in a diction...

Are mutually-dependent child/parent namespaces a code smell?

I was looking at some dependency graphs for my primary personal project recently, and I noticed that I had a mutual dependency between objects in nested namespaces. E.g., I had an object in MyNamespace.Foo that implemented a generic interface in MyNamespace.Foo.Interfaces with that object as the generic parameter in the interface. name...

Static factory method gateway to internal factory - code smell?

Say I had a class that has a static factory method, like this: public class Table { public static Table OpenTable(string path) { ITableFactory fac = IoC.Resolve<ITableFactory>(); return fac.OpenTable(path); } } and a factory class that looks like this: internal class TableFactory : ITableFactory { i...

Example of Spring missuse

Our software shop does a big enterprisey system and one of its part is a sophisticated monitoring and log viewer tool. Recently one of our teems rewrote it, since previous version was really lacking some essential features. And it was really ugly. Since this team is bored with enterprisey stuff and they heard of IoC and Spring ("Seem...

Persuading the business that fundamental design flaws are worth fixing

This is the second project I've worked on where an incorrect assumption has been made in the design of the software. In both cases it has resulted in a solution that is: More likely to get bugs related to the flaw More messy to work with as workarounds are implemented to get around it Harder to understand as the assumption does not mat...

Managing internal dependencies

I'm having a bit of trouble figuring out how to manage the internal dependencies that I have in a SDK I'm developing, for some reason everything I try just seems to be hard to work with. Say I have these classes: class Table { Table(string name,IQueryProvider provider, IComObject comobject) {} } class TableFactory { Table BuildT...

Indications of possibly poor design

Hi I have a large code base. The whole code is in C. I feel that inappropriate attention has been given to design. What evidences should I look for in the C code base that are strong indicators of bad/poor design. And can some of theses indications be provided by some automated tools. Thanks Vivek Kumar ...

Is excessive use of this in C++ a code smell

I'm dealing with a large code base that uses the following construct throughout class MyClass { public: void f(int x); private: int x; }; void MyClass::f(int x) { ' ' this->x = x; ' ' } Personally, I'd always used and hence prefer the form class MyClass { public: void f(int x); private: int _x; }; void MyClass::f(int x)...

Object doesn't do anything after instantiation - bad code smell?

Hi, I should probably know things like this by now - but for some reason this one passed me by! I have an object that I instantiate - it's quite nifty as it also extends a superclass and does some stuff in the contructor - in fact all the vital parameters and method calls are handled in the constructor. After this I never call the o...

tool to detect C# code smells

I'm working with C# and I was hoping to find some tools akin to those I'm used to in Ruby and Ruby on Rails for detecting code smells. I'm referring to things like Roodi, Flay, Flog, Reek, Rcov, and Saikuro. It would be nice if the tool(s) integrated with Visual Studio 2008. I have ReSharper and it's nice for alerting me when I'm not ...

Does my code smell? Lots of empty, virtual methods

I have a class "Shape" which is a supertype of many other "shapes" in my app. I have lots of empty methods on the Shape class which are declared as virtual / overridable, so there is not really any default bahaviour. Of course, some sub-shapes implement these methods. I am really just using it so that I can treat all my shapes as Shape...

How do I convince my coworker that methods with 26 parameters are bad practice?

Title says it all... we've debated this without any progress. Closest related questions I could find: How many parameters are too many? Worst Java practice found in your experience? What “bad practice” do you do, and why? ...

MVC Design pattern smells?

I must have implement MVC dozens of times in the context of various toolkits. I've noticed there are a few things that keep cropping up in the implementation which I'm not completely comfortable about. I was wondering if these are indeed things I should be looking to avoid. For instance The eternal Model instance - In an Single documen...

The field must have a documentation header - Style Cop - Code smell?

I was just running style cop against some of my code and got a few: SA1600: The field must have a documentation header. Now don't get me wrong I like style cop, it's great when you work on a project with more then one person but this rule seems a bit excessive to me. Why would you want to add: /// <summary> /// blah blah bla...

C#: Replacement of enum that requires translation and enumeration.

We have some stuff that may be exported into various formats. Currently we have these formats represented by an enum like this: [Flags] public enum ExportFormat { None = 0x0, Csv = 0x1, Tsv = 0x2, Excel = 0x4, All = Excel | Csv | Tsv } Problem is that these must be enumerated and they also need a translation or des...

Single Responsibility Principle: do all public methods in a class have to use all class dependencies?

Say I have a class that looks like the following: internal class SomeClass { IDependency _someDependency; ... internal string SomeFunctionality_MakesUseofIDependency() { ... } } And then I want to add functionality that is related but makes use of a different dependency to achieve its purpose. Perhaps someth...

does an incorrect comment smell?

I just had a situation where I was reading some code while working on a bug and I noticed an incorrect comment (the code did not do what the comment said it did). I just thought "hmm, ok" and went on working on the bug. About an hour later I was back at that line of code, having determined that it had caused the bug. In fact, if the c...

Is an abstract CRUD controller a good idea?

We're developing quite a big application using ASP.NET MVC and at the beginning we saw that could be useful to have an abstract base controller with common CRUD actions (new, save, delete...) plus a default list action. In our case we have 20+ entities that are managed through this kind of controllers. That works and avoids duplicating ...

Is it OK to use a macro to specialize std::swap?

So, I have a macro. // swap_specialize.hpp #include <algorithm> #ifndef STD_SWAP_SPECIALIZE #define STD_SWAP_SPECIALIZE( CLASSNAME ) \ namespace std { \ template<> inline \ void swap( CLASSNAME & lhs, CLASSNAME & rhs ) \ { lhs.swap(rhs); } } #endif So then I have a class // c.hpp #include...

What is this code smell called?

I think of this as broken OOP. It's starting to grow like mold in our code base and I need to start talking with people about cleaning it up. Is there a common name for it? public void eat(Fruit fruit) { if (fruit instanceof Banana) { ((Banana) fruit).peel(); } else if (fruit instanceof Pineapple) { ((Pinea...