473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What to name container "flavors"?

Hiya.

Frequently (as in at least twice now) I find that when I write some sort of
container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach is
to give the "generic" name to whichever flavor I write first and then add
modifiers to the other two whenever prodded to build 'em:

template<size_t NStates, typename TState>
class HiddenMarkovModel {...};

and a week later:

template<typename TState>
class RTHiddenMarkovModel { RTHiddenMarkovModel(size_t nStates)...};

and 3 weeks after that:

template<typename TState>
class DynamicHiddenMarkovModel { ... };

OK, truth is I've yet to need to code DynamicHiddenMarkovModel - bad
example. But:

template<typename TCell>
class Stack { Stack(size_t maxStates) ...};

template<size_t NStates, typename TCell>
class FixedStack {...};

template<typename TCell>
class DynamicStack {...};

has come up. Sort of a trivial question, how to name these things to reduce
average client surprise (library name entropy), but I am wondering how
y'all cope with this.

- Michael
Jul 23 '05 #1
2 1510
On 2005-06-30, Michael Olea <ol***@sbcglobal.net> wrote:
Hiya.

Frequently (as in at least twice now) I find that when I write some sort of
container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach is
to give the "generic" name to whichever flavor I write first and then add
modifiers to the other two whenever prodded to build 'em:


One way to do it is make it all the same class, and make the dynamic or
staticness a policy parameter.

struct dynamic {} ;

template <size_t i> struct static_fixed {} ;
struct rt_fixed {} ;

template <typename T, typename policy = dynamic> class Array ;

So now your classes would be called things like:

Array<Foo, dynamic> a1; // a dynamic array
Array<Foo, static_fixed<10> > a2; // a fixed array, sze known at compile time
Array<Foo, rt_fixed > a3(30); // a fixed array, size known at runtime

template <typename T>
class Array <T, dynamic > : private std::vector<T>
{
public:
typedef typename std::vector<T>::size_type size_type;
// etc ...

Array() : std::vector<T> () {}
Array(size_type N) : std::vector<T> (N) {}
template <typename iter> Array (iter i1, iter i2)
: std::vector<T>(i1,i2) {}
T& operator [] (size_type i) { return std::vector<T>::operator[] (i); }
const T& operator [] (size_type i)const
{ return std::vector<T>::operator[] (i); }

// blah blah
};

// Array<T, rt_fixed> is the same except some functionality needs to be
// restricted, e.g. resize, push_back, capacity, etc.

template <typename T, size_t i>
class Array<T, static_fixed<i> >
{
T impl[i];
public:
// blah blah blah ...
};

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2
Donovan Rebbechi wrote:
On 2005-06-30, Michael Olea <ol***@sbcglobal.net> wrote:
Hiya.

Frequently (as in at least twice now) I find that when I write some sort
of container I want at least two out of three possible versions:

o fixed max size known at compile time
o fixed max size known at run time
o max size is dynamic

The question is how to name the variants consistently. My usual approach
is to give the "generic" name to whichever flavor I write first and then
add modifiers to the other two whenever prodded to build 'em:
One way to do it is make it all the same class, and make the dynamic or
staticness a policy parameter.


Yeah. I gave that idea a good, hard, intense 5 minute's thought before
posting. My conclusion was that that is certainly the way to go when
feasible, but it probably only reduces rather than eliminates the problem -
there will still be cases where separate classes have to be written, and
named (I think). An interesting exercise would be to take that approach
with bitsets - have std::bitset and boost::dynamic_bitset fall out as
special cases of: bitset<Size_Policy>. No loss of functionality, no loss of
efficiency: easy, hard, or crazy?

struct dynamic {} ;

template <size_t i> struct static_fixed {} ;
struct rt_fixed {} ;

template <typename T, typename policy = dynamic> class Array ;

So now your classes would be called things like:

Array<Foo, dynamic> a1; // a dynamic array
Array<Foo, static_fixed<10> > a2; // a fixed array, sze known at compile
time
Array<Foo, rt_fixed > a3(30); // a fixed array, size known at runtime

template <typename T>
class Array <T, dynamic > : private std::vector<T>
{
public:
typedef typename std::vector<T>::size_type size_type;
// etc ...

Array() : std::vector<T> () {}
Array(size_type N) : std::vector<T> (N) {}
template <typename iter> Array (iter i1, iter i2)
: std::vector<T>(i1,i2) {}
T& operator [] (size_type i) { return std::vector<T>::operator[] (i);
} const T& operator [] (size_type i)const
{ return std::vector<T>::operator[] (i); }

// blah blah
};

// Array<T, rt_fixed> is the same except some functionality needs to be
// restricted, e.g. resize, push_back, capacity, etc.
Right. Maybe Array derives publicly from the parameterized Size_Policy,
which, if dynamic, has the enriched interface...

template <typename T, size_t i>
class Array<T, static_fixed<i> >
{
T impl[i];
public:
// blah blah blah ...
};

Cheers,


Cheers, and thanks for the ideas - Michael
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: rcb845 | last post by:
HI fellow php fans, I am blocked with a simple problem, at least it seems simple, but I cannot make it through. I want to execute a .php script in case of "error 404, page not found". I am...
0
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code...
6
by: Al Dykes | last post by:
I've just grabbed a PHP book and can deal with the syntax and now I need to decide to learn specific packages and features. Define "framework". What are the major framework flavors ? Under...
20
by: John Bailo | last post by:
http://www.joelonsoftware.com/articles/APIWar.html "So you've got the Windows API, you've got VB, and now you've got .NET, in several language flavors, and don't get too attached to any of...
2
by: Joe Lester | last post by:
Does anyone know if there's a way to embed the Postgres database inside an application... so that it runs transparently, without the user even having to know it's there? I would prefer to use...
93
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code...
2
by: SammyBar | last post by:
Hi all, I'm trying to send a message from ASP.NET to another PC by using MSMQ. I created my ASP.NET project by using Visual Studio 2005 but I initially set the project to be located on the File...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
2
by: HaifaCarina | last post by:
i have this unfinished java program and i can't figure out what is the problem.. please help... /** * @(#)Answer3.java * * * @author * @version 1.00 2008/1/17
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.