Quote:
Originally Posted by Gullanian
Who here is from London again? I just went to the London HN meetup was very cool, hundreds of people, free beer, some good talks and Joel Spolsky gave an interesting talk as well about how in communities it's important to naturally repel people you don't want as well as attract those you do which I thought was interesting.
If anyone is around for the next one let me know can go for a pint after!
I'm in. Where on HN do they post about the meetups?
On an unrelated note, I have a refactoring problem I don't know what to do about. I have a performance sensitive depth first recursive (iterative version with a custom stack showed lower performance and was far more complex) function that traverses a tree structure. I need to do pre and post processing and among the algorithms that traverse the tree. I have more than a few different algorithms that traverse the tree and do various calculations, but the only thing they share in common (for the most part) is the actual traversal code, but it feels like an incredibly bad idea to copy and paste that among the functions. What's twisting me up is that these functions use different numbers of variables and often have different local variables that they work with. Here is a simplified representation of how the algorithms might look:
Code:
void recurse(Node &node, .....) {
//possibly calculate some local variables to be use,
// or maybe not
for (c=0;c<node.numChildren;++c) {
//various code, possibly more temporary variables
//and either dealing with a leaf node or recursing further
}
//post processing, possibly using some of the
// temporary variables that have been modified
//while walking the children
}
I'll also add that my traversing code is far more complex than this as I exploit some properties of my tree to place certain types of nodes/leave in certain positions in the child array.
Is there anything I can do to not repeat myself without performance penalties?