language-agnostic

What is the best practice for returning a subclass or interface implementation from a method?

Disclaimer Please don't just vote to close this because the title looks subjective, and if it's been asked before please point me to the previous question in the comments and I'll delete this one -- I really did look high and low trying to find a previous question on the subject. Background Given I have the following interface and co...

What are the best practices for preventing SQL creep?

I have a webapp written in PHP using a MySQL database backend. This question could just as easily apply to any language and application trying to use an SQL database and MVC OOP design. How do you keep your SQL code restricted to the Model? There's a rather longer story specific to my case behind the question. As previously mentioned ...

Implementing Unit Testing and Acceptance Testing Halfway Through A Project

I am having a lot of headaches maintaining a website right now. Most often things would end up breaking after a couple of updates. This website was started by two developers in our team and then passed on to me. I was wondering if it would be alright to go with unit testing and acceptance testing considering that I'm halfway through the ...

Good algorithm for calculating ln(1-x) for small (and occasionally large) x

I'm looking for an algorithm to calculate ln(1-x). x is often small (<0.01), but occasionally it might be larger. Algorithm needs to be accurate, and not too slow. I'd rather not use library for ln(x), because I might lose accuracy. ...

Algorithm for online approximation of a slowly-changing, real valued function

Hi all, I'm tackling an interesting machine learning problem and would love to hear if anyone knows a good algorithm to deal with the following: The algorithm must learn to approximate a function of N inputs and M outputs N is quite large, e.g. 1,000-10,000 M is quite small, e.g. 5-10 All inputs and outputs are floating point values, ...

Whether variable name in any programming language takes memory space

e.g. int a=3;//-----------------------(1) and int a_long_variable_name_used_instead_of_small_one=3;//-------------(2) out of (1) and (2) which will acquire more memory space or equal space would be aquire? ...

What are "High-level modules" and "low-level modules" (in the context of Dependency inversion principle)?

I was reading Wikipedia's definition of Dependency inversion principle, and it uses those two terms, which I wasn't able to figure out.. What are they and what does Dependency inversion principle have to do with them? Thanks. ...

Keeping modules independent, while still using each other

A big part of my C++ application uses classes to describe the data model, e.g. something like ClassType (which actually emulates reflection in plain C++). I want to add a new module to my application and it needs to make use of these ClassType's, but I prefer not to introduce dependencies from my new module on ClassType. So far I have ...

Creating Fake Objects

Hello, I was just curious, afer seeing an ad on S/O, and clicking on it, then downloading it from Google Code... Why would anybody want/need to create a Fake Object? I don't object to it, or don't think there's anything wrong with it, I just really don't know. Thanks! ...

Design Patterns for adding jQuery features to a form control in PHP/jQuery (or other web languages)

I am using PHP and jQuery for a project. As some forms are reused across different functionality, I've coded a strategy class to render the forms. An example of one such class looks something like this: class strategy_render_member_form() { public function execute() { return '<form> <input type="text" name="us...

Best line equation to use for computational geometry.

Hi, I'm looking to write a little comp-geom library, in Ruby. I'm about to write the code for lines, and was wondering which line equation I should use: ax + by + c = 0 r + tv (where r and v are vectors) Thanks. ...

How to use a matrix to rotate the reference system of a vector relatively to another?

Real-life case (helps understand the question) I am building a device that can freely rotate around all its axis (x, y, z) and is equipped with: an accelerometer (A) that gives me a vector pointing to the centre of the Earth (Va) a 3D magnetometer (M) that gives me the direction of the magnetic field of the Earth (Vm) The two vector...

Producing Expressions from This Grammar with Recursive Descent

I've got a simple grammar. Actually, the grammar I'm using is more complex, but this is the smallest subset that illustrates my question. Expr ::= Value Suffix | "(" Expr ")" Suffix Suffix ::= "->" Expr | "<-" Expr | Expr | epsilon Value matches identifiers, strings, numbers, et cetera. The Suffix ru...

"if' VS "else if"

I'd been told, that using "if" statements is preferred , because of harder debugging of the code, when "else if" is used? Is there a grain of truth in this statement? ...

Group functions of similar functionality

Sometimes I come across this problem where you have a set of functions that obviously belong to the same group. Those functions are needed at several places, and often together. To give a specific example: consider the filemtime, fileatime and filectime functions. They all provide a similar functionality. If you are building something l...

Testing... how do the pros do it, and what techniques can scale to single-person development?

I've been writing software for years, but have never mastered the art of testing. My typical testing includes thorough run-throughs on my machines, and then testing in various operating systems via VMware. Mainly a brute-force play-with-it-until-it-breaks-or-doesn't approach. Where possible I work on actual hardware, but this isn't al...

What are the origins of foo, bar and baz?

Possible Duplicates: Using Foo and Bar in examples What do the placeholders foo, bar and baz mean? What are the origins of the placeholders "foo", "bar" and "baz"? Does anyone know for sure? ...

What pattern to use when invoking multiple external apps?

Given a set of external apps (app1.exe, app2.exe, ... ). Invoking one app will change something. Sometimes the result needs to be analyzed, sometimes is just a prerequisite for other apps. If one fails, abort process. All apps need to be invoked, in a specific order, and they must succeed in order to finalize without errors. Is there a...

How beneficial is it to learn Java in a job as a C# developer?

Hi, I am a C# developer. In my current job, I am learning a mix of Java and related languages (Clojure etc). How beneficial is it to a career learn Java too? Has anyone been in this position? Any examples of the benefits? Thanks ...

How does a program work which gathers data from another (not open source) program?

I play an MMORPG and there exists a third party program that can add things to the game's GUI. It can display your HP as a number (as opposed to the green bar), display how long until a power recharges, and other such nifty things. What I can't understand is how on earth the third party program can extract this data? The MMORPG is not ...