refactoring

Refactoring Code: When to do what?

Ever since I started using .NET, I've just been creating Helper classes or Partial classes to keep code located and contained in their own little containers, etc. What I'm looking to know is the best practices for making ones code as clean and polished as it possibly could be. Obviously clean code is subjective, but I'm talking about ...

How to find unused/dead code in java projects

What tools do you use to find unused/dead code in large java projects? Our product has been in development for some years, and it is getting very hard to manually detect code that is no longer in use. We do however try to delete as much unused code as possible. Suggestions for general strategies/techniques (other than specific tools) ar...

What tools and techniques do you use to find dead code in .NET?

I've seen similar questions for java and VB.NET, but nothing general for .NET, or specific to C# yet. In the past, I've decorated methods with the Obsolete attribute (passing true so the compiler will issue an error, as described in MSDN). I'd be interested in seeing the suggestions of others (beyond tools like FxCop or ReSharper). Ed...

Coupling, Cohesion and the Law of Demeter

The Law of Demeter indicates that you should only speak to objects that you know about directly. That is, do not perform method chaining to talk to other objects. When you do so, you are establishing improper linkages with the intermediary objects, inappropriately coupling your code to other code. That's bad. The solution would be fo...

What is in your .vimrc?

Vi and Vim allow for really awesome customization, typically stored inside a .vimrc file. Typical features for a programmer would be syntax highlighting, smart indenting and so on. What other tricks for productive programming have you got, hidden in your .vimrc? I am mostly interested in refactorings, auto classes and similar productiv...

Clearing a list

I find it annoying that I can't clear a list. In this example: a = [] a.append(1) a.append(2) a = [] The second time I initialize a to a blank list, it creates a new instance of a list, which is in a different place in memory, so I can't use it to reference the first, not to mention it's inefficient. The only way I can see of retain...

Visual Studio: Is there a "move class to different namespace" refactoring?

I'm doing some architectural cleanup that involves moving a bunch of classes into different projects and/or namespaces. Currently I'm moving the files by hand, building, and then manually adding using Foo statements as needed to resolve compilation errors. Anyone know of a smarter way of doing this? (We're a CodeRush and Refactor! shop, ...

Ways to ASSERT expressions at build time in C

I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers). However, I'm concerned that with the volume of changes I m...

Tool for finding package namespace conflicts in java code

We have a number of projects that use the same and/or similar package names. Many or these projects will build jar files that are used by other projects. We have found a number of foo.util foo.db and foo.exceptions where the same class names are being used leading to name space conflicts. Does anyone know of a tool that will search a s...

Refactoring an application.

If you had to fix and stabilize a MVC application, where would you start: the Model, Controller or View? The problems are spread equally throughout the application, with bad programming practices that make it hard to add functionality. The application is written in PHP if it makes a difference. ...

Python, unit-testing and mocking imports

Hello, I am in a project where we are starting refactoring some massive code base. One problem that immediately sprang up is that each file imports a lot of other files. How do I in an elegant way mock this in my unit test without having to alter the actual code so I can start to write unit-tests? As an example: The file with the funct...

What would you do when you are about to add some new features to a large (and dirty) codebase which has virtually *NO* unit-testing code?

Martin Fowler says that we should do refactoring before adding new features (given that the original program is not well-structured). So we all want to refactor this dirty codebase, that's for sure. We also know that without unit-testing code it's very easy to introduce subtle bugs. But it's a large codebase. Adding a complete suite of...

Refactoring XSD Schemas

I'm working in a project which needs to clean up some third party XSD Schemas and I want to do some refactoring of common elements in them. There is any suitable tool to automate this? I tried by sfactor from XMLBeans but it doesn't work (it throws a weird exception which even Google can't answer!). ...

Re-factoring from Active Record to Data Mapper

have you re-factored from an Active Record to a Data Mapper pattern? what conditions prompted the switch? i'm primarily interested in web based applications, but would like to know the challenges that accompany such a move in any environment. ...

Help refactor function that takes lots of arguments.

Hi all, I was wondering if anyone would be able to help me refactor some code that I wrote a while ago. I wrote a wrapper for a COM object that only excepted strings as input, so in good OOP practice I wrapped the string up in a function so that it was easier to build and call. I was just wondering if anyone could think of a better w...

What ReSharper 4+ live templates for C# do you use?

What ReSharper 4.0 templates for C# do you use? Let's share these in the following format: [Title] Optional description Shortcut: shortcut Available in: [AvailabilitySetting] // Resharper template code snippet // comes here Macros properties (if present): Macro1 - Value - EditableOccurence Macro2 - Value - EditableOccurence ...

make bad code good

I got myself reading a article regarding changing the existing bad code into a good one. For reference, this is the link to the article http://www.javaworld.com/jw-03-2001/jw-0323-badcode.html?page=1 It broadly talked about the following Add comments Re-Factoring Code Break large classes into smaller classes Break large functions in...

Improving really bad systems

How would you begin improving on a really bad system? Let me explain what I mean before you recommend creating unit tests and refactoring. I could use those techniques but that would be pointless in this case. Actually the system is so broken it doesn't do what it needs to do. For example the system should count how many messages it s...

Is there a key combination in Xcode to implement a Protocol?

In Visual Studio if I define a class to implement an interface e.g. class MyObject : ISerializable {} I am able to right click on ISerializable, select "Implement Interface" from the context menu and see the appropriate methods appear in my class definition. class MyObject : ISerializable { #region ISerializable Members publi...

Renaming accessor/mutator methods in Eclipse?

Is there any way to automatically rename accessor/mutator when a variable they get/set gets refactored -> renamed (Eclipse 3.4)? ...