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...
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...
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 ...
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"
...
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....
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...
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...
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...
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...
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...
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 ...
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? 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 ...
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...
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.
...
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 ...
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...
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 ...
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...
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 ...