code-smell

Code smells galore. Can this be a good company?

I am currently doing some contract work for a company. Now they want to hire me for real. I have been reading on SO about code smells lately. The thing is, I have worked with some of their code and it smells. Badly. They use incredibly old versions of MSVC (2003), they do not seem to use version control systems, most code is completely ...

Java: limit to nest classes?

A very poor style to code but sometimes unavoidable. It is an extreme example. So is there some limit for nesting classes? are they equivalent? how do you deal with such situations? Create library? Code new FileObject().new Format().new Words().new Some().new Continue someThing; ((((new FileObject()).new Format()).new Words()).ne...

Is a line formed by two points greater than 45 degrees off of the horzontal.

I am trying to find out if a line defined by two points is greater than or equal to 90 degrees compared to the horizontal. Here is the code I used bool moreThan90 = false; double angle = Math.Atan((double)(EndingLocation.Y - Location.Y) / (double)(EndingLocation.X - Location.X)); if (angle >= Math.PI / 2.0 || angle <= -Math.PI / 2.0) ...

Helper Casting Functions -- Is it a code smell?

I recently began to start using functions to make casting easier on my fingers for one instance I had something like this ((Dictionary<string,string>)value).Add(foo); and converted it to a tiny little helper function so I can do this ToDictionary(value).Add(foo); Is this a code smell? Also, what about simpler examples? For example...

Saving a reference to a int.

Here is a much simplified version of what I am trying to do static void Main(string[] args) { int test = 0; int test2 = 0; Test A = new Test(ref test); Test B = new Test(ref test); Test C = new Test(ref test2); A.write(); //Writes 1 should write 1 B.write(); //Writes 1 should write 2 C.write(); //Writes 1...

How to cope with developing against a poor 3rd party API/application?

Update: Based on the feedback, some good strategies are: Avoid geeky arguments, instead focus on problems that effect the application on the whole, not just problems for developers. Keep a bug list of problems with the product, explain how they effect the end users. Write a wrapper over the APIs, make your code modular so a different s...

Application wide messaging... without singletons?

So, I want to go for a more Singleton - less design in the future. However, there seem to be a lot of tasks in an application that can't be done in meaningful way without singletons. I call them "application wide services", but they also fall into the same category as the cross cutting concerns, which I usually fix via AOP. Lets take a...

Passing an array for setting variable

Hi, I often see this idiom when reading php code: public function __construct($config) { if (array_key_exists('options', $config)) { ... } if (array_key_exists('driver_options', $config)) { ... } } Here I am concern with the way the parameter is used. If I were in lisp I would do: (defun ct (&key optio...

Is this the correct way to process a large dataset?

I am tasked with rewriting our internal conversion software from vb6 to C# .net 4. The software will take a data source (it could be a flat file, mySQL, MS SQL, Access) and put it in to our MS SQL format. So yes I as the client I need to touch all 4,000,000 rows. Right now I am writing a MS SQL -> MS SQL module. Because I need to do many...

Generic callback mechanism overloads success handler as a means for flow control - code smell?

I'm fairly new on a project and ran across an interesting design paradigm for some asynchronous calls we make to the database (variables and function name altered): private void OnLogin(object selectedInitialState, AsyncEventCompletedCallback<EmptyAsyncEventArgs> userCallback, object userState) ...

Is html.renderaction code smell

I've recently started a new job where I've been thrown into a bug fixing role on an under development ASP.Net MVC application. I'm a big fan of using an MVC approach for web apps and built some hefty production apps on Maverick.Net starting back in 2004/2005 however this is my first time using the ASP.Net MVC framework for anything other...

How to deal with someone's ugly code gently?

I've recently been given the task of finishing an incomplete project for my University. It'll count as credit for one Class so I'll shave a month off of my studies! Here's the thing. The that was left behind is horrible: unorganized and not well thought-out. For example: Protected Sub btnAceptar_Click(ByVal sender As Object, ByVal e As...

Is repeatedly calling size() on a container (during loop) bad?

For efficiency reasons, I always avoid writing loops like this: for(std::size_t i = 0; i < vec.size(); ++i) { ... } where vec is an STL container. Instead, I either do const std::size_t vec_size = vec.size(); for(std::size_t i = 0; i < vec_size; ++i) { ... } or use the container iterators. But how bad is the first solution really...

Are strongly typed ASP.NET MVC views smelly for composite models

Consider 2 options for a real-world application that needs to build a model, a composite model if you will, from a variety of sources the choices for for using strongly typed views: Create a new custom class for the model with a property for each piece of information that needs to be passed to the view stage, Confine the models to the ...

Is checking whether a DataMapper (or other ORM) model is persisted a code smell?

I've found myself starting to leverage checking persistence to get my models to 'work'. It seems convenient and correct to include a persistence check. On the other hand, it feels a little shady, as if I was being overly cautious or breaking the ORM abstraction in a small way. An example might be: class Shipment include DataMapper:Re...

What's this pattern called?

Some I'm reviewing some code within my team's code base, where we traverse over one hierarchical data structure and build a new data structure from it. There are no nested loops -- every level of the hierarchy has its own dedicated function. So we have code like this: public void DoA(A a, Transform transform) { foreach(B b in a) ...

Is there an alternative to the Curiously Recurring Template Pattern?

I've caused myself some headaches over the past couple of weeks with the curiously recurring template pattern. Following on from these two questions of mine: What’s the correct way of retrieving my custom enumeration classes by their value? Why are my static objects not being instantiated when first access to the static class is a sta...

PMD code smell detection and refactoring

(I develop using JAVA and want to implement plugin in eclipse which can detect code smell and automate refactoring) 1) Initialy, I would like to find a smell detector library in order to get the smell existing in the class. I installed PMD plugin in Eclipse and try using it. I want to get all information which is represented in a views ...

"Monolithic" page classes - Is this a code smell?

I'm new to PHP and I'm trying to build a site for the first time without using a framework (n.b. I have nothing against frameworks, I just think I should learn to code from scratch before learning a framework on top of it. Sort of like learning Javascript before learning JQuery). I like OOP in concept, so I started there. I'm thinking o...

Does this method violate SOLID or has code smell?

Does this give any code smell or violate SOLID principles? public string Summarize() { IList<IDisplayable> displayableItems = getAllDisplayableItems(); StringBuilder summary = new StringBuilder(); foreach(IDisplayable item in displayableItems) { if(item is Human) summary.Append("The person is " + item.GetInfo()); else ...