refactoring

How to convert this procedural programming to object-oriented programming?

I have a source code that is needed to be converted by creating classes, objects and methods. So far, I've just done by converting the initial main into a separate class. But I don't know what to do with constructor and which variables are supposed to be private. This is the code : import java.util.*; public class Card{ private static...

Refactoring c / c++ in vim (e.g. method extraction like in eclipse.)

Hi Is there any plugins or built-in method in vim for performing refactoring on c or c++ code, something like the refactoring tools in eclipse? I'm especially keen on the extract method refactoring tool from eclipse that will determine parameters from new method and typically also guess a variable to use as return value. ...

Should I go back and fix work when you learn something new/better?

Considering that we're all constantly learning, we've all got to come across a point where we learn something just awesome that improves our code or parts of it significantly. The question is, when you've learned some new technique, strategy or whatever, do your or should you go back to code that you know works, but could be so much be...

C++ brain teaser

I recently refactored code like this (MyClass to MyClassR). #include <iostream> class SomeMember { public: double m_value; SomeMember() : m_value(0) {} SomeMember(int a) : m_value(a) {} SomeMember(int a, int b) : m_value(static_cast<double>(a) / 3.14159 + static_cast<double>(b) / 2.71828) {} }; class MyClass ...

Suggestions on Working with this Inherited Generic Method

We have inherited a project that is a wrapper around a section of the core business model. There is one method that takes a generic, finds items matching that type from a member and then returns a list of that type. public List<T> GetFoos<T>() { List<IFoo> matches = Foos.FindAll( f => f.GetType() == typeof(T) ); L...

Is search and replace the only way to rename an asp control in the code behind file?

Is search and replace the only way to rename as asp control in the code behind file? I find this extremely annoying, but it is the only way I can find. Scenario: I'll find a variable that needs renaming (Usually to meet naming convention) I'll rename the variable in the aspx/ascx file. I'll have to go in the code behind files and sear...

Is there a better way to write the find_messages_by_slug_or_404 method?

In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug) if message.nil? raise Error404 end message end I find it not elegant and not very Rubist. Is there a way to improve it? ...

Quick help refactoring Ruby Class

I've written this class that returns feed updates, but am thinking it can be further improved. It's not glitchy or anything, but as a new ruby developer, I reckon it's always good to improve :-) class FeedManager attr_accessor :feed_object, :update, :new_entries require 'feedtosis' def initialize(feed_url) @feed_object = Fee...

Java: Best practices for turning foreign horror-code into clean API...?

Hello, everyone! I have a project (related to graph algorithms). It is written by someone else. The code is horrible: public fields, no getters/setters huge methods, all public some classes have over 20 fields some classes have over 5 constructors (which are also huge) some of those constructors just leave many fields null (so I can'...

Help with refactoring PHP code

I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty of 200 reputation I finally managed to write a working implementation: http://stackoverflow.com/questions/2466928/lawlers-algorithm-implementation-assistance I feel like I'm using too many variables and loops there though so I am trying to refactor the co...

How to make freelance clients understand the costs of developing and maintaining mature products?

I have a freelance web application project where the client requests new features every two weeks or so. I am unable to anticipate the requirements of upcoming features. So when the client requests a new feature, one of several things may happen: I implement the feature with ease because it is compatible with the existing platform I ...

linq null refactoring code

i have code public List<Files> List(int? menuId) { if (menuId == null) { return _dataContext.Files.ToList(); } else { return _dataContext.Files.Where(f => f.Menu.MenuId == menuId).ToList(); } } is it possible to make it only one line like return _dataContext.Files.Where(f => f.Menu.MenuId == men...

Removing unused local variables from .NET code

Is there a tool available that can scan a C# or VB.NET project and automatically remove all unused local variables? ...

Practical refactoring

I've read about refactoring and probably did it before I even knew about it, however I don't really know much about it is actually done and what it practically means. What, from your view, is refactoring? How and when do you do it? ...

Find unused classes in a .net project

I have a VS.NET 2008 project. Is it possible to check for classes that are not used anywere in the project? With FXcop I can find unused variables and unused code, but not unused classes. ...

Refactoring SQL

Are there any formal techniques for refactoring SQL similar to this list here that is for code? I am currently working on a massive query for a particular report and I'm sure there's plenty of scope for refactoring here which I'm just stumbling through myself bit by bit. ...

Is it possible to create a domain model for legacy code without refactoring?

I currently have a client that wants me to 'abstract' out a domain model from the existing code but they specifically said that I shouldn't refactor the existing code itself. My question is 1) whether or not this is advisable and 2) what techniques would you apply in this scenario if you can't refactor the code yet they expect you to com...

Etiquette for refactoring other people's sourcecode?

Our team of software developers consists of a bunch of experienced programmers with a variety of programming styles and preferences. We do not have standards for everything, just the bare necessities to prevent total chaos. Recently, I bumped into some refactoring done by a colleague. My code looked somewhat like this: public Person Cr...

Refactor instance declaration from try block to above try block in a method

Hi, Often I find myself coming across code like this: try { StreamWriter strw = new StreamWriter(); } However, there is no reference to the object outside the scope of the try block. How could I refactor (extract to field in Visual Studio says there is no field or something) the statement in the try block so that it is declared abo...

In sql server, is there any way to check whether the schema change will impact on the stored procs?

In SQL Server, is there any way to check whether the changes in the schema will impact Stored Procedures (and/or Views)? For example a change of the column name in one table, may break some Stored Procedures; how to check the impacted stored procs? ...