Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Field (computer science)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Variable in a record}} In [[data hierarchy]], a '''field''' ('''data field''') is a [[Variable (computer science)|variable]] in a [[record (computer science)|record]].<ref name="pascal_p42_quoted">{{cite book | last1 = Jensen | first1 = Kathleen | last2 = Wirth | first2 = Niklaus | title = PASCAL User Manual and Report | publisher = Springer-Verlag | year = 1974 | page = 42 | quote = [A] record is a structure consisting of a fixed number of components, called fields. | isbn = 0-387-90144-2 }}</ref> A record, also known as a [[data structure]], allows logically related data to be identified by a single name. Identifying related data as a single group is central to the construction of understandable [[computer program]]s.<ref name="cpl_p169_quote1">{{cite book | last1 = Wilson | first1 = Leslie B. | last2 = Clark | first2 = Robert G. | title = Comparative Programming Languages, Third Edition | publisher = Addison-Wesley | year = 2001 | page = 169 | quote = Being able to structure data in this way is central to the construction of understandable programs. | isbn = 0-201-71012-9 }}</ref> The individual fields in a record may be accessed by name, just like any variable in a computer program.<ref name="cpl_p169">{{cite book | last1 = Wilson | first1 = Leslie B. | last2 = Clark | first2 = Robert G. | title = Comparative Programming Languages, Third Edition | publisher = Addison-Wesley | year = 2001 | page = 169 | isbn = 0-201-71012-9 }}</ref> Each field in a record has two components. One component is the field's [[data type|datatype]] [[Declaration (computer programming)|declaration]]. The other component is the field's [[identifier]].<ref name="pascal_p42">{{cite book | last1 = Jensen | first1 = Kathleen | last2 = Wirth | first2 = Niklaus | title = PASCAL User Manual and Report | publisher = Springer-Verlag | year = 1974 | page = 42 | isbn = 0-387-90144-2 }}</ref> == Memory fields == Fields may be stored in [[random access memory]] (RAM). The following [[Pascal (programming language)|Pascal]] record definition has three field identifiers: firstName, lastName, and age. The two name fields have a datatype of an [[Array (data structure)|array]] of [[Character (computing)|character]]. The age field has a datatype of [[integer]]. <syntaxhighlight lang="pascal"> type PersonRecord = record lastName : array [ 1 .. 20 ] of Char; firstName : array [ 1 .. 20 ] of Char; age : Integer end; </syntaxhighlight> In Pascal, the identifier component precedes a colon, and the datatype component follows the colon. Once a record is defined, [[Instance variable|variables]] of the record can be [[Instance (computer science)|allocated]]. Once the memory of the record is allocated, a field can be accessed like a variable by using the dot notation. <syntaxhighlight lang="pascal"> var alice : PersonRecord; alice.firstName := 'Alice'; </syntaxhighlight> The term ''field'' has been replaced with the terms ''data member''<ref name="stroustrup-p450">{{cite book | last = Stroustrup | first = Bjarne | title = The C++ Programming Language, Fourth Edition | publisher = Addison-Wesley | year = 2013 | page = 450 | isbn = 978-0-321-56384-2 }}</ref> and ''attribute''.<ref name="cpl_p104">{{cite book | last1 = Wilson | first1 = Leslie B. | last2 = Clark | first2 = Robert G. | title = Comparative Programming Languages, Third Edition | publisher = Addison-Wesley | year = 2001 | page = 104 | isbn = 0-201-71012-9 }}</ref> The following [[java (programming language)|Java]] [[Class (computer programming)|class]] has three attributes: firstName, lastName, and age. <syntaxhighlight lang="java"> public class PersonRecord { private String firstName; private String lastName; private int age; } </syntaxhighlight> == File fields == [[File:Data Hierarchy diagram showing Employee database example by JeffTan.gif|thumb|File Data Hierarchy diagram]] Fields may be stored in a [[random access]] [[computer file|file]].<ref name="cpl_p169_quote2">{{cite book | last1 = Wilson | first1 = Leslie B. | last2 = Clark | first2 = Robert G. | title = Comparative Programming Languages, Third Edition | publisher = Addison-Wesley | year = 2001 | page = 169 | quote = The original use of records was in languages like COBOL, where they were used to define the structure of records held in a file. | isbn = 0-201-71012-9 }}</ref> A file may be written to or read from in an arbitrary order. To accomplish the arbitrary access, the [[operating system]] provides a method to quickly ''seek'' around the file.<ref name="upe_p207_quote">{{cite book | last1 = Kernighan | first1 = Brian W. | last2 = Pike | first2 = Rob | title = The UNIX Programming Environment | publisher = Prentice Hall | year = 1984 | page = 207 | quote = The system call lseek provides a way to move around in a file without actually reading or writing. | isbn = 0-13-937699-2 }}</ref> Once the [[Disk read-and-write head|disk head]] is positioned at the beginning of a record, each file field can be read into its corresponding memory field. File fields are the main storage structure in the [[ISAM|Indexed Sequential Access Method]] (ISAM). In [[relational database]] [[Database theory|theory]], the term ''field'' has been replaced with the terms ''column'' and ''attribute''.<ref name="did_p5_quote">{{cite book | last = Date | first = C.J. | title = Database in Depth | publisher = O'Reilly Media, Inc. | year = 2005 | page = 5 | quote = An n-ary relation can be pictured as a table with n columns; the columns in the picture correspond to attributes of the relation and the rows correspond to tuples. | isbn = 0-596-10012-4 }}</ref> ==See also== * {{Annotated link|Class variable}} * {{Annotated link|Mutator method}} ==References== {{Reflist|2}} {{DEFAULTSORT:Field (Computer Science)}} <!--Categories--> [[Category:Data modeling]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Cite book
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)