Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Assignment

created by Webster 1913

(idea) by flyingroc (1.3 y) (print)   ?   (I like it!) Wed Oct 09 2002 at 20:06:54

Assignment is an operator that is ubiquitous in imperative programming languages such as C or Java.

Assignment is a data movement operator. That is, it moves data (value) from one variable to another. For example, let us say that we have two variables A and B, with values 1 and 2 repectively. That is:

    ---------+-------
    Variable | Value
    ---------+-------
         A   |   1
    ---------+-------
         B   |   2
    ---------+-------

the assigment statement "A := B" (*) will have the following effect:

    ---------+-------
    Variable | Value
    ---------+-------
         A   |   2
    ---------+-------
         B   |   2
    ---------+-------

As you can see, A now has the value that B previously had, and B retains its old value. That is, A receives a copy of the value of B.

Assignment is ubiquitous partially because of its direct mapping into how to make machines transfer data from one memory cell into another. However this copying semantics shows some problems when the data stored in a variable is more than just a simple data type.

For example, if A and B were large matrices instead of simple integers, the assigment statement would have to copy the whole matrix, element by element. This clearly is inefficient. The solution to this problem is usually to use assigment to copy pointers or references instead. Now, instead of copying the whole matrix, we need to copy only a pointer to the memory location where the matrix resides.

The gain in efficiency, however, causes another problem: aliasing. Using reference smeantics, the statement A := B will make A and B refer to the same data. Thus when the data A refers to is changed, B will also change. This can cause unexpected problems.

Say for example, A and B are linked lists, and we call a procedure append(A,B) which will append the list B to the end of list A. What happens when A and B refer to the same list?

There are many ways in which these problems are addressed. One way is to simply be careful with efficiency when copying values, and careful with reasoning when copying references.

Another option is to eliminate assignments totally! Some logic and functional languages do this, like Haskell. Others, like Lisp have assignment but its use is generally discouraged.

A novel way of dealing with the problem is to replace assignment with swapping, such that in our original example, the effect of a swapping operation will be:

    ---------+-------
    Variable | Value
    ---------+-------
         A   |   2
    ---------+-------
         B   |   1
    ---------+-------

Since swapping exchanges the values of A and B, it can be efficient for large data structures (internally implemented as swapping references, instead of copying every value). And since swapping does not have the effect of making two variables refer to the same value, it cannot have the problem of aliasing.


(*) C and Java use the symbol "=" as the assignment operator, but I've chosen to use ":=" as the former may be mistaken as the equality operator.
Reference and Further Reading:
Bruce W. Weide, Scott M. Pike, and Wayne D. Heym, Why Swapping?, Proceedings of the RESOLVE 2002 Workshop, online version available at: http://people.cs.vt.edu/~edwards/RESOLVE2002/proceedings/Weide2.html

(definition) by Webster 1913 (print) Tue Dec 21 1999 at 21:55:56

As*sign"ment (#), n. [LL. assignamentum: cf. OF. assenement.]

1.

An allotting or an appointment to a particular person or use; or for a particular time, as of a cause or causes in court.

2. Law (a)

A transfer of title or interest by writing, as of lease, bond, note, or bill of exchange; a transfer of the whole of some particular estate or interest in lands.

(b)

The writing by which an interest is transferred.

(c)

The transfer of the property of a bankrupt to certain persons called assignees, in whom it is vested for the benefit of creditors.

Assignment of dower, the setting out by metes and bounds of the widow's thirds or portion in the deceased husband's estate, and allotting it to her.

Assignment is also used in law as convertible with specification; assignment of error in proceedings for review being specification of error; and assignment of perjury or fraud in indictment being specifications of perjury or fraud.

 

© Webster 1913.


printable version
chaos

:= Demanding Bitch haiku Teacher Evaluation How to stay up all night if you've been up all day
ten commandments for c++ programmers == George Stephenson Play the cancer card
I rewrote the world Ice Theory of The Origin of Life operator Using Everything for homework research
spendthrift trust Platypus The Salt Mill, a Swedish Legend History Repeats Itself
3SAT Functional programming Dower parameter passing mechanism
let* examination Donal MacIntyre Assembler
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Little presents from the Node Fairy:
Globe Theatre
The art of stuffing people into boxes
Sea dragon
The Human Anatomy
A really good sandwich that ideath could make to take to work with her
When being chased by CIA trainees, don't mention Belgium to the waffle house physicist
USA PATRIOT Act
My brother made $700 in 3 hours by sitting in front of a grocery store
Massachusetts Institute of Technology
Angkor Wat
We're all missing the point on computer security
The Warlock of Firetop Mountain
Basque
New Writeups
antigravpussy
One fly amonst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
Twin Eclipse
Conversations with God: An Uncommon Dialogue(idea)
SwimmingMonkey
Conversations with Fo Fo- the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
Everything 2 is brought to you by the letter C and The Everything Development Company