Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I often have data that in some contexts I want to handle uniformly, but in other contexts I wish to differentiate it. For example, I could have a vector that is series of angles or a series of velocities, or a std::string that contains the current mode of a device or the name of that device instance. In some cases I want to operate on the specific information, such as modifying the angles or velocities using input data. In other cases I want to simply operate on all the data uniformly, such as serializing all of the strings or writing algorithms that will perform calculations for any device with a set of angles, or using a standard string algorithm. In yet more cases, physical devices will often have specific values that differ from one to another, like button differences between a wii remote and an xbox controller.

Has anyone put thought into designing and implementing data storage, algorithms, and device drivers in a maximally generic way and have insight or resources they can share?

One interesting document of note is the boost best practice handbook.

share|improve this question

closed as too broad by Ixrec, amon, MichaelT, durron597, enderland Jul 1 at 14:08

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

    
recommended reading: On discussions and why they don't make good questions –  gnat Jun 30 at 19:36
    
This question should be reasonably answerable. In C# the answer would be "generics." –  Robert Harvey Jun 30 at 19:37
1  
yeah one sure can cover C++ templates and C# / Java generics in an answer of reasonable size –  gnat Jun 30 at 19:46
    
I'm not sure you can cover Java Generics at all, to be honest. Martin Odersky, the designer of Scala, once wrote on the Scala mailinglist that he believes that there are maybe three people in the world who understand Java Generics. And he should know, in addition to being the designer of Scala, he also designed Java Generics and wrote the current incarnation of Sun/Oracle javac! (And from the tone and context of that mail, I get the impression he – the designer(!) – does not count himself among those three people.) –  Jörg W Mittag Jun 30 at 19:56
    
A simple illustrative example containing perhaps 3 data entries, two of different types, and one unique, with a simple function to extract and operate on the data generically would probably capture a useful answer. I know C++ templates quite well. –  Andrew Hundt Jun 30 at 19:57