I don't want to replicate code across overloaded constructors as below. How do I refactor it?
/// <summary>
/// Represents a pseudo-random number generator, a device that
/// produces a sequence of numbers that are normally distributed.
/// </summary>
public class NormalDeviate : UniformDeviate
{
double mean;
double standardDevi...
I have a few large projects I am working on in my new place of work, which have a complicated set of statically linked library dependencies between them.
The libs number around 40-50 and it's really hard to determine what the structure was initially meant to be, there isn't clear documentation on the full dependency map.
What tools w...
Suppose I have a model and a view that display this model properties.
public class UserModel
{
public string UserName { get; set; }
.................
}
somewhere in a view...
<%= Model.UserName %>
Now I rename one of the properties (say, UserName => FullUserName), VS will suggest to perform refactoring meaning project-wide ...
I'm refactoring some code in C++, and I want to deprecate some old methods. My current method for finding all of the methods looks like this:
Comment out the original method in the source file in which I'm working.
Try to compile the code.
If a compiler error is found, then make a note comment out the call and try to recompile.
Once th...
I'm in the middle of refactoring some code on my current project, and I'd like some input on if any design pattern exists for the following scenario.
I have a class which executes some logic and returns an object containing the results of said logic; Let's call this the Result object. The state information contained in the Result objec...
I have 3 tables.
1. Users 4 Cols
UserID - User - RealName - Flags
2. UsersGroups 2 Cols
UserID - GroupID
3. Groups 3 Cols
GroupID - Group - Flags
and I want to set the flags on the User table for User = 'Administrator' and apply the same to the Group table.
I have the following SQL that works, but I also have several flags that I ...
Phone number data in various formats (I've chosen these because the data coming in is unreliable and not in expected formats):
+1 480-874-4666
404-581-4000
(805) 682-4726
978-851-7321, Ext 2606
413- 658-1100
(513) 287-7000,Toll Free (800) 733-2077
1 (813) 274-8130
212-363-3200,Media Relations: 212-668-2251.
323/221-2164
My Ruby code t...
Hi, I'm testing a simple DAO layer with mockito but I found a problem, basically a hard to test interface and I was wondering if you could give me some insight...
This is the method I want to test:
public Person getById(UserId id) {
final Person person = new PersonImpl();
gateway.executeQuery(GET_SQL + id.getUserId(), new Resu...
There is a maintanble approach to build DOM with jQuery?
Take a look at the append method of this code...
$.getJSON("api/test", function(data) {
$.each(data, function () {
$("#tests").append($('<tr><td><input type="radio" name="' + this["name"] + '"/><td>' + this["name"] + '</td><td>' + this["descr"] + '</td></tr>'));
}...
Hi there,
When I do a refactoring such as renaming a field in netbeans, the hibernate mapping files are updated accordingly.
This could have bean a good thing if the whole files were not completely reformatted. So I would rather not have this feature.
Is there a way to disallow the modification of hibernate mapping files by netbeans?
...
I've too many methods that repeatedly do something like
Statement stmt = null;
ResultSet rstmt = null;
try {
stmt = conn.createStatement();
rstmt = stmt.executeQuery(...);
while (rstmt.next()) {
//handle rows
}
} catch (SQLException e) {
//handle errors
} finally {
try {rstmt.close();} catch (SQLException...
As I write some scripts, I usually reach a point where my code looks like this :
end
end
end
end
end
end
I don't know about you, but this look very ugly to me. Can something be done about this?
...
We're refactoring a long method; it contains a long for loop with many continue statements. I'd like to just use the Extract Method refactoring, but Eclipse's automated one doesn't know how to handle the conditional branching. I don't, either.
Our current strategy is to introduce a keepGoing flag (an instance variable since we're goin...
The object here is to update the UI. I normally do this on the client however this application uses the code behind. Anyways my question is I am trying to clean up these if else statements and I thought the strategy pattern may be appropriate. I don't need everything done for me but if you could give me a couple pointers to get going. Do...
Possible Duplicates:
Whats the worst piece of code you have come across?
Examples of some of the worst code youve had to manage?
This mess reminded of some of the stuff I've had to work on. I was wondering if anyone else had nasty refactoring war stories and especially if you found unique or helpful solutions.
...
I'm in the middle of an ASP.NET MVC project and recently installed the free trial of ReSharper 4.5. Immediately I realized the benefits, simply because of the refactoring it wanted me to do.
Things like inverting if statements to reduce nesting, changing some of my if/else statements that were returning Views to ?/?? operators - drastic...
After frequently coming across recommendation not to use leading and double underscores in C/C++ identifiers I decided to fix all our sources once and for all. What I need to do now is convert _Identifier to Identifier_.
Should I use a specialized tool for this task of regular expressions will do for this job? In latter case what is the...
I've got a class in my project and I want to move and rename that class to somewhere else in the project's namespace. I tried simply moving it, but then the program won't deserialize any settings saved under Properties.Settings.Default for that setting. Is there a way I can move it without losing all of the user's settings?
...
Is there any way to avoid the repetition of the type in this kind of declaration of a class member?
Dictionary<string, int> myDict = new Dictionary<string, int>();
...
Here is another old function I have from my C# 1 days, what would be a more elegant way to write it:
//method: gets the text in a string in front of a marker, if marker is not there, then return empty string
//example: GetTextAfterMarker("documents/jan/letter043.doc","/") returns "documents"
//example: GetTextAfterMarker("letter043.doc"...