language-agnostic

Explaining a concept: Does showing code early make it clearer?

I guess this is a question that may interest many, so please discuss! :-) Now, imagine you want to show people you work with a concept for future development (like a new product or a new technology you want to introduce). Does it make sense to show code early or would you go with the PPT first? Or what would you recommend? ...

Is there a Dynamic Programming way to compute the k minimum spanning trees?

My teacher asked us to implement a Dynamic Programming solution to that problem, but I'm thinking one doesn't exist since I couldn't find it using Google. Anyway, given a graph and a k, say 3, you have to find the 3 best MSTs from it. If the graph is such that it doesn't have k subtrees, you can return either the same tree multiple time...

Language-independent tutorial or book on web-apps

Is there any language-independent tutorial or book for developing web applications? For example implementation of login procedures, photo-gallery making etc, not focused on any particular language? ...

How do you write quality code under duress?

Possible Duplicate: How do you manage to write high quality code very quickly? When emergency code fixes are required ASAP, how do you ensure that the code you're writing is better than the code you replaced? What processes do you keep when time is of the essence? ...

Accessing email in a transparent fashion

How could one go about accessing email without interfering in any way that would be visible to a user with standard email clients such as Thunderbird? P.S: I've marked this as both java and language-agnostic so the approach can be described in general steps or detailled programatically. ...

How forgiving should form inputs be?

I went to my bank website the other day and entered my account number with a trailing space. An error message popped that said, "Account number must consist of numeric values only." I thought to myself, "Seriously?! You couldn't have just stripped the space for me?". If I were any less of a computer geek, I may even have thought, "What? ...

How can I reduce this problem to the Tower of Hanoi (or solve it in the least number of iterations)?

Suppose there are 2n+1 holes and 2 sets of n sticks, one set white and another black. The sticks are initially organized so that the white sticks are left, there is a hole in the middle and the black sticks are right. A stick can move by either: 1) being placed on the hole next to it, if empty 2) jump the neighboring stick iff the neig...

What is Global data (Has the term become stretched)?

What exactly is global data? This may seem like a very rudimentary question but the reason I'm asking is because I'm wondering has the term become stretched over time - i.e it dosn't just apply to data in the "Global" namespace (in c++) or a variable that is available in every scope. So, what do you consider to be global data? ...

A or B, not both, not neither

Ever since reading Clean Code I have been trying to keep my code descriptive and easy to understand. I have a condition where either A or B must be filled in. But not both. And not neither. Currently the if statement to check for this condition is hard to follow at a glance. How would you write the following to make it clear at a gl...

Efficient Independent Synchronized Blocks?

I have a scenario where, at certain points in my program, a thread needs to update several shared data structures. Each data structure can be safely updated in parallel with any other data structure, but each data structure can only be updated by one thread at a time. The simple, naive way I've expressed this in my code is: synchroniz...

Code Golf: Four is magic

The puzzle A little puzzle I heard while I was in high school went something like this... The questioner would ask me to give him a number; On hearing the number, the questioner would do some sort of transformation on it repeatedly (for example, he might say ten is three) until eventually arriving at the number 4 (at which point he wo...

Generate a large random planar graph

What is the most efficient way to generate a large (~ 300k vertices) random planar graph ("random" here means uniformly distrbuted)? ...

How to create a simple glass effect

I am currently painting a light blue, partly transparent overlay over owner-drawn objects to indicate certain state. It's OK but I thought that it would be even nicer if I could at some sort of glass effect to further establish the idea that the particular object has "something" overlaid over the top of it. I thought that some glass str...

Custom Textarea Control/Component

I would like to create my own irregular shaped Text area control to be place on a webpage, which would be shaped in a sort of backwards L. Would this be possible to create in something such as adobe flash or silverlight? or is this not possible at all? I have tried searching for a few hours and have found nothing if anyone has any exper...

Elegant/Clean (special case) Straight-line Grid Traversal Algorithm?

I'm dusting off an old project of mine. One of the things it had to do was -- given a Cartesian grid system, and two squares on the grid, find a list of all squares that a line joining the center of those two squares would pass through. The special case here is that all start and end points are confined to the exact center of squares/c...

Operator Associativity Question

Most binary arithmetic operators are left-associative in most programming languages. However, most compilers are free to evaluate the operands of a binary operator in either order. Are these statements contradictory? Why or why not? EDIT This comes from the book I am reading "Programming Language Pragmatics" Chapter 6, Exercise 6.1, I ...

How to deal with merged objects/resources in a web app and in a RESTful API?

I have a web app that has lots of pages with a URL of the form /object_type/object_id/ which show this objects details. I also have a RESTful API, returning a JSON/XML representation of my objects (under /api/object_type/object_id/ ). (My objects are Laws and Bills, but I guess this question is rather generic). From time to time, I disc...

Unwillingness to see boilerplate code as a major issue? Why? Countermeasures?

Almost everywhere I worked I met lots of people who didn't care that they produced massive amounts of boilerplate code. For me this is one of the worst things ever, it leads to errors, it is boring and it increases the noise. Worst example may be even Microsofts unwillingness to give us a better syntax for this annoying "INotifyPropert...

How to write a safe code : Condition checking Vs Exception handling?

Conditional Checking: if denominator == 0: // do something like informng the user. or skipping this iteration. else: result = numerator/denominator if FileExists('path/to/file'): // open file read & write. else: // do something like informng the user. or skipping this iteration. Exception Handling: try: result =...

Generating random points within a hexagon for procedural game content

I'm using procedural techniques to generate graphics for a game I am writing. To generate some woods I would like to scatter trees randomly within a regular hexagonal area centred at <0,0>. What is the best way to generate these points in a uniform way? ...