language-agnostic

How do I translate XML from one schema to another?

I want to translate xml documents with a certain schema into another schema. I know both the old and new schemas... I am planning to use python's xml.dom library , and translate line by line. Any ideas on how to go about it ? Any tools or libraries in other languages that might make this easier/more efficient. Thanks! ...

How to trigger a function once, and only once...?

I often want to trigger a certain function just once, but I need to trigger it from within another function that gets repeatedly called. For instance, taking a snapshot of something for later use. I usually do it by setting a global boolean. I'm wondering whether the way I do it is actually best way? I seem to recall reading that glob...

Is there a difference between foreach and map?

Ok this is more of a computer science question, than a question based on a particular language, but is there a difference between a map operation and a foreach operation? Or are they simply different names for the same thing? ...

What are some good examples of Mixins and or Traits?

I was reading up on Ruby, and learned about its mixins pattern, but couldn't think of many useful mixin functionality (because I'm not used to thinking that way most likely). So I was wondering what would be good examples of useful Mixin functionality? Thanks Edit: A bit of background. I'm Coming from C++, and other Object languages, b...

What do you call an object level equivalent of Mixin/Traits system, is there a Pattern name for it?

I previously asked about what Mixins were, and have begun to get the gist of what the pattern means. But it got me wondering if there is a common pattern name for doing something like Mixins at an Object level as opposed to the Class level. Pseudo code (in some non existent language): Class MyClass { function foo() { ...

How do you explain OO to new programmers?

My relative is studying programming and has a hard time understanding classes. He has trouble understanding for example that you need to instantiate it, that methods cannot access variables in other methods and if you change a variable in one instance of a class it doesn't change for other instances. I've tried to use analogies like a c...

How to design a good "progress panel"

For tasks that will take more than a few seconds, a good user interface, in my opinion, should provide a progress bar along with appropriate information on the progress of the operation. (Microsoft kindly provide User Interface Guidelines on this topic, but I want a status panel that is a bit more advanced.) The "task" class I am using ...

Should I use `!IsGood` or `IsGood == false`?

I keep seeing code that does checks like this if (IsGood == false) { DoSomething(); } or this if (IsGood == true) { DoSomething(); } I hate this syntax, and always use the following syntax. if (IsGood) { DoSomething(); } or if (!IsGood) { DoSomething(); } Is there any reason to use '== true' or '== false'? Is it ...

Generating a unique reference number strategies

Hrm... here's where my CS knowledge lets me down. I want to write an algorithm that generates a reference number that is unique. I don't want to use sequential numbers as they introduce a security risk and I want to use alphanumerics. The ref will have a min and max length too. (I can't use a GUID it is too long) Ideally I don't wan...

Have you come across any reason for three levels of indirection?

Just flicking through one of my favourite books (Ellen Ullman's The Bug) and there is a small bit where one programmer confronts another over three levels of indirection: ***object_array = ***winarray; I get the idea of double indirection - a way of passing a pointer into a function, and allowing it to point to an object created withi...

Shuffle a list (with duplicates) to avoid identical elements being next to each other

Hi, I am wondering if there is a "best" way to shuffle a list of elements that contains duplicates such that the case where array[i] == array[i+1] is avoided as much as possible. I am working on a weighted advertising display (I can adjust the number of displays per rotation for any given advertiser) and would like to avoid the same ad...

Creating dynamic maps on the web

My company uses a sales model of dealers, territory managers and regional managers, each with a different level of area scope (IE manage based on zips codes, states, or regions.) I want to create a slimmed down map that is similar to this US state map that would allow our users to manipulate who manages what. What are some good resourc...

Is there an alternative to hyper-indented code?

I often run into code that has to perform lots of checks and ends up being indented at least five or six levels before really doing anything. I am wondering what alternatives exist. Below I've posted an example of what I'm talking about (which isn't actual production code, just something I came up with off the top of my head). public ...

What is the necessity of IP-in-IP?

There is even a standard for IP in IP encapsulation. What is the use case here? I can understand stuff like TCP over DNS, where IP might be unavailable, but if you can do IP in IP, couldn't you simply do regular IP? ...

What's the best way to model an unordered list (i.e., a set)?

What's the most natural way to model a group of objects that form a set? For example, you might have a bunch of user objects who are all subscribers to a mailing list. Obviously you could model this as an array, but then you have to order the elements and whoever is using your interface might be confused as to why you're encoding arbitr...

Monitor changes to an arbitrary web page, and subscribe to the changes via RSS.

I've seen services like this before, where you give a URL and you're given an RSS feed of changes to the web page. But google is not turning up anything quite as simple/usable as what I'm remembering. Please submit one such service or solution per answer so that as the landscape changes they can be voted up or down accordingly. (Custo...

Is it a bad practice to have multiple classes in the same file?

I used to have one class for one file. For example car.cs has the class car. But as I program more classes, I would like to add them to the same file. For example car.cs has the class car and the door class, etc. My question is good for Java, C#, PHP or any other language. Should I try not having multiple class in the same file or is it...

IT Managers: When hiring, do you look for experience or education?

Okay...here's the short long story: I'm a graduate from a two-year programming course, earning my associate's degree (with honors, no less). Earlier this year, I had a brief stint where I tried to go back to school part-time for my Software Engineering BS degree, but that fell apart for various reasons which I won't go into here. I've ...

Functional programming: immutability etc.

I recently asked a question about functional programming, and received (good!) answers that prompted more questions (as seems to be the case with learning, sometimes). Here are a couple examples: One answer made reference to an advantage of immutable data structures: each thread can have its own copy. Now, to me, this sounds rather lik...

Should inheritance (of non-interface types) be removed from programming languages?

This is quite a controversial topic, and before you say "no", is it really, really needed? I have been programming for about 10 years, and I can't honestly say that I can recall a time where inheritance solved a problem that couldn't be solved another way. On the other hand I can recall many times when I used inheritance, because I...