language-agnostic

Reference table values in a war against magic numbers

This question bugged me for years now and can't seem to find good solution still. I working in PHP and Java but it sounds like this maybe language-agnostic :) Say we have a standard status reference table that holds status ids for some kind of entity. Further let's assume the table will have just 5 values, and will remain like this for ...

Marking deleted records in DB tables

Sometimes you want to mark a DB table record as deleted instead of deleting it permanently, right? How do you do that? So far I've been using a boolean "deleted" field but I'm not sure if it's a good apprach. ...

How it is called when write or read return less that requested?

What term should I use to describe situations (or bugs in software) caused by read, write, send, recv doing less work than expected? For example, write(fd, "123456", 6); may return 3 and we need to write "456" to finish our work. /* Still in doubt between "short write/read" and "data truncation" after reading answers. */ ...

Is it bad to have multiple return statements?

Possible Duplicate: Should a function have only one return statement? Hi, I have a code somethg like below: int method(string a ,int b , int c){ if(cond1) return -1; if(cond2 || cond3) return 3; if(cond1 && cond2) return 0; else return -999; } Does it perform badly when compared to having ...

Resources on how to design a framework

Are there any resources on how to design frameworks, i.e. tips and tricks, best practices, etc.. ...

Are preprocessors obsolete in modern languages?

Hello, I'm making a simple compiler for a simple pet language I'm creating and coming from a C background(though I'm writing it in Ruby) I wondered if a preprocessor is necessary. What do you think? Is a "dumb" preprocessor still necessary in modern languages? Would C#'s conditional compilation capabilities be considered a "preprocessor...

What makes a program inefficient?

are there any main factors in which the programs efficiency depends? ...

Bit Flipping in Hex

I have an 8 digit hexadecimal number of which I need certain digits to be either 0 or f. Given the specific place of the digits is there a quick way to generate the hex number with those places "flipped" to f. For example: flip_digits(1) = 0x000000f flip_digits(1,2,4) = 0x0000f0ff flip_digits(1,7,8) = 0xff00000f I'm doing this on an...

Method of transforming 3D vectors with a matrix

I've been doing some reading on transforming Vector3 with matrices, and am tossing up digging deeper into the math and coding this myself versus using existing code. For whatever reason my school curriculum never included matrices, so I'm filling a gap in my knowledge. Thankfully I only need a few simple things, I think. Context is th...

Strongly typed language.

Possible Duplicates: What is a strictly typed language? What are the key aspects of a strongly typed language? What does it mean that language is strongly typed? ...

Count the number of objects in an Image

I am investigating the possibility of image processing to identify certain objects and also count them in an image. I will be given a picture and I need to identify the number of boxes present in that image. Does anybody have any experience with any Machine Vision/ Image Processing libraries like ImageJ, Fiji, JAI, jMagick ,Java Visio...

Behavior Tree Implementations

I am looking for behavior tree implementations in any language, I would like to learn more about how they are implemented and used so can roll my own but I could only find one Owyl, unfortunately, it does not contain examples of how it is used. Any one know any other open source ones that I can browse through the code see some examples ...

Data structure name: combination array/linked list

I have come up with a data structure that combines some of the advantages of linked lists with some of the advantages of fixed-size arrays. It seems very obvious to me, and so I'd expect someone to have thought of it and named it already. Does anyone know what this is called: Take a small fixed-size array. If the number of elements you ...

Best practice - When to evaluate conditionals of function execution

If I have a function called from a few places, and it requires some condition to be met for anything it does to execute, where should that condition be checked? In my case, it's for drawing - if the mouse button is held down, then execute the drawing logic (this is being done in the mouse movement handler for when you drag.) Option one ...

Is it possible to create thread-safe collections without locks?

This is pure just for interest question, any sort of questions are welcome. So is it possible to create thread-safe collections without any locks? By locks I mean any thread synchronization mechanisms, including Mutex, Semaphore, and even Interlocked, all of them. Is it possible at user level, without calling system functions? Ok, may b...

Naming classes like "com.facebook.FacebookClient" vs "com.facebook.Client"

I'm looking for opinions or if there is an agreed way of doing this, regarding to naming namespaced classes. E.g.: com.facebook.FacebookClient vs com.facebook.Client Or javax.script.ScriptEngine; vs javax.script.Engine; I'm currently prefer the first name in each example but the extra word seems a bit wasteful. ...

Code Golf: Phone Number to Words

Guidelines for code-golf on SO We've all seen phone numbers that are put into words: 1-800-BUY-MORE, etc. What is the shortest amount of code you can write that will produce all the possible combinations of words for a 7 digit US phone number. Input will be a seven-digit integer (or string, if that is simpler), and assume that ...

Most elegant way to expand card hand suits

I'm storing 4-card hands in a way to treat hands with different suits the same, e.g.: 9h 8h 7c 6c is the same as 9d 8d 7h 6h since you can replace one suit with another and have the same thing. It's easy to turn these into a unique representation using wildcards for suits. THe previous would become: 9A 8A 7B 6B My question is - ...

Develop an classic UI or be bold with a newer design?

Forgive me if this is the wrong place but I am curious as to how other programmers feel about this topic: I am currently working on my portfolio site, it is being designed and built in silverlight 4. I initially started off with a typical stylised e-folio theme much like a standard website in terms of layout and flow. As I work more in...

Reusability, testability, code complexity reduction and showing-off-ability programming importance

There are lots of programming and architecture patterns. Patterns allow to make code cleaner, reusable, maintainable, more testable & at last (but not at least) to feel the follower a real cool developer. How do you rank these considerations? What does appeal you most when you decide to apply pattern? I wonder how many times code reu...