data-types Flashcards

detecting the sort of data are you looking at in someone's program, so you'll know what all those "sigils" mean...

1
Q

what’s a sigil?

A

a sign or symbol

e.g. in Ruby the @ symbol, as in @my_var means that ‘my_var’ is the name of an instance-variable (vs. a global variable $my_global_var or a local variable my_local_var)

sigils make code look cryptic, until you know what they mean, then you appreciate them because they make it easier to type something that might otherwise be cumbersome.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what sort of data does the computer expect when it sees “…” (a double-quote(s))?

A

typically wrap strings of characters, e.g. “this is a string of characters”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what sort of data does the computer expect when it sees ‘…’ (a single-quote(s))?

A

in the (kinda-old) “c” programming language single-characters* (see the ascii chart) get wrapped in single-quotes.

However, in most modern** languages (javascript, ruby, python, bash-shell, etc) single- & double-quotes are both used to wrap strings of characters:

‘this is a string’

*Note: a - z aren’t the only single-characters, there’s also stuff like “\n” which although it looks like two characters is treated like a single-character (the return character).

**Note: that said, most modern languages interpret single-quoted strings exactly. Whereas double-quoted strings allow for interpolation of variables…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is it called when you make the computer put the value of your variable into the middle of a string?

A

string-interpolation (i.e. of the variable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what sort of data does the computer expect when it sees a: { (an opening-brace)
and
} (a closing-brace)

A

in between the matching braces you are likely looking at what is sometimes called: a dictionary (in python), an associative-array (in perl), a hash (in ruby), or (in javascript) an object.

This data-structure associates a key with a value:
{
"this key": "this value",
"that key": "that value"
}

notice the “:” (colon) is the separator between the key and the value.
also, notice the “,” (comma) that separates one key-value pair from another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you read a value from a hash?

A
given:
x = {
"key1": "value1",
"key2": "value2"
}

you read the value “value2” by supplying the key “key2”
e.g.
x[“key2”] is equal to “value2”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what sort of data does the computer expect when it sees a: [ (an opening-bracket)
and
] (a closing-bracket)

A

in between the matching square-brackets you are likely looking at what is sometimes called an array.

This data-structure is an ordered list of the elements that you add to it. Like a hash it has a key, but the key is just the ordinal-position of each value:
[
“value 1”, “value 2”, “value 3”
]

notice the “,” (comma) that separates each value, one from the next…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do you read a value from an array?

A

given:
x = [“value 1”, “value 2”, “value 3”]

you read the value “value 2” by suppling it’s position:
x[1] is equal to “value 2”
(why not x[2]?)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is meant by a zero-based array?

A

in most programming languages the values in arrays are stored, starting with position “0” then “1”, then “2” and so on…

e.g.
a = [1,2,3] 
a[0] = 1
a[1] = 2
a[2] = 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how do you access the second to last value in an array?

A

a[-2]

e.g. given:
a = [1,2,3,4]
a[-2] == 3

*the double-equals means “is equivalent to”
whereas the single-equals means “is assigned to”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What kind of things can you store in a variable?

A

numbers, characters, strings, arrays, and objects (aka: hashes or associative-arrays of key-value pairs)

e.g.
var foo = “this variable stores a string”;
var bar = 42;
var baz = {
“this string is the key used to lookup the answer”: bar,
“key2”: 9
};

in some languages, variables are “typed” meaning you have to specify the “type” of number, or that you want to store a string…

e.g. (golang):
var x uint16;
var y uint64;
var isHungry bool;
var myDecimal float32;
as well as
 string
(whereas in `c` a `string` is essentially an array of char[] )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly