language-agnostic

What should I do to improve my code/style of programming?

I am sure you guys know me. I am the person from your offshore team whose code puts you off and at times makes you pull your hair (bcoz you can't pull mine). My programming concepts are quite okay (and I continuously try and improve them by reading blogs, articles). But, my code isn't up to the mark. It has got better with experience, bu...

Technical non-terminating condition in a loop

Most of us know that a loop should not have a non-terminating condition. For example, this C# loop has a non-terminating condition: any even value of i. This is an obvious logic error. void CountByTwosStartingAt(byte i) { // If i is even, it never exceeds 254 for(; i < 255; i += 2) { Console.WriteLine(i); } } Sometime...

How to find the mathematical function defining a bezier curve

Im trying to implement a bezier curve and line segment intersection test. The closest thing my searching has turned up is to take the bezier curve (lets limit it to three control points for simplicity) find the mathematical function generating that curve and place it on origo. Then, using the function for the line segment as another func...

Alpha and Gamma parameters in QLearning

What difference to the algorithm does it make having a big or small gamma value? In my optic, as long as it is neither 0 or 1, it should work exactly the same. On the other side, whatever gamma I choose, it seems the Qvalues get pretty close to zero really quickly(I'm having here values on the order of 10^-300 just in a quick test). How ...

algorithm for getting time zone from geo coordinates

Hi, I want to write app where user can point any place on map (not only cities) and get timezone in that place. What data structure (app will not have Internet connectivity) and algorithm should I use? Where I can obtain needed data (I wont more accuracy then divining map into 24 rectangles)? I will write my app in Java ME. ...

Is there an existing solution to the multithreaded data structure problem?

I've had the need for a multi-threaded data structure that supports these claims: Allows multiple concurrent readers and writers Is sorted Is easy to reason about Fulfilling multiple readers and one writer is a lot easier, but I really would wan't to allow multiple writers. I've been doing research into this area, and I'm aware of ...

Open Source Licenses: LGPL vs. Creative Commons

I'm writing a .NET library for the Stack Overflow pre-alpha API. After uploading some early code to a new project over at Google Code, I set the license info to GPL and added the appropriate license disclaimers to the code files. After posting an announcement on Meta, though, Kevin Montrose told me that LGPL is better. I have also looked...

Optimizing binary tree inserts to O(1) with hash map for write heavy trees

First of all I assume I've missed something major when thinking about this, but I still wanted to post about it to see if I really didn't miss anything, on with it... I have a pretty write heavy binary tree (about 50/50 between writes and reads), and on the way home today I was thinking about ways to optimize this, especially make the w...

Finding the translation between points

I have a map of the US, and I've got a lot of pixel coordinates on that map which correspond to places of interest. These are dynamically drawn on the map at runtime according to various settings and statistics. I now need to switch over to a different map of the US which is differently sized, and the top left corner of the map is in a...

String Compare "Logic"

Can anybody please tell me why the string comparisons below deliver these results? >>"1040"<="12000" True >> "1040"<="10000" False I've tried the string comparison in both C and Python, the result is obviously correct, I just can't figure out how the result is calculated... P.S.: I know that comparing strings of different lengt...

Parsing line and selecting values corresponding to a key

there is a set of data which is arranged in a specific manner (as a tree), as is given below. basically a key=value pair, with some additional values at the end, which informs how many children does the branch have and some junk value. 11=1 123 2 11=1>1=45 234 1 11=1>1=45>9=16 345 1 11=1>1=45>9=16>2=34 222 1 11=1>1=45>9=16>2=34>7=0 2234...

Have you ever restricted yourself to using a subset of language features?

Have you ever restricted yourself to using a subset of language features, and more importantly, why? I'm curious to find out who choose to use only certain language features and avoid others in order to win big in areas such as, but not limited to, memory usage, execution speed or plain old readability and maintainability. And by doing ...

Why don't managed languages offer the ability to manually delete objects?

Lets say you want to write a high performance method which processes a large data set. Why shouldn't developers have the ability to turn on manual memory management instead of being forced to move to C or C++? void Process() { unmanaged { Byte[] buffer; while (true) { buffer = new Byte[10240...

Have any identifier case readability studies been done?

Different languages have different standards for identifier casing. Most discussion I see about this subject revolves around a specific language, and is loaded with personal opinions. And these strong opinions all stem from the decision of one person or a group of people who created the language. I'd love to see a graph showing just how...

Language-integrated design patterns

Hi. I've noticed that getting started with design patterns is pretty difficult for beginners. Understanding the design patterns structure requires a lot of time. Applying the design patterns to your practice requires a lot of time too. Agree, you can't see the differences between various types of the design patterns for the first time if...

Diversify programming knowledge

I've taken courses, studied, and even developed a little by myself, but so far, i've only worked with Microsoft technologies, and until now I have no problems with it. I recently got a job in a Microsoft gold partner company for development in C#, VB.net and asp.net. I'd like tips on how to diversify, learning technologies other than th...

When to upgrade an existing program to new language features?

Imagine you have a program written e.g. in Java 1.4 or C# 1.0. Of course this program doesn't use generics and other language features that were introduced with later versions. Now some non-trivial changes have to be made. And of course, you already have a newer IDE/compiler so you could use Java 1.6 resp. C# 3.5 instead. Would you use ...

Is it possible to write a program that extracts a specific melody/beat/rhythm from a specific instument from a mixed wave (or other music format) file?

Is it possible to write a program that can extract a melody/beat/rhythm provided by a specific instument in a wave (or other music format) file made up of multiple instruments? Which algorithms could be used for this and what programming language would be best suited to it? ...

Is it ok to put comments about bug fixes in the source code?

And if so, where do you draw the line? My coworkers and I disagree on this subject. I have seen such things as // fixes bug # 22 to // fixed bug: shouldnt be decrementing i++; Is it ok if the change is fairly significant, and radically changes what the method was written to do? Or do you simply change the summary text of the metho...

Regex with 'include' list and 'exclude' list

I have a sentence (words delimited by spaces). I then have two lists of phrases (full or partial words i.e. contain no spaces): one is an 'include' list and the other is an 'exclude' list. A matching sentence will contain all phrases in the 'include' list (overlaps are OK, case insensitive) and none of the phrases in the 'exclude' lis...