Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / DB Theory / October 2007

Tip: Looking for answers? Try searching our database.

Types variables and values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David BL - 22 Oct 2007 04:23 GMT
In An Introduction to Database Systems,  C.J. Date, characterises
value, variable and type as follows:-

"value" : An "individual constant" - for example the individual
constant that is the integer 3.  A value has no location in time or
space.

"variable" : a holder for the appearance of a value. ... variables
unlike values can be updated.

"type" : a named set of values along with an associated set of
operators that can be applied to values and variables of the type in
question.

According to Date, a type by definition is abstract, and should not be
confused with a particular implementation of a type (which he calls a
"POSSREP").

It seems to me that these definitions are very important and useful
but neverthess don't capture a general enough notion of "variable" and
"type".

That being said they're certainly appropriate for the topic of the
book (Database Systems).

In the following it is convenient to use C++ code examples, while
tending to use Date's terminology.

Firstly, let's agree that these definitions are perfectly adequate for
the following types

   bool, int, float,  string,  Point, Circle,  Ellipse

I would call these "value-types", to distinguish from the following
Mutex class:-

   class Mutex
   {
       public:
           void Lock();
           void Unlock();
       private:
           < locking thread id, lock count, queue of waiting
threads ... >
   };

Consider the following declaration

   Mutex m;

Presumably we would say this declares a variable named 'm' of type
Mutex.   Is this compatible with Date's definition of "variable" and
"type"?

I would say it is inappropriate to regard a Mutex variable as holding
a "value" that exists independently of the variable.  That point of
view raises more questions than answers...

1.  What does it mean to assign a value to a mutex variable?  Assume
that the mutex variable is currently counting the number of times a
particular thread has locked it, and it has queued a number of threads
blocking in an efficient wait state on the call to Lock().

2.  What operations exist on Mutex values?

3.  What does it mean to copy the value in a mutex variable?

I can think of lots of examples where I would say that a variable has
state,  but logically doesn't represent a "value".

a  A node of a double linked list or  red black tree
b  A thread pool
c  A proxy for external hardware such as a printer or HDD

These types are characterised by not supporting copy and assignment
operations.

Do Date's definitions apply reasonably to pointers?   The answer would
appear to be yes, because it is certainly useful (and common
terminology) to distinguish between pointer types, pointer variables
and pointer values.   Pointer values can be assigned to pointer
variables.  Pointer values can be passed as arguments into functions,
or returned from functions.

However,  there is something strange going on. We would normally think
of values as existing independently of variables (and in fact the
abstract machine), and yet a (non-null) pointer value represents a
reference to a particular variable that exists in a particular running
process on a particular machine.
Marshall - 24 Oct 2007 18:40 GMT
> In An Introduction to Database Systems,  C.J. Date, characterises
> value, variable and type as follows:-
[quoted text clipped - 85 lines]
> reference to a particular variable that exists in a particular running
> process on a particular machine.

Just some general comments and responses:

Date's description of values is good. Also, different theories may
have
different things to say on the topic. ZFC set theory has only sets,
and
values are always sets. However there are other set theories that
admit values that are not sets.

As far as variables go, I am hesitant about describing them as being
necessarily "updatable" if by that we mean a destructive update
operator such as destructive assignment. (As distinguished from
initialization.) For example, consider:

 f(x) = x+1

 a = f(1)
 b = f(2)

Inside the body of f, x takes on the value 1 in one case and 2 in the
second case. One would expect to call x a variable, but x is not
updatable in some formal systems. (In some programming languages
x is an updatable entity that is initialized with a copy of the
argument,
but this is not always the case.)

Date's definitions (and his writings in general) assume a "single
level" model. Pointers and objects both introduce a multilevel
model. An object is both a variable, in that it can be updated,
and a value, the value being its identity. So you can have a
program with a local variable, that is initialized with an object
that is itself a variable. Code may update the variable to hold
a different object, or the underlying object itself may be updated.
So both of these constructs rather muddle the definitions of
value and variable.

This raises the question of whether the multilevel model is
a good idea or not. Various authors have pointed out a
number of negative consequences of this idea. My personal
experience bears out these arguments: local state in objects,
(which is necessarily unmanaged, the very antithesis of data
management) is a big source of bugs.

However, from a programming language design standpoint,
objects or something like them are devilishly hard to keep out.
For example, the combination of updatable variables,
first class functions and lexical scope combine to introduce
what is effectively objects. (Namely, stateful closures.)
If threads have state and can be communicated with, they
are effectively objects. The killer is that these are all
must-have features in my book. (I believe Date excludes
first-class functions and doesn't address concurrency,
but that's too harsh a solution for me.)

The real problem of objects from a data management
view is that unlike simple values, objects can change.
Imagine a relation with object values in it, and updating
those objects without invoking updates on the relation.
One imagines constraint checking would be bypassed.
Yuck.

Marshall
David BL - 25 Oct 2007 04:33 GMT
> Just some general comments and responses:
>
[quoted text clipped - 4 lines]
> values are always sets. However there are other set theories that
> admit values that are not sets.

In my opinion the OO community ignores the importance of values and
value-types.  I particularly like Date's treatment of subtyping of
value-types (which is about value substitutibility in contrast to
variable substitutibility).

There was an interesting thread on the circle/ellipse question back in
2001, and I thought Bob Badour argued the case well.

I have wondered whether a C++ like language could support the
following:

   float Perimeter(Rectangle r)
   {
       return 2*(r.Width() + r.Length());
   }

where it is assumed that Rectangle is a value-type with no assumed
implementation.  Therefore the compiler treats Perimeter as a
parameterised function.   This allows the compiler to generate an
implementation that simply returns the value 4 for a UnitSquare -
because it is a subtype of Rectangle where Width() and Length() return
1.

This is getting our cake and eating it too : code reuse and
efficiency.  It's also more concise than explicit use of genericity
such as with C++ templates.

> As far as variables go, I am hesitant about describing them as being
> necessarily "updatable" if by that we mean a destructive update
[quoted text clipped - 12 lines]
> argument,
> but this is not always the case.)

Are you referring to FP where a variable can only bind to a value
once?

Even in C++, I always get an uneasy feeling with functions that update
the variables associated with formal arguments that have been passed
in by value.

I agree that variables shouldn't be defined as necessarily
updateable.  In C++ one can use 'const' to declare variables that
cannot be updated

   void f(const int x)
   {
       return x+1;
   }

I think the defining feature of a variable has to do with it having
state and an address (or an identity, if you like).

> Date's definitions (and his writings in general) assume a "single
> level" model. Pointers and objects both introduce a multilevel
[quoted text clipped - 5 lines]
> So both of these constructs rather muddle the definitions of
> value and variable.

You just muddled me up as well :)   This reminds me of Java where
objects are passed around by reference by value!

   Point p = new Point(0,0);    // In Java pointers are implicit

In my previous post I tried to avoid the term "object".  Is the above
standard terminology?   I'm not entirely sure what it means to say
that an object is both variable and value (= identity) at the same
time.

I (now) tend to think of a variable as having identity and therefore
there is no point introducing a new term "object" for what is
essentially the same thing.

What do you think of the following definitions?

   value :       as per Date
   val-type :   set of values + operations on those values   (as Date
calls "type")
   variable :   has state and address [but not necessarily a value]
   var-type :   type for a variable

Operations on values must not be confused with operations on
variables.

val-type inheritance is distinct from var-type inheritance.

For every val-type there is a corresponding var-type for a variable
that can hold values of that val-type.   However the reverse is not
true - there are var-types that don't correspond to any val-type.

> This raises the question of whether the multilevel model is
> a good idea or not. Various authors have pointed out a
> number of negative consequences of this idea. My personal
> experience bears out these arguments: local state in objects,
> (which is necessarily unmanaged, the very antithesis of data
> management) is a big source of bugs.

I agree that val-types are generally to be favoured.  I think this
also relates back to pure functional programming and the simplicity
one achieves with functions that don't have side effects.

> However, from a programming language design standpoint,
> objects or something like them are devilishly hard to keep out.
[quoted text clipped - 6 lines]
> first-class functions and doesn't address concurrency,
> but that's too harsh a solution for me.)

I guess a Mutex class is a practical example.

I can't say I understand exactly where (for example) pure functional
programming reaches limitations.   Over the years I have tended to use
the latter style more and more in my OO programs,  as if stateful
objects should be treated as the "last resort".   Unfortunately I
haven't spent enough time thinking and doing FP to know what I might
be missing!

> The real problem of objects from a data management
> view is that unlike simple values, objects can change.
> Imagine a relation with object values in it, and updating
> those objects without invoking updates on the relation.
> One imagines constraint checking would be bypassed.
> Yuck.

I think by definition,  domains, tuples and relations are all value-
types.  It seems to be one of the reasons why RM is so simple yet
powerful.    I guess it relates back to the general rule that
surrogate ids should be avoided - never create identity that shouldn't
be there in the first place.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.