code-smell

Feature envy smell in my code, pls explain?

Eclipse (RedRails) complain about "Feature envy" in the following code: if input_text =~ /^(---\s*\n.*?\n?)(---.*?)/m content_text = input_text[($1.size + $2.size)..-1] # warning in $1 header = YAML.load($1) @content = content_text.strip() @title = header["title"] end My understanding is that I safe to ignore this warning. B...

Is an abundance of void, parameterless functions a code smell?

So I'm looking over some code I've written and noticed that most of the function calls are parameterless and return void. They tend to use public properties instead of arguments and return values. This was an outgrowth of the architectural pattern I was using and I just wound up extending it. The canonical example of MVP passive view has...

Is it a code smell for one method to depend on another?

I am refactoring a class so that the code is testable (using NUnit and RhinoMocks as testing and isolations frameworks) and have found that I have found myself with a method is dependent on another (i.e. it depends on something which is created by that other method). Something like the following: public class Impersonator { private ...

C#.NET - How Can I Get typeof() to Work With Inheritance?

I will start by explaining my scenario in code: public class A { } public class B : A { } public class C : B { } public class D { } public class Test { private A a = new A ( ) ; private B b = new B ( ) ; private C c = new C ( ) ; private D d = new D ( ) ; public Test ( ) { // Evaluates to "false" ...

Good ratio of catch statements to lines of code

Are there any rules of thumb as to how many catch statements you'd expect per source line of code in a large piece of software? For instance, in one piece of software written in C#, Visual Studio shows up about 350 lines containing the word "catch", and cloc reports that we have about 160k SLOC, 30k commented lines, and 15k blank lines....

boolean parameters -- do they smell?

I just found a bug caused by a boolean parameter... the caller thought it was controlling one thing but it was really controlling something else. So do boolean parameters smell in general? Personally, I don't feel comfortable when I see them. I mean: DoSomething(false); What the heck am I supposed to think when I read something lik...

Good limits for code refactoring

What are your preferred limits for, Lines per file Lines per function Nesting Are there other effective guidelines for limiting / settings (i.e. large font size)? FYI, I code mostly in Python along with some C,Java,Ruby etc. Edit: The reason I'm not asking about number of char columns is because 80 columns generally is the hard lim...

Too many constants?

Is there such a thing as too many constants in a project? What are some general rules of thumb about where the use of constants starts to become inappropriate and should be refactored? Perhaps moving some of these values into a model tier, or configuration files, etc. A concrete example. Using the pureMVC framework for Actionscript/Flex...

"it works-don't touch it" and continues engineering

Sometimes I work with bad smelling code. Yes, there's bad code out there :) I'm not talking about design problem but about much more simple things like: messy indentation non consistent use of empty lines a big banners introducing functions, which just repeat the function/method names non consistent name conversion, even in the same li...

When is Inversion of Control useful and when shouldn't it be used?

I've recently been bitten by code that uses Inversion of Control when it's not appropriate. Lately, I'm of the opinion that IoC is among the patterns that have the worst effect when misapplied. This is because it tends to create a coupling of classes that can cause a lot of shotgun surgery if you run into a circumstance that's a little...

Is it bad to use reflection to simplify constructors, comparisons, etc?

I hate having a bunch of "left/right" methods. Every time a property is added or removed, I have to fix up each method. And the code itself just looks ... wrong. public Foo(Foo other) { this.Bar = other.Bar; this.Baz = other.Baz; this.Lur = other.Lur; this.Qux = other.Qux; this.Xyzzy= other.Xyzzy; } Really this is ...

tool for detecting commented-out code

It is agreed by many that commented out code is a bad thing if you are using source control. (And it is agreed by many more, that if you are not using source control, that is even a worse thing). So the question is, do you know a tool that detected (too much) commented out code? Do you think such a thing would be a useful [[your-buil...

Is a public constructor in an abstract class a codesmell?

Is a public constructor in an abstract class a codesmell? Making the constructor protected provides all of the access of which you could make any use. The only additional access that making it public would provide would be to allow instances of the class to be declared as variables in scopes that cannot access its protected members, but ...

Is storing user configuration settings on database OK?

I'm building a fairly large enterprise application made in python that on its first version will require network connection. I've been thinking in keeping some user settings stored on the database, instead of a file in the users home folder. Some of the advantages I've thought of are: the user can change computers keeping all its set...

What are Database Smells? What is the easiest way to correct them?

Scott W. Ambler has put up a good list of basic database smells. It would be good to see how these can be corrected, what database refactorings can be applied as a remedy and if any smells are missing from the list. For "ground rules" when replying, take a look at question on programming smells if you please. ...

deadline shortcuts

Most of the time I write very maintainable and well design code(even at home). However I just wrote db + msword report app for my friend and code is really bad - lots of code duplication and development speed driven db design - I just dont care at all about this code. I just wanted to finish it fast and go to sleep. I came up with some ...

Best Place to Put SelectListItem Generators in ASP.NET MVC Application

In my first venture into ASP.NET MVC, I am coming across a few situations where I have dropdown lists that are limited in their purpose to a single view. A good example is that I have a signup form where a user has to put in their gender and birthdate. Once entered, nowhere in the application is it changed. For the gender, I build out...

Is the number of inherited interfaces on an object a code smell?

I've got an object (well 3 similar objects) that inherits from 6 interfaces: public class PaperContract : IDocument, ICanSell, IPrintable, INotifyPropertyChanged, IDataErrorInfo, ISerializeable The first signifies that this is a document which has properties for the file format it gets saved to and other ...

Defaulting to passing reference types using the ref keyword

I work with a developer who defaults to passing reference types such as StringBuilder, string and MemoryStream using the ref keyword. They do this regardless of whether they need to actually change the reference itself. public void ExampleMethod(ref MemoryStream ms) { byte b=ms.ReadByte(); ... // No changing of actual ms re...

C# code that generates javascript on the fly

Is it OK to generate code like this on the fly? Or is this a major code smell? How can this be made better? I'm new to web but I'm stumbling across this all the time and I don't really understand why. // Create a js function that applies foo to each group of controls foreach (KeyValuePair<string, Dictionary<Control, string>> pair in ...