@ wrote... (3 years, 6 months ago)

Every article I've ever read about technical debt always talks about how technical debt was a deliberate choice to get a product out the door quicker. In over fifteen years of professional development I've never, ever, seen that choice being taken on purpose. I have seen absolute horror shows of a code base brought on by:

  1. developers of questionable experience
  2. developers of questionable skill
  3. developers of questionable passion
  4. developers of questionable taste

Don't get me wrong, I've written stuff and been happy and proud of it but then six months later when I know more and understand the problem better I'm, to say the least, no longer proud of said code.

My point is, lets get off our high horse and stop pretending that shitty code was a choice called technical debt and own up to the fact that once upon a time the royal we wrote some crap and it's time to fix it.

Category: tech, Tags: programming
Comments: 0
@ wrote... (5 years, 3 months ago)

Do you have a function called Enable() and another called Disable(). Make those two private and make a third:

void Enable(bool enable) {
  if ( enable )
    Enable();
  else
    Disable();
}

// now change all your calling code from
if( x == y )
  Enable();
else
  Disable();

// to
Enable( x == y ); // 4 lines are now 1

As per my example above, four lines got compressed into one line but nothing actually changed. The algorithm is identical but you now have fewer lines to think about and worry about. And all of this multiplies. If you make that change 4 times you've removed 12 lines of potential bugs and oversights.

Category: tech, Tags: cpp, programming, simple
Comments: 0
@ wrote... (5 years, 4 months ago)

I've finally gotten around to uploading a little project I did years ago. any_config is a template class that implements a somewhat fancy prototype pattern.

Read about at github.com.

Category: tech, Tags: boost, cpp, programming
Comments: 0
@ wrote... (5 years, 7 months ago)

Don't check a pointer before deleting it, just delete it.

// don't do this
if ( p ) delete p;

// just do this
delete p;

// ie: this doesn't crash or do anything bad
int* p = NULL;
delete p;

// but you probably need something like this
#define NUL_DEL( p ) { delete p; p = NULL; }
NUL_DEL(p)

But seriously, this isn't the dark ages, you really want to be doing this.

std::shared_ptr<int> p;
...
p.reset(); // no need to set to NULL (or rather null_ptr)
Category: tech, Tags: cpp, programming, stl
Comments: 0
@ wrote... (5 years, 8 months ago)

Part of my Why is simple hard? series.

Do you even typedef bro?

more…

Category: tech, Tags: cpp, programming, simple
Comments: 0
@ wrote... (5 years, 8 months ago)

Part of my Why is simple hard? series.

Like most people with taste, I despise Hungarian notation. But, at the end of the day it really is only a style issue and easy enough to fix with a search & replace.

more…

Category: tech, Tags: cpp, programming, simple
Comments: 0
@ wrote... (5 years, 8 months ago)
Controlling complexity is the essence of computer programming.
Brian Kernighan

This has been bugging me for years, and it's getting worse. In some type of ironic paradox, it seems like the worst programmers are (in some ways) the best programmers.

more…

Category: tech, Tags: programming, simple
Comments: 0
@ wrote... (5 years, 9 months ago)

Although I doubt I'm forging into unknown territory, here is a nice little way I came up with to iterate around a box or square.

def next_coord( w, h ):
    """
    get the next x,y coordinates around your box
    w,h are the width and height of your box

    note, the strange ranges are to prevent getting the corners twice
    this loop configuration goes around clockwise from top left

    for x,y in next_coord(3,3):
        print "(%d,%d)" % (x,y),
    >>> (0,0) (1,0) (2,0) (2,1) (2,2) (1,2) (0,2) (0,1)
    """
    for x in range(0,w-1):        # top
        yield x,0
    for y in range(0,h-1):        # right
        yield w-1,y
    for x in range(w-1,0,-1):     # bottom
        yield x,h-1
    for y in range(h-1,0,-1):     # left
        yield 0,y
Category: tech, Tags: programming, python
Comments: 0
@ wrote... (8 years, 4 months ago)

A static variable in a class method are shared between all instances of that class and not per class instance.

#include <stdio.h>

class Foo {
public:

    int foo() {
        static int i = 0;
        i++;
        return i;
    }
};

int main() {

    Foo a, b;

    printf( "a: %d\n", a.foo() );
    printf( "b: %d\n", b.foo() );
}
a: 1
b: 2
Category: tech, Tags: cpp, programming
Comments: 0
@ wrote... (8 years, 10 months ago)

I still don't know what eigenvalues are, what they're for, or how to use them, but I needed to calculate them for work and make sure they were positive.

more…

Category: tech, Tags: cpp, programming
Comments: 0