﻿WEBVTT

00:00:00.840 --> 00:00:03.400 align:middle
In this session, I'd like you to focus

00:00:03.560 --> 00:00:06.320 align:middle
on the use of parentheses and brackets.

00:00:06.480 --> 00:00:08.520 align:middle
Don't mix them up.

00:00:09.160 --> 00:00:12.480 align:middle
Parentheses change the priority
of an execution

00:00:12.640 --> 00:00:15.040 align:middle
in expressions or in code,

00:00:15.200 --> 00:00:17.760 align:middle
while brackets define blocks.

00:00:17.920 --> 00:00:22.840 align:middle
When the expressions in a block
are defined, they are not executed.

00:00:23.000 --> 00:00:27.160 align:middle
You control the execution: you must send
the message value to the block

00:00:27.320 --> 00:00:29.960 align:middle
to trigger the execution
of its expressions.

00:00:31.960 --> 00:00:36.760 align:middle
Let's talk again
about when you must use brackets.

00:00:36.920 --> 00:00:38.960 align:middle
You use them around expressions

00:00:39.120 --> 00:00:44.600 align:middle
if you don't know
whether they will be executed:

00:00:45.280 --> 00:00:49.320 align:middle
for instance, do they use if? Do they
belong to the branch of a deviation?

00:00:50.440 --> 00:00:53.440 align:middle
You also use brackets

00:00:53.600 --> 00:00:57.040 align:middle
if you don't know how many times
you must execute

00:00:58.200 --> 00:01:01.760 align:middle
the expressions a block contains.

00:01:02.760 --> 00:01:07.120 align:middle
For instance:
n timesRepeat: [self doSomething]

00:01:07.280 --> 00:01:11.840 align:middle
self doSomething
is encapsulated in a block.

00:01:12.480 --> 00:01:18.080 align:middle
Why? Because you must
execute its expressions several times.

00:01:18.240 --> 00:01:22.840 align:middle
You must put them in a block to send it
the message value several times.

00:01:25.840 --> 00:01:29.680 align:middle
Another example: this time,
I send the message ifTrue:.

00:01:29.840 --> 00:01:32.000 align:middle
Depending on the receiver,

00:01:32.160 --> 00:01:36.240 align:middle
depending on whether this expression
is true or false,

00:01:36.920 --> 00:01:41.120 align:middle
you execute or don't execute
the expression self doSomething.

00:01:41.280 --> 00:01:46.120 align:middle
I can't use parentheses since if needed,
it won't be executed at all.

00:01:47.120 --> 00:01:48.840 align:middle
If you put it in a block,

00:01:49.000 --> 00:01:52.640 align:middle
you can decide
whether you send it the message value.

00:01:55.080 --> 00:01:59.240 align:middle
This is the same thing
but with whileTrue:.

00:01:59.400 --> 00:02:04.120 align:middle
It's the same with the receiver block
and the block passed as a parameter.

00:02:04.280 --> 00:02:10.040 align:middle
Depending on whether the evaluation
returns the Boolean true or false,

00:02:10.200 --> 00:02:14.280 align:middle
you must execute once, several times,
or even not at all

00:02:14.440 --> 00:02:18.000 align:middle
the expression self doSomething:
it must be put in a block.

00:02:19.400 --> 00:02:22.240 align:middle
Let's do a small exercise.

00:02:23.160 --> 00:02:26.400 align:middle
If I give you
the two following expressions,

00:02:26.560 --> 00:02:30.360 align:middle
repeat from 1 to: n self doSomething,

00:02:30.520 --> 00:02:33.040 align:middle
should I use parentheses or brackets?

00:02:33.200 --> 00:02:36.800 align:middle
If I write x ifEmpty: self doSomething,

00:02:36.960 --> 00:02:39.520 align:middle
should I use parentheses or brackets?

00:02:41.720 --> 00:02:43.440 align:middle
I'll give you the answers.

00:02:44.360 --> 00:02:46.920 align:middle
In both cases, you should use brackets.

00:02:47.080 --> 00:02:51.600 align:middle
In the first case,
if you want to repeat self doSomething,

00:02:51.760 --> 00:02:55.360 align:middle
you have to send the message value
to this block several times.

00:02:56.080 --> 00:02:59.000 align:middle
In the second case, x ifEmpty:,

00:02:59.160 --> 00:03:04.360 align:middle
if x isn't empty,
you shouldn't execute self doSomething.

00:03:04.520 --> 00:03:07.560 align:middle
If x is empty, you have to.

00:03:07.720 --> 00:03:10.280 align:middle
To sum up, we saw in this course

00:03:10.440 --> 00:03:13.720 align:middle
that you shouldn't mix up
parentheses and brackets.

00:03:13.880 --> 00:03:19.120 align:middle
Parentheses are about changing the order
of computation in an expression.

00:03:19.280 --> 00:03:23.800 align:middle
Brackets are about freezing

00:03:23.960 --> 00:03:27.040 align:middle
expressions

00:03:27.200 --> 00:03:31.400 align:middle
and to control their execution
or even to execute them several times.