language-agnostic

What is the cost of memory access?

We like to think that a memory access is fast and constant, but on modern architectures/OSes, that's not necessarily true. Consider the following C code: int i = 34; int *p = &i; // do something that may or may not involve i and p {...} // 3 days later: *p = 643; What is the estimated cost of this last assignment in CPU instructi...

What hash function yields the shortest output?

What is the shortest hash that can be obtained and why? What happens if you try to achieve a shorter one, is there a fixed limit or does it depend on the length of the hashed data and why? ...

Implementing Transparent Persistence

Transparent persistence allows you to use regular objects instead of a database. The objects are automatically read from and written to disk. Examples of such systems are Gemstone and Rucksack (for common lisp). Simplified version of what they do: if you access foo.bar and bar is not in memory, it gets loaded from disk. If you do foo.ba...

Shortest distance between points on a toroidally wrapped (x- and y- wrapping) map?

I have a toroidal-ish Euclidean-ish map. That is the surface is a flat, Euclidean rectangle, but when a point moves to the right boundary, it will appear at the left boundary (at the same y value), given by x_new = x_old % width Basically, points are plotted based on: * see edit (x_new, y_new) = ( x_old % width, y_old % height) Thin...

Number of characters recommended for a statement

Hi, I have been using Qt 4.5 and so do C++. I have been told that it's a standard practice to maintain the length of each statement in the application to 80 characters. Even in Qt creator we can make a right border visible so that we can know whether we are crossing the 80 characters limit. But my question is, Is it really a standard ...

Perls Of Wisdom For a .Net Programmer

Hi Guys, I like to think that recently I have moved from complete beginner to beginner. It has been a hard road and one on which I took many wrong turns. Very rarely in any profession is there a place where so many rock stars gather, this is something I would like to take advantage of. What I would like to ask is what are your perls of...

Regex not being greedy enough

I've got the following regex that was working perfectly until a new situation arose ^.*[?&]U(?:RL)?=(?<URL>.*)$ Basically, it's used against URLs, to grab EVERYTHING after the U=, or URL= and return it in the URL match So, for the following http://localhost?a=b&amp;u=http://otherhost?foo=bar URL = http://otherhost?foo=bar Unfortun...

How to deal with overlapping character groups in different tokens in an EBNF grammar?

I'm using an LL(k) EBNF grammar to parse a character stream. I need three different types of tokens: CHARACTERS letter = 'A'..'Z' + 'a'..'z' . digit = "0123456789" . messageChar = '\u0020'..'\u007e' - ' ' - '(' - ')' . TOKENS num = ['-'] digit { digit } [ '.' digit { digit } ] . ident = letter { letter | digit | '_' } . ...

Looking for web comic: number of words made up in protocols

There is this xkcd comic: I recently saw a version with "probability protocol is good" and a quote from the HTTP RFC (I believe). But I can't seem to find it anymore. Can someone help? (I need this to convince some of my co-workers that they're doing the design for a network protocol we're building wrong, so this question is programm...

How would you name...

Since naming is a so important thing in programming, I would like to start a thread for giving help to all those that have same problems as I sometimes. Rules: Set a post with the description of the form||control||class or whatever you need to find a good name for. Get name hints in the answers. ...

Algorithm to Render a Horizontal Binary-ish Tree in Text/ASCII form

It's a pretty normal binary tree, except for the fact that one of the nodes may be empty. I'd like to find a way to output it in a horizontal way (that is, the root node is on the left and expands to the right). I've had some experience expanding trees vertically (root node at the top, expanding downwards), but I'm not sure where to st...

How to implement three stacks using a single array.

Hi, I came across this problem in an interview website. The problem asks for efficiently implement three stacks in a single array, such that no stack overflows until there is no space left in the entire array space. For implementing 2 stacks in an array, it's pretty obvious: 1st stack grows from LEFT to RIGHT, and 2nd stack grows fro...

If you use MVC in your web app then you dont need to use Smarty(TemplateEngine) Right?

I'm just trying to understand the Templating(system). If you use MVC in your web application then you don't need to use something like Smarty(template engine) as you are already separating application code from presentation code anyway by using MVC right? please correct me? So am i correct in thinking it's MVC OR Templating or do you us...

Making legacy straightforward win.forms application code more clear

I have legacy win.forms application written in pretty straightforward approach where forms communicate with DAL on UI events. For example there are textboxes: login/password, button - "Login" and a click-handler where business logic is implemented (DAL is asked to get user by id/password, if not null - than show next screen, if null - sh...

Helper class(es) vs functional inheritance. Best practice

I have commands classes that implement ICommand { Execute } interface. Several commands have duplicate pieces of code. I have several options how to DRY: Create static helper class(es) and move duplicate code there Create commands inheritance with protected helper methods What would you suggest and why? ADDED Thank you everyone w...

Correct way to textually report the remaining time on a long running process?

So you have a long running process, perhaps with a progress bar, and you want a text estimate of the remaining time, eg: "5 minutes remaining" "30 seconds remaining" etc. If you don't actually want to report clock time (due to accuracy or resolution or update-rate issues) but want to stick to the text summary, what is the correct paradi...

General difference between structural program and object oriented program??

what's the General difference between structural program and object oriented program?? what OOP offers?? thank you all ...

RESTful service description

From what I understand, I need to use WADL to describe a RESTful web service. Still, I have read many answers in relevant posts, where users are strongly opposed the use of WADL. What are the disadvantages of WADL? Is there any alternative solution? ...

Any benefit/disadvantages to open beta vs. closed beta for webapp

This isn't a question about code, but it's programming related. We have a web app that's ready for beta testing. Has anyone noticed any difference between open beta vs. closed beta in terms of the quality or quantity of feedback the testers give or any other factors? ...

How do I generate a random string of up to a certain length?

I would like to generate a random string (or a series of random strings, repetitions allowed) of length between 1 and n characters from some (finite) alphabet. Each string should be equally likely (in other words, the strings should be uniformly distributed). The uniformity requirement means that an algorithm like this doesn't work: al...