WEBVTT
Kind: captions
Language: en

1
00:00:00.060 --> 00:00:01.540
In the early days of computing,

2
00:00:01.540 --> 00:00:05.140
programmers needed to be very sure about the
data they were operating on.

3
00:00:05.140 --> 00:00:09.380
If an operation was fed a number when it was
expecting a letter, a character:

4
00:00:09.380 --> 00:00:11.260
at best you might get a garbled response,

5
00:00:11.270 --> 00:00:14.520
and at worst you could break the system.
Maybe even physically.

6
00:00:14.520 --> 00:00:17.740
Now, at the low level of coding,
yeah, that’s still true.

7
00:00:17.740 --> 00:00:20.000
But these days we have
programming languages where

8
00:00:20.000 --> 00:00:23.249
we don’t always need to be
so rigorous in defining the data,

9
00:00:23.249 --> 00:00:25.279
and we can let the computer figure it out.

10
00:00:25.280 --> 00:00:29.620
But for something that seems so technical,
this can be controversial.

11
00:00:32.440 --> 00:00:34.840
When you write a computer program,
you use variables,

12
00:00:34.850 --> 00:00:37.340
which are basically just labelled
buckets of memory.

13
00:00:37.340 --> 00:00:39.881
Inside that bucket is some data,
and you can change it,

14
00:00:39.881 --> 00:00:42.620
you can vary it.
Hence, variable.

15
00:00:42.620 --> 00:00:44.700
I know it’s a massive simplification,

16
00:00:44.710 --> 00:00:47.800
but computer memory is a bit like
an enormous rack of switches

17
00:00:47.800 --> 00:00:52.410
storing ones and zeros that represent other
things like letters and numbers.

18
00:00:52.410 --> 00:00:54.290
But if we look into a region of memory,

19
00:00:54.290 --> 00:01:00.110
there is nothing in there to indicate what
those ones and zeros are actually representing.

20
00:01:00.110 --> 00:01:04.620
So in the code, we declare that the variable
is a particular type.

21
00:01:04.620 --> 00:01:08.070
What's contained in that variable,
in that bucket?  It's an integer.

22
00:01:08.070 --> 00:01:09.940
What's in that one?
It's a string of characters.

23
00:01:09.940 --> 00:01:14.420
That tells the computer how to interpret those
ones and zeros in memory.

24
00:01:14.420 --> 00:01:18.240
The types that you get to use can
differ a bit between languages.

25
00:01:18.240 --> 00:01:21.799
But in general, you’ll at least have:
Integer or INT.

26
00:01:21.799 --> 00:01:24.850
That’s a whole number that can’t have
anything after the decimal point.

27
00:01:24.850 --> 00:01:27.120
And those are extremely useful
for storing things like

28
00:01:27.120 --> 00:01:29.939
the number of times you’ve looped
through some code,

29
00:01:29.939 --> 00:01:32.180
or how many points
your player’s clocked up,

30
00:01:32.180 --> 00:01:35.360
or how many pennies there are
in someone’s account.

31
00:01:35.360 --> 00:01:37.880
Then you've got character or CHAR.

32
00:01:37.880 --> 00:01:40.670
These are letters, numbers,
punctuation, and whitespaces,

33
00:01:40.670 --> 00:01:44.139
like the space between words,
and instructions to start a new line.

34
00:01:44.139 --> 00:01:47.679
And in most high-level languages,
you’ll probably be using a STRING instead,

35
00:01:47.679 --> 00:01:50.329
which is just a string of characters.

36
00:01:50.329 --> 00:01:55.530
Then you've got Boolean, or BOOL, named after
George Boole, an English mathematician.

37
00:01:55.530 --> 00:01:57.960
That's very simple: it's true or false.

38
00:01:57.960 --> 00:02:02.420
A boolean only contains either
a zero or a one. A yes or a no.

39
00:02:02.420 --> 00:02:04.360
A no or a yes.

40
00:02:04.360 --> 00:02:05.479
Nothing more.

41
00:02:05.479 --> 00:02:07.740
Then there’s floating-point numbers, or
FLOATs.

42
00:02:07.740 --> 00:02:10.890
Floats are complicated and messy and a whole
other video, but in short,

43
00:02:10.890 --> 00:02:13.190
they let you store numbers with decimals,

44
00:02:13.190 --> 00:02:16.610
although you might lose a very small bit of
precision as you do it.

45
00:02:16.610 --> 00:02:19.129
There are others, other types,
in a lot of languages,

46
00:02:19.129 --> 00:02:23.660
I know it’s more complicated than this:
but this is just the basics.

47
00:02:23.660 --> 00:02:27.360
So. Most languages use
“explicit type declaration”.

48
00:02:27.370 --> 00:02:30.370
So when you declare a 
when you set up that bucket,

49
00:02:30.370 --> 00:02:32.159
you have to also declare its type.

50
00:02:32.159 --> 00:02:38.069
So, x is an integer, it can only hold integers,
and right now, that integer is 2.

51
00:02:38.069 --> 00:02:39.417
But in some languages,

52
00:02:39.417 --> 00:02:43.400
including some popular ones that people
tend to get started with, and that I like,

53
00:02:43.400 --> 00:02:44.950
you don’t need to actually declare that.

54
00:02:44.950 --> 00:02:48.900
It just gets figured out from your code.
That’s called “implicit declaration”.

55
00:02:48.900 --> 00:02:53.440
So in JavaScript, you can just type
x = 1.5 and it’ll know, that’s a number.

56
00:02:53.440 --> 00:02:57.230
Put the 1.5 in quotes,
and it’ll go, ah, it’s a string.

57
00:02:57.230 --> 00:03:00.620
So, okay, it’s storing 1.5 and “1.5”
as different ones and zeros.

58
00:03:00.620 --> 00:03:02.180
Why does that matter?

59
00:03:02.180 --> 00:03:05.370
Well, in JavaScript, the plus sign means
two different things.

60
00:03:05.370 --> 00:03:07.819
It’s the addition operator,
for adding two numbers together.

61
00:03:07.819 --> 00:03:12.099
But it’s also the concatenation operator,
for combining two strings together.

62
00:03:12.100 --> 00:03:15.760
So if x is “1.5”, you ask for x + x...
it returns 3.

63
00:03:15.760 --> 00:03:19.740
But if either of those xs is "1.5", a string,

64
00:03:19.740 --> 00:03:21.620
it'll return that.

65
00:03:21.620 --> 00:03:25.980
And that's called “type casting”;
converting from one data type to another.

66
00:03:25.980 --> 00:03:31.220
Some languages require the programmer
to explicitly request the conversion in code.

67
00:03:31.220 --> 00:03:34.420
Other languages, like JavaScript there,
do it automatically.

68
00:03:34.420 --> 00:03:37.720
JavaScript is referred to as having “weak
typing” as opposed to “strong typing”.

69
00:03:37.730 --> 00:03:40.579
And it’s weak because, even if that 1.5
is a string,

70
00:03:40.579 --> 00:03:42.579
and you ask for it multiplied by 2…

71
00:03:42.579 --> 00:03:44.709
it’ll return 3.

72
00:03:44.709 --> 00:03:47.799
Unlike the plus sign, that asterisk can only
mean ‘multiply’,

73
00:03:47.799 --> 00:03:51.290
so it can only handle an integer
or a floating-point number.

74
00:03:51.290 --> 00:03:52.290
Give it a string, though,

75
00:03:52.290 --> 00:03:54.340
and it won’t throw an error like a
strongly-typed language would.

76
00:03:54.340 --> 00:03:56.670
It’ll just convert it for you on the fly.

77
00:03:56.670 --> 00:03:59.900
Really convenient.
Really easy to program with.

78
00:03:59.900 --> 00:04:02.200
Really easy to accidentally screw things up

79
00:04:02.200 --> 00:04:04.930
and create a bug that’ll take you hours
to track down.

80
00:04:04.930 --> 00:04:09.999
Or worse, create a bug that you
don’t even notice until much, much later.

81
00:04:09.999 --> 00:04:14.269
In a lot of languages, you can also cast
to and from boolean values.

82
00:04:14.269 --> 00:04:16.260
Which is called "truthiness",

83
00:04:16.260 --> 00:04:20.500
and experienced programmers who are
watching this may already be grimacing.

84
00:04:20.500 --> 00:04:22.350
Truthiness is a great shorthand.

85
00:04:22.350 --> 00:04:25.470
If you convert an empty string to a boolean,

86
00:04:25.470 --> 00:04:27.240
it generally comes out as false.

87
00:04:27.240 --> 00:04:28.480
Anything else, true.

88
00:04:28.480 --> 00:04:32.520
So you can just test for an empty string with
if(x).

89
00:04:32.520 --> 00:04:33.520
But that also means that in JavaScript,

90
00:04:33.520 --> 00:04:37.930
you can ask for true + true and
it’ll tell you that the answer to that is 2,

91
00:04:37.930 --> 00:04:40.729
because when you cast ‘true’ to a number
you get 1.

92
00:04:40.729 --> 00:04:45.070
In PHP, a language notable for many
questionable design decisions,

93
00:04:45.070 --> 00:04:49.260
even a string with just a single zero in it
will get converted to a boolean false,

94
00:04:49.260 --> 00:04:51.880
there’s a special case just for that string.

95
00:04:51.880 --> 00:04:54.620
Which can cause a lot of unexpected bugs.

96
00:04:54.620 --> 00:04:57.520
Now, there is a workaround for that in
loosely-typed languages.

97
00:04:57.520 --> 00:04:59.860
Normally, if you want to
compare two variables,

98
00:04:59.860 --> 00:05:01.750
you use two equals signs, like this.

99
00:05:01.750 --> 00:05:05.139
You can’t use a single one, because that’s
used for assigning variables.

100
00:05:05.139 --> 00:05:10.930
I’ve been coding for about thirty years and I
still absent-mindedly screw that up sometimes.

101
00:05:10.930 --> 00:05:16.080
Now, if you ask if 1.5 is equal to “1.5”
with two equals signs in JavaScript or PHP,

102
00:05:16.080 --> 00:05:17.550
you’ll get “true”.

103
00:05:17.550 --> 00:05:21.000
But if you add a third equals sign,
then you’re asking for strict equality.

104
00:05:21.000 --> 00:05:27.050
If the data types don’t match,
any comparison will automatically fail.

105
00:05:27.050 --> 00:05:28.740
So why is all this controversial?

106
00:05:28.740 --> 00:05:31.380
Well, languages like Javascript and PHP can
get a bad reputation

107
00:05:31.380 --> 00:05:33.880
because they use weak typing.

108
00:05:33.880 --> 00:05:37.330
If you see yourself as a Real Programmer --
and I’m using that sarcastically,

109
00:05:37.330 --> 00:05:43.190
but if you see yourself as the kind of programmer
where you are in control of everything, then…

110
00:05:43.190 --> 00:05:46.880
yeah, you can see that weak typing
is like training wheels,

111
00:05:46.880 --> 00:05:50.039
something that introduces sloppy
coding practices and bugs and shorthand.

112
00:05:50.039 --> 00:05:51.390
And that’s not unfair.

113
00:05:51.390 --> 00:05:55.610
But weak typing also makes programming
easier to learn and easier to do,

114
00:05:55.610 --> 00:05:59.509
it can reduce frustration and
just make programmers’ lives easier.

115
00:05:59.509 --> 00:06:01.360
It is a trade-off:

116
00:06:01.360 --> 00:06:04.590
even if it is a controversial one.

117
00:06:04.590 --> 00:06:07.990
This series of The Basics is sponsored by
Dashlane, the password manager.

118
00:06:07.990 --> 00:06:12.270
It’s kinda obvious that passwords are more
secure the longer they are,

119
00:06:12.270 --> 00:06:15.580
but it can be difficult to get an intuitive
sense of just how much more secure.

120
00:06:15.580 --> 00:06:17.699
So let’s say you’ve signed up to Dashlane,

121
00:06:17.700 --> 00:06:21.700
and now you’re able to use long, complicated,
symbol-filled passwords everywhere

122
00:06:21.700 --> 00:06:25.979
because Dashlane remembers,
synchronises and autofills them for you.

123
00:06:25.979 --> 00:06:28.350
How much more secure are those passwords?

124
00:06:28.350 --> 00:06:29.970
Well, let’s do the maths.

125
00:06:29.970 --> 00:06:32.740
The characters that most web sites tend to
accept for passwords are:

126
00:06:32.740 --> 00:06:36.819
uppercase and lowercase letters, numbers,
and let’s say thirty punctuation marks.

127
00:06:36.819 --> 00:06:38.410
That’s 92 characters.

128
00:06:38.410 --> 00:06:42.949
There’s an argument that you should be allowed
to use any Unicode character in a password,

129
00:06:42.949 --> 00:06:44.480
but it’s definitely an argument,

130
00:06:44.480 --> 00:06:46.930
so let’s limit it to those 92 characters.

131
00:06:46.930 --> 00:06:50.419
First, because we’re using random characters,
we can ignore ‘wordlists’

132
00:06:50.420 --> 00:06:54.940
that make password cracking orders of magnitude
easier by guessing dictionary words first

133
00:06:54.940 --> 00:06:57.720
including, like, using an exclamation mark
instead of a 1,

134
00:06:57.720 --> 00:06:59.919
or deliberately swapping a couple of letters.

135
00:06:59.919 --> 00:07:01.330
Those tricks won’t work here.

136
00:07:01.330 --> 00:07:03.820
Now, let’s say that an attacker
is able to test

137
00:07:03.820 --> 00:07:06.700
a billion possible passwords
every single second.

138
00:07:06.700 --> 00:07:10.159
That’s not unreasonable if the encryption
is weak and their computer is fast.

139
00:07:10.159 --> 00:07:11.759
If you have a six-character password,

140
00:07:11.759 --> 00:07:14.349
it will take them at 
about ten minutes to try

141
00:07:14.349 --> 00:07:18.610
every single possible one of the
606 billion combinations.

142
00:07:18.610 --> 00:07:21.800
But every letter you add
multiples that time by 92.

143
00:07:21.800 --> 00:07:24.259
Seven characters works out to
15 and a half hours.

144
00:07:24.259 --> 00:07:25.819
Eight characters, about two months.

145
00:07:25.819 --> 00:07:28.169
Nine characters, 14 years.

146
00:07:28.169 --> 00:07:30.880
Ten characters, more than a millennium.

147
00:07:30.880 --> 00:07:33.150
Eleven characters is a hundred thousand years.

148
00:07:33.150 --> 00:07:34.650
By the time you’ve got to fifteen characters,

149
00:07:34.650 --> 00:07:38.530
it’s about a thousand times longer than
the universe has existed.

150
00:07:38.530 --> 00:07:42.770
Long, complicated, random passwords aren’t
a cure-all.

151
00:07:42.770 --> 00:07:45.370
But they’re certainly better than the alternative.

152
00:07:45.370 --> 00:07:46.639
And to help you with them:

153
00:07:46.639 --> 00:07:49.889
dashlane.com/tomscott for a 30-day free trial
of Dashlane Premium,

154
00:07:49.889 --> 00:07:52.360
which includes unlimited password storage
and sync,

155
00:07:52.360 --> 00:07:53.620
plus a load of other features.

156
00:07:53.620 --> 00:07:56.820
And if you like it, you can use the code
“tomscott” for 10% off.

