By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,453 Members | 3,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,453 IT Pros & Developers. It's quick & easy.

Data dictionaries

P: n/a
I spent ALL day playing with named parameters instead of positional
parameters to functions, and ended up throwing it all away. C just
doesn't make that easy or clean.

But the basic gist of what I want, is this: I would like to create a
'data dictionary' that stores the data name and type. Whenever I need
a new function parameter or local variable, and it's manipulating an
item that is described in the data dictionary, I want to be able to
declare and use it without thought... I don't want to have to remember
or look up what type it is.

I have some sample code to show you. It's pretty short, which is
funny, considering all the complicated stuff I threw away earlier
today. >:-D But simple is good - maybe that means it will be easier to
use.

#include<stdio.h>
#include<memory.h>

#define ID __int64
#define AGE int
#define HEIGHT int
#define NAME char*

void Test(ID id, NAME name, AGE age, HEIGHT height)
{
printf("ID %I64d, Name %s, Age %d, Height %d\n", id, name, age,
height);

}

void main()
{
ID id = 64;
NAME name = "Sandy";

Test(id, name, 99, 145);

}

Does anyone have any thoughts about using this method?
Here's a couple of my thoughts:

1. I hate typedefs. I've shot myself in the foot once with them, stared
at the gory hole for a few minutes, and decided I was never gonna use
them if there was an alternative. This method doesn't use typedefs.

2. The decision on what to call a variable becomes easy. Look up the
variable in the data dictionary, use the uppercase version for the type,
the lowercase version for the variable.

3. It will help in the declaration of structures, as well... no more
hunting around for all references to a member (parameters, members,
etc.) when you change the type.

4. There is a possibility of collision with other uppercase constants
and such, but it doesn't look to be too difficult.

5. Being a #define instead of a table lookup, it doesn't slow down the
code or add to the memory requirements.

If there's something wrong with it, let me know!
If it's all good, yay. :-)

--Kami
Mar 5 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kami wrote:
I spent ALL day playing with named parameters instead of positional
parameters to functions, and ended up throwing it all away. C just
doesn't make that easy or clean.
No. (Shrug.)
But the basic gist of what I want, is this: I would like to create a
'data dictionary' that stores the data name and type. Whenever I need
a new function parameter or local variable, and it's manipulating an
item that is described in the data dictionary, I want to be able to
declare and use it without thought... I don't want to have to remember
or look up what type it is.

I have some sample code to show you. It's pretty short, which is
funny, considering all the complicated stuff I threw away earlier
today. >:-D But simple is good - maybe that means it will be easier to
use.

#include<stdio.h>
#include<memory.h>
What's this? Never mind; it doesn't seem to be used.
#define ID __int64
#define AGE int
#define HEIGHT int
#define NAME char*

void Test(ID id, NAME name, AGE age, HEIGHT height)
{
printf("ID %I64d, Name %s, Age %d, Height %d\n", id, name, age,
height);
I don't see any evidence here of anything I'd call a
"data dictionary." In fact, you haven't even been relieved
of the burden of remembering things about the types: How
did you know to use "%s" for name and "%d" for age and height?
(And what's that "I" modifier about? Some non-standard thing
related to the non-standard __int64, I'd guess -- and if
so, yet another thing the "data dictionary" didn't supply.)
}

void main()
When you threw away all that "complicated stuff," you
forgot to throw away this line.
{
ID id = 64;
NAME name = "Sandy";

Test(id, name, 99, 145);

}

Does anyone have any thoughts about using this method?
Here's a couple of my thoughts:

1. I hate typedefs. I've shot myself in the foot once with them, stared
at the gory hole for a few minutes, and decided I was never gonna use
them if there was an alternative. This method doesn't use typedefs.
This isn't a "thought," it's a statement about your
personal preferences. It has about as much relevance as
would "I hate parsnips."
2. The decision on what to call a variable becomes easy. Look up the
variable in the data dictionary, use the uppercase version for the type,
the lowercase version for the variable.
And if you need two such variables ...? Well, the obvious
thing would be to add a "decoration," as in

NAME myname, yourname;

.... which accomplishes two things: It shows how to modify your
naming convention in a clear and useful way, and it introduces
an error that may make you think again about typedef.
3. It will help in the declaration of structures, as well... no more
hunting around for all references to a member (parameters, members,
etc.) when you change the type.
I don't understand how using macros will help or hinder
the task of finding occurrences. Also, "when you change the
type" has always struck me as letting the tail wag the dog,
in this and in other contexts. C doesn't support a programming
style in which you suddenly say "I think I'll change NAME from
a char* to a long double, hey presto! it's done!" These much-
posited type changes are, in my experience, infrequent.
4. There is a possibility of collision with other uppercase constants
and such, but it doesn't look to be too difficult.
C offers very little to help avoid name collisions in
any case (pun intended).
5. Being a #define instead of a table lookup, it doesn't slow down the
code or add to the memory requirements.
I guess this is another reference to the "data dictionary,"
but I still don't see how any such thing enters the picture.
If there's something wrong with it, let me know!
If it's all good, yay. :-)
My guess is that you're trying to do something but that
I'm unable to make sense of your explanation of it.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Mar 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.