Data types and data structures that are important in IT:
types of numbers:
Programming languages commonly use integers and floats
Databases and some data formats additionally use decimals
Be cautious of rounding errors: Some numbers cannot be represented as floating point numbers - the will always be rounded
e.g.: 1/3
A computer is also unable to represent numbers like 0.1
or 0.2
exactly
Example: 0.3 - 0.2
will often not evaluate to 0.1
, but 0.09999999999999998
Types like integer or float usually have a specific accuracy
examples:
Saving as a number or as text?
How should we store credit card numbers, ZIP codes, telephone numbers, ...
Credit card numbers, ZIP codes, telephone numbers should be stored as text
reasons:
/
, spaces)Principle: if a number cannot be sensibly used for coputations it should be stored as text
Boolean value = value representing yes/no or true/false
Boolean values can be represented via a separate data type or via the values 1
and 0
Are usually named true
and false
The special value null
commonly represents missing / unknown data
data (file) formats:
JSON = JavaScript Object Notation: File format which is especially relevant in web development.
The expression null
symbolizes the absence of a value
null
Strings are delimited by double quotes
(In JavaScript single quotes would be allowed as well)
An array contains a sequence of other objects
["Anne", "Bob", "Chris"]
[2, 3, 5, 7, 11]
An object contains named entries
{
"firstName": "Thomas",
"lastName": "Edison",
"birthYear": 1847,
"living": false
}
(In JavaScript the names of entries can be stated without quotes, e.g. firstName
)
CSV (comma-separated values) is a text file format which can hold tabular data
ISO,Country,Capital,Languages
AD,Andorra,Andorra la Vella,"ES,FR"
AE,United Arab Emirates,Abu Dhabi,"AE,fa,en,hi,ur"
AF,Afghanistan,Kabul,"AF,tk"
There is no official definitive standard
CSV formats can vary based on:
The format is older than the standards - in practice the format varies widely
"
) appears within a field, it must be escaped by doubling it (""
)Derived from CSV: tab-separated values
Advantages: easier to read, commas don't have to be escaped
Disadvantages: not standardized, not as popular
ISO Country Capital Languages
AD Andorra Andorra la Vella ES,FR
AE United Arab Emirates Abu Dhabi AE,fa,en,hi,ur
AF Afghanistan Kabul AF,tk
Create a simple CSV file in VS Code and view it in tabular view (icon open in preview in the top right corner)
XML = Extensible Markup Language
Language that is similar to HTML
Was a default language for data exchange; is being replaced more and more by JSON
example:
<person>
<name>Adam</name>
<age unit="years">40</age>
</person>