Hi,
I am porting some code from C to C++ and I found this code:
if(ErrorCode >= SOME_CONSTANT)
{
Status = RETVAL_OK;
switch ( ErrorCode )
{
default:
Status = RETVAL_FAILED;
break;
}
}
This code generates a compilation warning:
warning C4065: switch statement contains 'default' but no ...
As part of learning C, I wrote the following code to combine directory name with file name. Eg: combine("/home/user", "filename") will result in /home/user/filename. This function is expected work across platforms (atleast on all popular linux distributions and windows 32 and 64bit).
Here is the code.
const char* combine(const char* p...
When coding and reviewing code, it's easy to spot places where a design pattern could be used. A chain of command here, a strategy there... It's tempting to dive in and apply patterns even though a better solution might be a switch or some simple if's.
Are there some rules or tips you've found valuable to estimate when to do the actual ...
I have code that looks something like this:
self.ui.foo = False
self.ui.bar = False
self.ui.item = False
self.ui.item2 = False
self.ui.item3 = False
And I would like to turn it into something like this:
items = [foo,bar,item,item2,item3]
for elm in items:
self.ui.elm = False
But obviously just having the variables in the list ...
so in my application I've got several different customers being "serviced". Each customer has their own implementations of various classes that are all based on interfaces.
With the latest customer being added, I've noticed there will be a lot of duplication of code from another customer but the other customer is in no other way relate...
Hi everyone,
I'm currently learning Zend Framework and now I am looking for a way to integrate it into an existing website. This website is coded in an extremely complex spaghetti way, and I am hoping that it will be easier to read by integrating it into Zend and slowly refactor it. How could i run legacy code and the zend framework + m...
When working with legacy code, and trying to create tests, I often break out dependencies from classes or methods so I can write unit tests using mocks for these dependencies. Dependencies most often come in the form of calls to static classes and objects created using the new keyword in the constructor or other locations in that class.
...
hi people,
I am getting some very weird behaviour from maven that I have never seen before. Basicaly I refactored some classes, like util.constants (lower c) to util.Constants (capital C), but when I run the maven build to produce a WAR from the command line (mvn clean install), it builds the war project with util.constants (lower c).
U...
I have code that looks something like this:
self.ui.foo.setEnabled(False)
self.ui.bar.setEnabled(False)
self.ui.item.setEnabled(False)
self.ui.item2.setEnabled(False)
self.ui.item3.setEnabled(False)
And I would like to turn it into something like this:
items = [foo,bar,item,item2,item3]
for elm in items:
self.ui.elm.setEnabled(Fa...
Python refactoring
Both the add and sub are very similar. How does one re-factor code like this? The logic is basically inverse of each other.
class point(object):
def __init__( self, x, y ):
self.x, self.y = x, y
def add( self, p ):
x = self.x + p.x
y = self.y + p.y
return point(...
i have the following code which has some duplication
private List<SelectListItem> GetDeskList(int deskId)
{
List<Desk> apps = Model.GetDesks();
List<SelectListItem> dropdown = apps.ConvertAll(c => new SelectListItem
{
Selected = c.Id == deskId,
Text = c.Name,
Value = c...
Is there any way, when doing e.g. a rename class refactoring with ReSharper, I can exclude certain files or projects in the solution from being searched?
I have one project in my solution that ReSharper takes forever to search through whenever I run a rename class, and I know that in 99% of the time, the refactoring does not affect this...
An application I inherited tracks lab test results performed on material samples. Data is stored in a single table (tblSampleData) with a primary key of SampleID and 235 columns representing potential test results. The problem is that only a few tests are performed per sample, so each row contains over 200 nulls. Actually, there is a sec...
i have a number of tables with a column called OrderId. I have just done a refactoring and i want to get rid of the Order table and i have a new table called Transaction. I want all tables that have an OrderId column to now have a TransactionId column
This is complete. I now need to populate the transactionId column. I have a mappi...
I have a class called DataStructures where I have a set of public static data structures that store objects. To add an object to a data structures is an involved process requiring a number of checks to be carried out, processes to be remembered and data to be rearranged. In another class called Foo, I need to add objects to the data stru...
I have the following function that takes a string as parameter and repeats it a number of times (also a parameter). I feel like this is something that's already in the framework or at least could be done better. Any suggestions?
private string chr(string s, int repeat)
{
string result = string.Empty;
for (int i = 0; i < repeat...
Hey,
I have two methods, one which counts the number of objects which are considered to have a lower value than a given object, and another which counts the number of objects which have a higher value than a given object. As you can probably tell, the two methods are practically identical:
public int countHigher(SomeObject a){
if (...
I'm using tinyxml to parse xml files, and I've found that error handling here lends itself to arrow code. Our error handling is simply reporting a message to a file.
Here is an example:
const TiXmlElement *objectType = dataRoot->FirstChildElement( "game_object" );
if ( objectType ) {
do {
const char *path = objectType->At...
Hello,
like this question I want to pass a function with arguments. But I want to pass it to built-in functions.
Example:
files = [ 'hey.txt', 'hello.txt', 'goodbye.jpg', 'howdy.gif' ]
def filterex(path, ex):
pat = r'.+\.(' + ex + ')$'
match = re.search(pat, path)
return match and match.group(1) == ex)
I could use t...
i'm creating NumericStepper and Slider component objects. both have very similar properties, except for a few. i'd like to refactor the code for creating them, but i'm not sure about the best way of doing so.
var numericStepper:NumericStepper = new NumericStepper();
numericStepper.width = 50;
numericStepper.minimum = 1;
numericStepper...