language-agnostic

Impact of learning a new language on productivity

Are there any scientific studies (and conclusions) about the impact of mastering a new programming language over previously learned programming languages? I'm particularly interested if mastering various languages can decrease average productivity. ...

Avoiding column name redundancy accessing SQL databases?

Hello, I'm working on a program using a SQL database (I use SQLite). What my program does is the following: Creates the tables in the database if they don't exist (on startup) Executes SQL queries (SELECT, UPDATE, DELETE) - decided by the user from the interface What I saw doing this is that there is a lot of redundancy. I give the ...

Is my programming logic correct here?

const char IsPressed = 1; // 1 const char WasHeldDown = 2; // 10 const char IsFirstPress = 4; // 100 char* keystates[256]; Class::CalculateKeyStates() { for(int i = 0; i < 256; ++i) { if(this->IsDown(i)) { keystates[i] |= IsPressed; // turn on if(keystates[i] & WasHeldDown) { ...

Collection Initialization Syntax, what for?

We just can use function like public static List<T> New<T>(params T[] items) { return new List<T>(items); } and more important it's better var list = new List<int> {1,2,3}; var list = List.New(1,2,3); So, when we really need to use it? Dictionary public static Dictionary<T, K> New<T, K>(T key, K value) { return new Dictio...

Mocks: How to avoid children talking to parents?

i'm trying to test an object by passing a mock owner. Originally PartD would be passed a PartB1 as its owner: PartD partD = new PartD(partB1); Now i want to test a feature of PartD by passing it a mock owner: PartD partD = new PartD(mockPartB1); This works okay, except there are things PartD does that depends on it knowing some sta...

Longest increasing subsequence.

Given an input sequence, what is the best way to find the longest (not necessarily continuous) non-decreasing subsequence. 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 # sequence 1, 9, 13, 15 # non-decreasing subsequence 0, 2, 6, 9, 13, 15 # longest non-deceasing subsequence (not unique) I'm looking for the best algorithm. I...

Regex named grouping

Can you have dynamic naming in regex groups? Something like reg = re.compile(r"(?PText|Or|Something).*(?PTextIWant)") r = reg.find("TextintermingledwithTextIWant") r.groupdict()["Text"] == "TextIWant" So that depending on what the beggining was, group["Text"] == TextIWant Updated to make the quesetion more clear. ...

Add extra information to exceptions

Assume I have method that reads customers from a csv file. When reading the file an exception occurs (e.g. IOException or FormatException). In most cases the method can't do anything about the errors but it can add extra information like file name, line number etc. The method's class got an IProgressAndErrorReporter dependency that is ...

Is it a good practice to catch all exceptions and re-throw them as a particular type of exception in terms of classification?

Hi! Is it a good practice to catch all exceptions and re-throw them as a specific type -basically to classify all the exceptions thrown from a particular part (or service) of an application? Something like: // This class is used to label all the exceptions occured on // Race Cars Service calls as RaceCarsServiceException public clas...

Calculating the smallest possible tree

Given a set of nodes, how can I construct a tree which links together all the nodes in a way which minimises max(max(degree), max(depth))? For example, given a set of five nodes, I could connect them like so: However, this is not minimal, since max(degree) == 4 and max(depth) == 1, a better tree would be: which has max(degree) == ...

Calculating a minimal tree for file transfer

I'm constructing a file sharing system which needs to transmit a single file to many peers. One single root peer has the entire file and needs to transfer it to all other peers. How can I best construct a tree of file transfers such that total waiting time is minimised? For example: In this tree, we need to wait 4 times before the tr...

Algorithm to find the lines bracketing one point

I have following task: In the program we should draw lines on a bit mapped display. An array of n pairs of reals (ai,bi) defined the n lines yi = ai*x + bi. The lines were ordered in the x-interval [0, 1] in the sense that yi < yi+1 for all values of i between 0 and n-2 and for all values of x in [0, 1] Less formally, the lines do...

how to move ball vibrate device?

who explain this show with programming theory?. i want to learn this show. Also how to move ball if you vibrate phone or computer? http://apps.facebook.com/sanalvideo/izle.php?id=6776 ...

Demystifying Web Authentication

I'm currently researching user authentication protocols for a website I'm developing. I would like to create an authentication cookie so users can stay logged in between pages. Here is my first bash: cookie = user_id|expiry_date|HMAC(user_id|expiry_date, k) Where k is HMAC(user_id|expiry_date, sk) and sk is a 256 bit key only known ...

When is it time to refactor code?

On on hand: 1. You never get time to do it. 2. "Context switching" is mentally expensive (difficult to leave what you're doing in the middle of it). 3. It usually isn't an easy task. 4. There's always the fear you'll break something that's now working. On the other: 1. Using that code is error-prone. 2. Over time you might realize that ...

Code Everyone Should Write

Put simply, what are some good practice applications that anyone who considers him/herself a programmer should write. ...

Is there such a thing as a super programmer?

Have you come across a super programmer? What identifies him or her as such? Also. how do you deal with a person in your team who believes he is a super programmer? Both in case he actually is or if he isn't? ...

Least amount of voters, given two halves.

One of my former students sent me a message about this interview question he got while applying for a job as a Junior Developer. There are two candidates running for president in a mock classroom election. Given the two percentages of voters, find out the least amount of possible voters in the classroom. Examples: Input: 50...

Language or package for drawing geometric diagrams

I am looking for a language, or package in an existing language, that is good for specifying and drawing geometric diagrams. For example, I would like to draw a hexagonal grid, with its dual triangular grid superimposed on it. Now, I could sit down, put some elbow grease in to work out the trig by hand and come up with some Postscript o...

Surprising Software Engineering Metrics

What's the most interesting/surprising Software Engineering metric you know? For example, I find that "50% of all projects are considered failures" is quite frightening. ...