language-agnostic

Worst Case Time Complexity for an algorithm

What is the Worst Case Time Complexity t(n) :- I'm reading this book about algorithms and as an example how to get the T(n) for .... like the selection Sort Algorithm Like if I'm dealing with the selectionSort(A[0..n-1]) //sorts a given array by selection sort //input: An array A[0..n - 1] of orderable elements. //output: Array A[0.....

Development Cost of Procedural Programming vs. OOP?

I come from a fairly strong OO background, the benefits of OOD & OOP are second nature to me, but recently I've found myself in a development shop tied to a procedural programming habits. The implementation language has some OOP features, they are not used in optimal ways. Update: everyone seems to have an opinion about this topic, as ...

Is "Out Of Memory" A Recoverable Error?

I've been programming a long time, and the programs I see, when they run out of memory, attempt to clean up and exit, i.e. fail gracefully. I can't remember the last time I saw one actually attempt to recover and continue operating normally. So much processing relies on being able to successfully allocate memory, especially in garbage c...

How can we identify "good code"?

There's already a great long post on identifying bad code (see Code Smells). I'd like to ask for the reverse. Do you know any good procedures or checks to identify good code? Quick pointers such as "the class definition fits on one page together with it's documentation", or "the code can be effortlessly re-used" would be great, longer...

Reimplementing ToUpper()

How would you write ToUpper() if it didn't exist? Bonus points for i18n and L10n Curiosity sparked by this: http://thedailywtf.com/Articles/The-Long-Way-toUpper.aspx ...

Automatic spell checking of words in a text

[EDIT]In Short: How would you write an automatic spell checker? The idea is that the checker builds a list of words from a known good source (a dictionary) and automatically adds new words when they are used often enough. Words which haven't been used a while should be phased out. So if I delete part of a scene which contains "Mungrohype...

How do I make an outgoing socket to a SPECIFIC network interface?

I have a server with two different network interfaces, each with a different IP address. How can I create a socket so it'll go out a specific IP address? I'd prefer a python example, but the question is language agnostic, so shoot away. EDIT: Please don't give me "You can't" as an answer. I mean, it is a computer. I can do anything I l...

Is Switch (Case) always wrong?

Are there instances where switch(case) is is a good design choice (except for simplicity) over strategy or similar patterns... ...

Left to right expression evaluation

In C# is it guaranteed that expressions are evaluated left to right? For example: myClass = GetClass(); if (myClass == null || myClass.Property > 0) continue; Are there any languages that do not comply? ...

When to rethrow an exception, when to return FALSE?

I am developing a wrapper for a third party function library that is interfacing with some special hardware. So basically, I want to encapsulate the dll functions (bool Connect(), void Disconnect() etc) in a MyHardwareObject with connect- and disconnect methods. The Connect function from the dll can throw some specific exceptions, for e...

When do you give up set operations in SQL and go procedural?

I was once given this task to do in an RDBMS: Given tables customer, order, orderlines and product. Everything done with the usual fields and relationships, with a comment memo field on the orderline table. For one customer retrieve a list of all products that customer has ever ordered with product name, year of first purchase, dates o...

Is there a more efficient way of creating a list of years/months?

On a page I want to dynamically list years and all the months in each year so an archive for each month can be viewed. I want to show the current year first but the current year may not be over yet so I only want to show the months that have passed, and the current month. Then I want all years and all months in the past since this year (...

What programmers should do to tackle information overload?

Any suggestions for concentrating on the relevant topics? ...

How to search for a person's name in a text? (heuristic)

I have a huge list of person's full names that I must search in a huge text. Only part of the name may appear in the text. And it is possible to be misspelled, misstyped or abreviated. The text has no tokens, so I don't know where a person name starts in the text. And I don't if know if the name will appear or not in the text. Example:...

runnable pseudocode?

I am attempting to determine prior art for the following idea: 1) user types in some code in a language called (insert_name_here); 2) user chooses a destination language from a list of well-known output candidates (javascript, ruby, perl, python); 3) the processor translates insert_name_here into runnable code in destination language;...

How could I add an entry to the right click menu ?

I'm not really sure how to google this one . I would like to know how would I add an entry to the right click menu in a Windows system . Something like "Open with ..." or "Archive with ... " . I would preffer a solution that works under Windows XP . ...

Generate colors between red and green for a power meter?

I'm writing a java game and I want to implement a power meter for how hard you are going to shoot something. I need to write a function that takes a int between 0 - 100, and based on how high that number is, it will return a color between Green (0 on the power scale) and Red (100 on the power scale). Similar to how volume controls wo...

Suggest logic to handle freeform movement over tile based system

I've got no experience with this, so i suspect my logic is overly complicated, or perhaps not complete enough to do what I want. I have a basic tile based system, but want to move units over the terrain in a coninuous fashion. Right now they are "teleporting" from one tile to another. I already have a lot of the game logic set up o...

What is the "Execute Around" idiom?

What is this "Execute Around" idiom (or similar) I've been hearing about? Why might I use it, and why might I not want to use it? ...

How do I apply gravity to my bouncing ball application?

I've written a fairly simple java application that allows you to drag your mouse and based on the length of the mouse drag you did, it will shoot a ball in that direction, bouncing off walls as it goes. Here is a quick screenshot: Each one of the circles on the screen is a Ball object. The balls movement is broken down into an x and ...