Difference between revisions of "W1102 Types"
Line 14: | Line 14: | ||
</pre> | </pre> | ||
[[File:Types-Set_of_Values.png|600px|center|link=]] | [[File:Types-Set_of_Values.png|600px|center|link=]] |
Revision as of 16:50, 13 December 2021
Prerequisites[edit]
Data Types[edit]
Data types (or sometimes just types) provide a means to classify data so that the REPL or ECRD environment can properly interpret the data. A data type provides the connection between the binary format in which all data is ultimately represented in a digital computer (whether that be in main memory, a register, on disk, or in transit across a network) and the representation of that data for humans. Further, legal operations on the associated data is determined by its type. Let’s consider a few bytes in memory:
07AE: 0 1 0 0 0 0 0 1 07AF: 0 1 0 1 1 0 0 0
Coming Soon | |
Add section describing all basic types, including sized integers (Int8, etc.) and unsigned integers of various sizes. |
Constants[edit]
A constant is a value which will not be altered as a program executes. A named constant is a constant associated with an identifier which can subsequently be used to refer to the value of the constant. In the below examples, pi, e, and g0 are all named constants:
let pi = 3.14159265358979323846 let e = 2.718281828459 let g0 = 9.80665 (in m/s2)
Named constants assist programmers to add clarity to their code. It is clearer to both the programmer herself and others that later read the code that pi refers specifically to π and not another number that happens to start with 3.14. It also helps to eliminate mistakes due to repeatedly typing or copying and pasting a constant. Further, if a mistake is discovered in a named constant it is necessary only to correct the definition of the named constant in a single location rather than attempt to search for the value throughout all of the source code. Finally, declaring named constants help to protect the programmer by enabling compile-time checks. While named constants are helpful for programmers they are also helpful to both REPL and ECRD environments as well by enabling optimizations that otherwise wouldn’t be available. Constants which are not named but rather expressed directly in the source code are called Literal Constants. For example: 145.6, “apple”, 185, -123, and false are all examples of literal constants.