I have the following methods:
protected static void updateExistingSection(XmlDocument doc,
XmlNode rootNode, string sectionTag, CreateSection createSection,
Func<XmlNode[]> createChildNodes, Action<XmlNode> firstSection)
{
IEnumerable<XmlNode> sections =
getChildNodesByName(rootNode, sectionTag);
if (sections.Cou...
When I hack around, some code tend to get much bigger than originally planned. As this happens I usually introduce/collapse/merge namespaces, move files between them, move folders etc etc. Sometimes, if I don't have a clear picture of the end result, this is a real pain and really easy to just "skip". This leads the project deteriorate w...
$('.tabs a ').click(function () {
var a = $(this).attr('href');
if (a == '#tab-1') {
$('.btn-buy').hide();
$('.btn-sell').show();
} else {
$('.btn-sell').hide();
$('.btn-buy').show();
}
return false;
});
... it works, but the code is ugly, too many lines. Can it be reduced any further...
I have been working on some 10 year old C code at my job this week, and after implementing a few changes, I went to the boss and asked if he needed anything else done. That's when he dropped the bomb. My next task was to go through the 7000 or so lines and understand more of the code, and to modularize the code somewhat. I asked him how...
I have a class that is a "manager" sort of class. One of it's functions is to signal that the long running process of the class should shut down. It does this by setting a boolean called "IsStopping" in class.
public class Foo
{
bool isStoping
void DoWork() {
while (!isStopping)
{
// do work...
...
There's a really obvious refactoring opportunity in this (working) code.
bool Translations::compatibleNICodes(const Rule& rule,
const std::vector<std::string>& nicodes)
{
bool included = false;
// Loop through the ni codes.
for(std::vector<std::string>::const_iterator iter = nicodes.beg...
Hi,
We have very complicated code(still well written) which performs lot of stuff for a particular operation. Currently, this is performed in a service which talks to database directly. I have two goals for this service.
I want to simplify the organization of the code.
I want to be able to add more machines to scale in the future.
T...
I know there are jQuery cookie plugins out there, but I wanted to write one for the sake of better learning the jQuery plugin pattern.
I like the separation of "work" in small, manageable functions, but I feel like I'm passing name, value, and options arguments around too much. Is there a way this can be refactored?
I'm looking for sni...
Greetings!
I inherited a C#.NET application I have been extending and improving for a while now. Overall it was obviously a rush-job (or whoever wrote it was seemingly less competent than myself). The app pulls some data from an embedded device & displays and manipulates it. At the core is a communications thread in the main application...
I came accross the following code today and I didn't like it. It's fairly obvious what it's doing but I'll add a little explanation here anyway:
Basically it reads all the settings for an app from the DB and the iterates through all of them looking for the DB Version and the APP Version then sets some variables to the values in the DB ...
Visual Studio includes a refactoring function called "Extract Interface" that generates an interface based on a class implementation.
The extracted interfaces are Internal by default. Problem is, we end up changing nearly all of them to Public.
Does anyone know why it's Internal by default? Better yet, is there a way to customize th...
I am learning ruby and practicing it by solving problems from Project Euler.
This is my solution for problem 12.
# Project Euler problem: 12
# What is the value of the first triangle number to have over five hundred divisors?
require 'prime'
triangle_number = ->(num){ (num *(num + 1)) / 2 }
factor_count = ->(num) do
prime_fac = Pr...
I have this situation which is rather frustrating... I have some user controls where I would like to rename their namespace. However, when I do this my build fails because the .designer.cs file for pages that use the controls is still generating control declarations with the OLD namespace. Is this coming from the assembly? I can't reb...
Suppose I have a class with 2 static functions:
class CommandHandler
{
public:
static void command_one(Item);
static void command_two(Item);
};
I have a DRY problem where I have 2 functions that have the exact same code for every single line, except for the function that it calls:
void CommandOne_User()
{
// some code A
Comm...
Okay, so you have a load of methods sprinkled around your system's main class. So you do the right thing and refactor by creating a new class and perform move method(s) into a new class. The new class has a single responsibility and all is right with the world again:
class Feature
{
public:
Feature(){};
void doSomething();
...
Background:
I have been working on a platformer game written in C++ for a few months. The game is currently written entirely in C++, though I am intrigued by the possibility of using Lua for enemy AI and possibly some other logic. However, the project was designed without Lua in mind, and I have already written working C++ code for m...
Being new to this I really am trying to learn how to keep code as simple as possible, whilst doing the job it's supposed to.
The question I have done is from Project Euler, it says
Each new term in the Fibonacci sequence is generated by adding the
previous two terms. By starting with 1
and 2, the first 10 terms will be:
...
I've been looking for the Eclipse JDT refactoring tool which allows me to quickly change
if (...) {
Object x = blablabla;
}
to
Object x;
if (...) {
x = blablabla;
}
// insert code using x here
But I can't find it. Does something like that exist?
...
HTML:
<ul>
<li><a href="#tab1">tab1</a></li>
<li><a href="#tab2">tab2</a></li>
</ul>
<div id="tab1" class="tab-content">content 1</div>
<div id="tab2" class="tab-content">content 2</div>
jQuery
$('#mode li:first').addClass('active');
$('#mode li.active').append('<span class="arrow"> </span>');
$('#mode li a').click(funct...
I have the following (Python) code to check if there are any rows or columns that contain the same value:
# Test rows ->
# Check each row for a win
for i in range(self.height): # For each row ...
firstValue = None # Initialize first value placeholder
...