refactoring

How can I improve our CM.AppSettings references...

ASP.NET 3.5 Classes throughout our solution referenced ConfigurationManater.AppSettings[""] to get appSettings (from web.config). We decided we weren't happy with that. Folks were mistyping appSetting key names in code (which compiled fine), and it was cumbersome to track usages. And then there's the duplicated strings throughout the...

Resource for Refactoring tips geared towards JavaScript

Hi all, I'd like to start a discussion on the best resources for refactoring tips, with an eye towards Front-End JavaScript refactoring. A friend whose opinion I respect suggests this book, though it uses examples in Java. I understand that the principles of OO refactoring should translate to another language. Let's talk about refactor...

Refactoring (and testing) for performance

I have a library that provides a reflection API on top of describeType() (a method that returns an XML object with all the specs of a class or instance). Since this library is used in several other libraries and frameworks, I really want it to be as fast as possible. The problem I'm facing is that I'm not sure about the best approach to...

How I can refactor imap nmap vmap code in vim?

I can such code in my .vimrc file: imap <D-1> <ESC>1gt vmap <D-1> 1gt nmap <D-1> 1gt imap <D-2> <ESC>2gt vmap <D-2> 2gt nmap <D-2> 2gt imap <D-3> <ESC>3gt vmap <D-3> 3gt nmap <D-3> 3gt imap <D-4> <ESC>4gt vmap <D-4> 4gt nmap <D-4> 4gt imap <D-5> <ESC>5gt vmap <D-5> 5gt nmap <D-5> 5gt imap <D-6> <ESC>6gt vmap <D-6> 6gt nmap <D-6> 6g...

How to correctly refactor this?

I have trouble finding way to correctly refactor this code so that there would be as little duplicate code as possible, I have a couple of methods like this (pseudocode): public List<Something> parseSomething(Node n){ List<Something> somethings = new ArrayList<Something>(); initialize(); sameCodeInBothClasses(); List<Node> nodes...

Python: Can subclasses overload inherited methods?

I'm making a shopping cart app in Google App Engine. I have many classes that derive from a base handler: class BaseHandler(webapp.RequestHandler): def get(self, CSIN=None): self.body(CSIN) Does this mean that the body() method of every descendant class needs to have the same argument? This is cumbersome. Only one descenda...

How to refactor logging in C#?

In my services all exposed methods have: try { // the method core is written here } catch(Exception ex) { Log.Append(ex); } It's boring and ugly to repeat it over and over again. Is there any way to avoid that? Is there a better way to keep the service working even if exceptions occur and keep sending the exception details to ...

Getting jQuery to return an ajax object

Hello, The question title is a bit strange because I'm not exactly sure how to phrase the problem. The issue is that I have many links to which I want to bind a click event with an ajax call, and I'm just looking to refactor some duplicate code into a single area. The links I'm trying to bind an ajax call only have one thing that diffe...

Multiple presenters interaction

I have two views each with their own presenters and they need a two way communication between them. Like if the user name changes in View A, presenter A needs to notify presenter B of the change and vice versa. Should I create a high level presenter/eventHandler that gets notified when either A or B needs to trigger an event or is there ...

moqing static method call to c# library class

This seems like an easy enough issue but I can't seem to find the keywords to effect my searches. I'm trying to unit test by mocking out all objects within this method call. I am able to do so to all of my own creations except for this one: public void MyFunc(MyVarClass myVar) { Image picture; ... picture = Image.FromStrea...

Refactoring large method in .NET

Hi, If I have a large .NET method, I want to know if it is good practice to split it up into multiple methods or not. My concerns are: 1 - Is there any point creating a method if it will only be called once? 2 - If I'm calling a private method from within my class, I try not to use instance variables. Is this good or bad practice? Fo...

Rails helper methods

I'm doing some refactoring on a piece of code I have, and am thinking of moving some stuff from the model into helper methods. Nothing major, but my model does some screen-scrapping, and I need to treat (and filter) some of the strings returned, so they are passed back to the controller nicely formatted. I've been using helper methods ...

ASP.NET: Reusing the same Repeater ItemTemplate

I'm currently using a certain ItemTemplate for three repeaters that are all on the same page, but they are all bound to different data sources. Is there any way to refactor my web form without using a user control to easily refer to this template so I will only have to define it once? ...

What are the most frequent Code Smells encountered and for which languages?

Possible Duplicate: What are Code Smells? What is the best way to correct them? We've all run across (as well as produced) "code smells". There are many kinds as documented here. What I'm interested in is what's the funk responsible for the funkiest code. It is difficult when writing code to maintain the perspective needed...

How to refactor these generic methods?

UPDATE: I should have mentioned in the original post that I want to learn more about generics here. I am aware that this can be done by modifying the base class or creating an interface that both document classes implement. But for the sake of this exercise I'm only really interested in solutions that do not require any modification to t...

How far did DevExpress get with Javascript refactoring?

Over a year ago, I remember watching one of DevExpress evangelists previewing or at least promoting rich Javascript refactoring (beyond just limited intellisense) within the Visual Studio shell, I recall part of CodeRush/DevExpress product line. I was excited. On checking today (lmgtfy) I can find only very very limited reference to it...

What is a faster way of merging the values of this Python structure into a single dictionary?

I've refactored how the merged-dictionary (all_classes) below is created, but I'm wondering if it can be more efficient. I have a dictionary of dictionaries, like this: groups_and_classes = {'group_1': {'class_A': [1, 2, 3], 'class_B': [1, 3, 5, 7], 'class_c': [1, 2],...

remove duplicate code in java

class A extends ApiClass { public void duplicateMethod() { } } class B extends AnotherApiClass { public void duplicateMethod() { } } I have two classes which extend different api classes. The two class has some duplicate methods(same method repeated in both class) and how to remove this duplication? Edit Both ...

Turning one file with lots of classes to many files with one class per file

How do I turn one file with lots of classes to many files with one class per file? (C\C++) So I have that file with such structure: Some includes and then lots of classes that sometimes call each other: #include <wchar.h> #include <stdlib.h> //... class PG_1 { //... } class PG_2 { //... } //...... class PG_N { //... } ...

Method to concatenate 2 Strings in Java

I have a method in Java that concatenates 2 Strings. It currently works correctly, but I think it can be written better. public static String concat(String str1, String str2) { String rVal = null; if (str1 != null || str2 != null) { rVal = ""; if (str1 != null) { rVal += str1; } if (str2 != null) { rVal ...