language-agnostic

Documenting getters and setters

For simple getters/setters, like the one below, what's the best way to document it? public float getPrice() { return price; } I'm pretty strict about coding standards, so my IDE warns me about any undocumented public/protected methods. Option 1: /** * Get the price field. * * @return */ Option 2: /** * @return Price */...

For any finite floating point value, is it guaranteed that x - x == 0?

Floating point values are inexact, which is why we should rarely use strict numerical equality in comparisons. For example, in Java this prints false (as seen on ideone.com): System.out.println(.1 + .2 == .3); // false Usually the correct way to compare results of floating point calculations is to see if the absolute difference agains...

Differentiate excel file types based on bytes, not extension

I currently have a method that receives a byte array of an excel file. It worked great, and I had it differentiating the file types (.xls, and .xlsx) based on the first two bytes in the file. If it's an .xlsx it started with a PK. Unfortunately, now I am getting .xlsm files sent, and I don't know what byte differs to tell them apart. ...

Asynchronous Observer Pattern.

Hi guys, I wanted to find out other ways to do Asynchronous Observer Pattern without using Message Queue. Ideas and examples are mostly welcomed. :-) (Think of this as a brainstorming session). PS Language preference is up to you. ...

Intersection of parabolic curve and line segment

I have an equation for a parabolic curve intersecting a specified point, in my case where the user clicked on a graph. // this would typically be mouse coords on the graph var _target:Point = new Point(100, 50); public static function plot(x:Number, target:Point):Number{ return (x * x) / target.x * (target.y / target.x); } Thi...

What patterns exist for translating data from one type to another?

I'm working on a project where I have to take data from one source and translate/tweak it so that it can be properly consumed by a different source, in this case, the database. I imagine this is a fairly common problem, and while I believe I'm off to a good start, I'm stuck as to how best to implement the middle part of the solution tha...

What are the legitimate uses for "method_missing"-type functionality?

Ruby has "method_missing", Tcl has "unknown", and most highly dynamic languages have an equivalent construct that is invoked when an undefined method is called. It makes perfect sense to add such functionality; something needs to happen, and there's no reason not to allow that something to be redefined by the programmer. It's rather triv...

Linking a facebook app's page to an existing facebook business page

I have a facebook app page, and a separate facebook business profile page. The business page was created, but not by me, some time before the app and its page were created. Is there any way to connect the two pages, or import the content and friends from one to the other? The older profile page has some content; a set of friends an...

Should I subclass or use enum?

I have many T arrays to read. Each T array can represent data of type A, B or C. A: A list of T B: A single T C: Exactly three T When I read a T array, I will be able to get a list of T, and determine by reading the first T in the list whether it's of type A, B or C. I thought of two possible approaches and would like to know their meri...

A name for a template-matching parameter

In my template-matching code I need the user to pass a floating-point parameter, which specifies whether the algorithm should concentrate only on the best matches (thus work faster) or analyse even low-probability areas (making it slower). The parameter is linear and normalized such that possible values are in range <0, 1>. It doesn't m...

Why does the JVM still not support tail-call optimization?

Two years after does-the-jvm-prevent-tail-call-optimizations, there seems to be a prototype implementation and MLVM has listed the feature as "proto 80%" for some time now. Is there no active interest from Sun's/Oracle's side in supporting tail calls or is it just that tail calls are "[...] fated to come in second place on every feature...

Formally constructing Control Flow Graph

Hi, Im writing a compiler for university project, and I would like to transform my Abstract Syntax Tree into a Control Flow Graph(CFG). Im thinking that the nodes(V) in the CFG should be nodes from the AST. I know algorithmically how to construct the edge set (G=(V,E)) but Im having a hard time writing the process a bit more formally ...

RRDTool and projects that use it (cacti etc) - HOWTO, storage, backup etc.

I want to create an application similar to cacti. I would like to store time-series data in a MySQL database (that is rotated on schedule). Where does cacti (nagios, zenoss) store polled data? a) in a MySQL database b) in a RRD database c) both? How does cacti (nagios, zenoss) make room for more data when it runs out of space? Ho...

Most effecient way to compute a series of moves in peg solitaire.

Given an arbitary peg solitaire board configuration, what is the most effecient way to compute any series of moves that results in the "end game" position. For example, the standard starting position is: ..***.. ..***.. ******* ***O*** ******* ..***.. ..***.. And the "end game" position is: ..OOO.. ..OOO.. OOOOOOO OOO*OOO OOOOOOO .....

Security/Authentication for Plugin Architecture

I was thinking of the multiple ways which security could be implemented in a Plugin-based system. Now when I say 'Security', what I mean is this: a) How developers of a Plugin system can ensure that plugins are secure and safe to use on the Core platform. b) How developers of a plugin can ensure that the plugins being used on their Plat...

Why is MVC so popular?

I was originally going to make this a longer question, but I feel like the shorter I make it, the better you'll understand what I mean. The MVC architectural pattern has 3 dependencies. The View depends on the model. The Controller depends on the View and Model. The Model is independent. The Layers architectural pattern defines N - 1 d...

Efficient way of finding all items within a given distance of a point.

Possible Duplicates: which data structure is appropriate to query all points within distance d from point p Storing objects for locating by x,y coordinates I have a list of items, each with a location in 2D space (specified using euclidean geometry, i.e. as an (x, y) coordinate pair). How should I store this list (e.g. hash...

Finding the optimum file size combination

Hello, This is a problem I would think there is an algorithm for already - but I do not know the right words to use with google it seems :). The problem: I would like to make a little program with which I would select a directory containing any files (but for my purpose media files, audio and video). After that I would like to enter in...

.NET method invocation interception

I need to intercept method invocations... please suggest a ready-made solution. It's necessary to block access to some methods (so calling them will generate an exception) ...

History of Namespaces/Packages/Modules?

I've been researching how different languages manage organization of source code. It appears most modern languages use some form of named abstract container. What its called and how its implemented varies from one language to the next but it boils down to a programming construct that operates beyond file boundaries to group related code....