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

7308 questions
387
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
  • 40,676
  • 19
  • 92
  • 127
342
votes
3 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
  • 29,060
  • 33
  • 127
  • 206
311
votes
19 answers

Detecting superfluous #includes in C/C++?

I often find that the headers section of a file get 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 #includes…
shoosh
  • 70,450
  • 50
  • 199
  • 310
309
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
  • 4,906
  • 3
  • 18
  • 26
305
votes
11 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
  • 7,007
  • 6
  • 34
  • 51
214
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
  • 2,983
  • 4
  • 20
  • 18
178
votes
9 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
  • 5,922
  • 17
  • 45
  • 60
170
votes
17 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
  • 74,291
  • 66
  • 249
  • 356
163
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
  • 11,294
  • 10
  • 48
  • 83
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
  • 28,698
  • 24
  • 111
  • 164
146
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
  • 39,694
  • 37
  • 117
  • 169
137
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
136
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
  • 2,997
  • 3
  • 21
  • 27
125
votes
3 answers

Coding Katas for practicing the refactoring of legacy code

I've gotten quite interested in coding katas in recent months. I believe they are a great way to hone my programming skills and improve the quality of the code I write on the job. There are numerous places where Katas can be found.…
mezoid
  • 26,370
  • 35
  • 104
  • 147
116
votes
2 answers

Using mixins vs components for code reuse in Facebook React

I'm beginning to use Facebook React in a Backbone project and so far it's going really well. However, I noticed some duplication creeping into my React code. For example, I have several form-like widgets with states like INITIAL, SENDING and SENT.…
Dan Abramov
  • 241,321
  • 75
  • 389
  • 492
1
2 3
99 100