Questions tagged [refactoring]

Refactoring is a disciplined technique for restructuring existing code, altering its internal structure without changing its external behavior. Open-ended questions about refactoring your code are off-topic for Stack Overflow, however they may be appropriate for Code Review.

When should I use this tag?

Refactoring questions may or may not be on-topic for Stack Overflow. To be suitable, questions must be specific. An open-ended question such as "How can I improve this [working] code?" is off-topic on Stack Overflow. It may be appropriate for Code Review.

What is refactoring?

The heart of the method is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

From the Refactoring Home Page.

Keeping the system in a consistent and correct state is ensured by unit testing after each change.

Books

Additional Resources

7934 questions
415
votes
14 answers

Method can be made static, but should it?

ReSharper likes to point out multiple functions per ASP.NET page that could be made static. Does it help me if I do make them static? Should I make them static and move them to a utility class?
dlamblin
  • 43,965
  • 20
  • 101
  • 140
405
votes
4 answers

How to use IntelliJ IDEA to find all unused code?

When I am in a .java file, the unused code is usually grayed out or has a green underline saying this code will probably (probably because of some weird JNI/Reflection corner cases) be unused. But I have this project with thousands of Java files and…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
364
votes
12 answers

Find and replace Android studio

Is there a way to find and replace all occurrences of a word in an entire project( not just a single class using refactor -> rename) and also maintain case, either in android studio or using a command line script? For example, Supplier has to go to…
sirFunkenstine
  • 8,135
  • 6
  • 40
  • 57
355
votes
19 answers

Detecting superfluous #includes in C/C++

I often find that the headers section of a file gets larger and larger all the time, but it never gets smaller. Throughout the life of a source file, classes may have moved and been refactored and it's very possible that there are quite a few…
shoosh
  • 76,898
  • 55
  • 205
  • 325
318
votes
21 answers

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…
knatten
  • 5,191
  • 3
  • 22
  • 31
226
votes
9 answers

Find unused code

I have to refactor a large C# application, and I found a lot of functions that are never used. How can I check for unused code, so I can remove all the unused functions?
Andre
  • 3,223
  • 4
  • 23
  • 19
195
votes
18 answers

How to simplify a null-safe compareTo() implementation?

I'm implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other goodies offered by the Java platform): public class Metadata implements Comparable { private String name; private…
Jonik
  • 80,077
  • 70
  • 264
  • 372
185
votes
8 answers

What are some alternatives to ReSharper?

I'm considering purchasing a ReSharper license, but are there any possible alternatives to ReSharper and how would you rate these compared to ReSharper? It doesn't necessarily have to be a free alternative, but I would just like to know how good…
Riain McAtamney
  • 6,342
  • 17
  • 49
  • 62
169
votes
19 answers

Is there a working C++ refactoring tool?

Does anybody know a fully featured refactoring tool for C++ that works reliably with large code bases (some 100.000 lines)? I tried whatever i can find again and again over the last years: SlickEdit, Eclipse CDT. They all were not at all usable.…
RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
164
votes
15 answers

How many constructor arguments is too many?

Let's say you have a class called Customer, which contains the following fields: UserName Email First Name Last Name Let's also say that according to your business logic, all Customer objects must have these four properties defined. Now, we can do…
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
157
votes
72 answers

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…
Sklivvz
  • 30,601
  • 24
  • 116
  • 172
150
votes
24 answers

When is a function too long?

35 lines, 55 lines, 100 lines, 300 lines? When you should start to break it apart? I'm asking because I have a function with 60 lines (including comments) and was thinking about breaking it apart. long_function(){ ...…
user58163
139
votes
22 answers

Unit testing for C++ code - Tools and methodology

I'm working on a large c++ system that is has been in development for a few years now. As part of an effort to improve the quality of the existing code we engaged on a large long-term refactoring project. Do you know a good tool that can help me…
Sakin
  • 3,367
  • 3
  • 23
  • 27
136
votes
11 answers

Could someone explain the pros of deleting (or keeping) unused code?

I have heard many times that unused code must be deleted from the project. However it is not clear for me "why?". My points for not deleting that are: Code is already written, and efforts are spent Code may be tested on syntetical and real…
Alex Turbin
  • 2,554
  • 2
  • 22
  • 35
128
votes
24 answers

What's the best way to refactor a method that has too many (6+) parameters?

Occasionally I come across methods with an uncomfortable number of parameters. More often than not, they seem to be constructors. It seems like there ought to be a better way, but I can't see what it is. return new Shniz(foo, bar, baz, quux,…
recursive
  • 83,943
  • 34
  • 151
  • 241
1
2 3
99 100