473,386 Members | 1,819 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,386 software developers and data experts.

Data dictionaries

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
1 2828
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lars Behrens | last post by:
Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and planning. The web site will have a submission page for...
0
by: Till Plewe | last post by:
Is there a way to speed up killing python from within a python program? Sometimes shutting down takes more than 10 times as much time as the actual running of the program. The programs are...
8
by: Frohnhofer, James | last post by:
My initial problem was to initialize a bunch of dictionaries at the start of a function. I did not want to do def fn(): a = {} b = {} c = {} . . . z = {}
3
by: Shivram U | last post by:
Hi, I want to store dictionaries on disk. I had a look at a few modules like bsddb, shelve etc. However would it be possible for me to do the following hash = where the key is an int and not...
210
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
9
by: SMB | last post by:
I have two lists of data like the following: LIST1 , ] LIST2 , 'label': 'First Name', 'width': 0L, 'separator': ',', 'height': 0L, 'type': 2L, 'order': 1L}, {'code': 14L, 'name': 'Last...
8
by: placid | last post by:
Hi all, Just wondering if anyone knows how to pop up the dialog that windows pops up when copying/moving/deleting files from one directory to another, in python ? Cheers
1
by: Nathan Harmston | last post by:
Hi All, I ve got a single module which I m using to contain a lot of dictionaries, constants, general information, which are used by various other modules. However I can't seem to access them: ...
4
by: Basilisk96 | last post by:
This topic is difficult to describe in one subject sentence... Has anyone come across the application of the simple statement "if (object1's attributes meet some conditions) then (set object2's...
3
by: csharpula csharp | last post by:
Hello, I would like to use a two ways data structure. Such as hash table that will provide me a mapping but to both sides and not only one side as it is in hash table. Is there such data structure...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.