language-agnostic

Good graph traversal algorithm

Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node's connections is a long process (10 seconds lets say). Saving a node to the database also takes about 10 seconds. I can check if a node is already present in the db very quickly. Allowing concurrency, but not having more tha...

What are multi-threading DOs and DONTs?

I am applying my new found knowledge of threading everywhere and getting lots of surprises Example: I used threads to add numbers in an array. And outcome was different every time. The problem was that all of my threads were updating the same variable and were not synchronized. What are some known thread issues? What care...

bit twiddling: find next power of two

If I have a integer number n. How can I find the next number k > n : k = 2^i, with some i element of N By bitwise shifting or logic. Example: If I have n=123 how can I find k=128 which is a power of two: 2^7(=i) and not 124 which is only divisible by two. It should be simple, but it eludes me. ...

Creative Terminology

I seem to use bland words such as node, property, children (etc) too often, and I fear that someone else would have difficulty understanding my code simply because the parts' names are vague, common words. How do you find creative names for classes and components to make them more memorable? I am particularly having trouble with generi...

On scaling tags in a tag cloud

I am implementing a tag cloud on a mobile device. The details of data-model etc, are not particularly important here. My question is about the scaling of tags: What is the 'best' expression to map tag frequency to font size? I have looked at this post discussing linear and logarithmic scaling and this answer from Adrian Kuhn sketch of ...

Redundant Code Checking

Are there any tools that can find any private functions without any references? (Redundant functions) Reason being, that a function may have been created and called from a couple of areas, but as the project expands and grows, these two calls may have been removed and swapped with a better alternative. But the method may still remain. I...

Routing "paths" through a rectangular array

I'm trying to create my own implementation of a puzzle game. To create my game board, I need to traverse each square in my array once and only once. The traversal needs to be linked to an adjacent neighbor (horizontal, vertical or diagonal). I'm using an array structure of the form: board[n,m] = byte Each bit of the byte represe...

How do the protocols of real time strategy games such as Starcraft and Age of Empires look?

Hello, I'm interested in how the protocols (and game loop) work for these type of games; any pointers or insights are appreciated. I guess the main loop would have a world state which would be advanced a few "ticks" per second, but how are the commands of the players executed? What kind of data needs to go back and forth? ...

percentage difference between two text files

I know that I can use cmp, diff, etc to compare two files, but what I am looking for is a utility that gives me percentage difference between two files. if there is no such utility, any algorithm would do fine too. I have read about fuzzy programming, but I have not quite understand it. ...

DDD Repository Awareness of Other Repositories

Is it generally acceptable that one repository can access another repository? Specifically in this case, I have one aggregate root that uses another aggregate root to determine what entities to add. It falls along the lines of an Item/Item Type relationship. The reason that the Item Type is an aggregate root is that they are separatel...

When should I use eval (taking a string and executing it as code at runtime)?

I've often heard the argument (in javascript, but many languages have an eval-like feature) that using eval is "bad." The arguments being that most things you would think to use eval for can be done other ways, the fact that eval is very slow in most cases, and that it can allow users to input code to be executed (if proper precaution wa...

Emerging areas in Computer Science

Hi guys, probably in other countries things are like here in Brazil, and in the end of the college degree in Computer Science you have to develop, document and present a final project in some area. I'm just about to finish the course and I haven't started the project yet, well, I did it a lot of times but I wouldn't decide about what to ...

How to TDD functionality in a base mixin class from one of many leaf classes?

Hi guys, following on from this question (Developing to an interface with TDD), I'm still having some issues. I test-drove two classes into existence, both of which ended up shared some identical functionality. I refactored a common base class into existence, and all the tests still passed. So far, so tdd-tastic. I needed a third cla...

What technology problems arise from creating a markup language for email?

I am wondering what technology problems arise from associating a markup language to email? Without examining the language let us assume a hypothetical markup language exists with the following conditions: It meets all possible user-agent needs for properly structuring and defining content in email. It properly sanctions communications...

How do you unit test templating code?

For example, I have a piece of code that's generating a SQL*Loader control file from this template (using Python): template = """ LOAD DATA INFILE '%(file_path)s' APPEND INTO TABLE %(table_name)s FIELDS TERMINATED BY "%(delimiter)" OPTIONALLY ENCLOSED BY "" (\n%(column_specifications)s\n) """ There are only two ways that I can think o...

Horizontal Lines in Comments

I realize that this is largely up to personal preference, but I'm curious whether there are some clear drawbacks to the following; I find myself constantly dividing source code into logical groups (via "comments") within the same file. For example: //---------------------------------------------------------------------------- #includ...

High-level/semantic optimization

I'm writing a compiler, and I'm looking for resources on optimization. I'm compiling to machine code, so anything at runtime is out of the question. What I've been looking for lately is less code optimization and more semantic/high-level optimization. For example: free(malloc(400)); // should be completely optimized away Even if thes...

What is a predicate?

Being a hobbyist coder, I'm lacking some fundamental knowledge. For the last couple days I've been reading some stuff and the word "predicate" keeps reappearing. I'd very much appreciate an explanation on the subject. Cheers! ...

Why do newbie programmers seem to shy away from libraries?

I've noticed many questions on here from new programmers that can be solved using libraries. When a library is suggested, often times they respond "I don't want to use X library" Is it the learning curve? or ? Just curious! ...

Simulating a network down to particular process

I am trying to simulate a scenario where connection to the server of one process is down while the connection to another server is up. Just pulling the network cable won't work in my case since I need another process connection to stay up. Is there any tool for this kind of job? I am on Windows. Thanks! ...