1 00:00:00,360 --> 00:00:03,120 Hello. Today, we will learn about variables 2 00:00:03,280 --> 00:00:05,640 and the types available in Pharo. 3 00:00:05,800 --> 00:00:07,840 In fact, there are two big types: 4 00:00:08,000 --> 00:00:13,280 local variables always start with lowercase by convention; 5 00:00:13,440 --> 00:00:15,920 we will see the local types available. 6 00:00:16,080 --> 00:00:18,800 The second big group is shared variables. 7 00:00:18,960 --> 00:00:22,560 They start with uppercase by convention. 8 00:00:22,720 --> 00:00:24,640 There are also several types. 9 00:00:25,600 --> 00:00:29,120 Let's start with local variables which start with lowercase. 10 00:00:29,280 --> 00:00:31,360 Local variables have one method. 11 00:00:31,520 --> 00:00:36,000 They are declared between pipes, 12 00:00:36,160 --> 00:00:37,400 the vertical bars. 13 00:00:37,560 --> 00:00:39,920 Here, there's a local variable, c: 14 00:00:40,080 --> 00:00:43,760 it's local to the method and exists only for its execution. 15 00:00:43,920 --> 00:00:46,960 Therefore, it must always start with lowercase. 16 00:00:47,120 --> 00:00:51,840 By the way, all the class names start with uppercase 17 00:00:52,000 --> 00:00:55,120 because they are shared in the system. 18 00:00:56,800 --> 00:00:59,640 Other types of local variables: 19 00:00:59,800 --> 00:01:03,560 for example, there are instance variables in the object 20 00:01:03,720 --> 00:01:07,120 which are local to it. There are two of them here: x and y. 21 00:01:07,280 --> 00:01:09,640 They always start with lowercase. 22 00:01:09,800 --> 00:01:11,880 As for local variables, 23 00:01:12,040 --> 00:01:15,560 there are also the methods' arguments, here. 24 00:01:16,280 --> 00:01:19,760 In aPoint, "a" is lowercase. 25 00:01:19,920 --> 00:01:22,840 because this variable is also local to the method. 26 00:01:23,000 --> 00:01:26,880 There are also block parameters. 27 00:01:27,040 --> 00:01:31,880 For :x, x is a local variable to a block. 28 00:01:32,040 --> 00:01:34,320 A block argument, sorry. 29 00:01:34,480 --> 00:01:37,280 So here, it starts with lowercase. 30 00:01:39,160 --> 00:01:43,440 In Pharo, there are six specific variables, 31 00:01:43,600 --> 00:01:46,840 called special variables; you can't change their names. 32 00:01:47,000 --> 00:01:48,720 They are reserved words in Pharo. 33 00:01:48,880 --> 00:01:52,640 There are more than 50 of them in Java or JavaScript; 34 00:01:52,800 --> 00:01:54,160 in Pharo, only six. 35 00:01:54,320 --> 00:01:57,720 These are true, false, nil, self, super, and thisContext. 36 00:01:57,880 --> 00:02:01,640 Let's figure out what these reserved words are for. 37 00:02:01,800 --> 00:02:04,360 true and false are instances of Booleans: 38 00:02:04,520 --> 00:02:07,240 true is the unique instance of the class True; 39 00:02:07,400 --> 00:02:10,160 false, the unique instance of the class False. 40 00:02:10,320 --> 00:02:13,760 nil is the unique instance of the class UndefinedObject. 41 00:02:13,920 --> 00:02:16,960 So true, false, and nil are objects like any other, 42 00:02:17,120 --> 00:02:21,200 except they are the unique instances of a specific class in the system. 43 00:02:21,800 --> 00:02:24,160 Next, there are three pseudo-variables: 44 00:02:24,320 --> 00:02:28,720 self refers to the current receiver, and it's equivalent to this in Java. 45 00:02:28,880 --> 00:02:31,520 super always refers to the current receiver, 46 00:02:31,680 --> 00:02:34,880 but this time, when you send a message via super, 47 00:02:35,040 --> 00:02:38,720 it means the method lookup, the selection method algorithm, 48 00:02:38,880 --> 00:02:40,960 which we will see in another class, 49 00:02:41,120 --> 00:02:45,840 will start in the superclass where the keyword super is written. 50 00:02:46,800 --> 00:02:51,000 thisContext is a pseudo-variable which refers to the object 51 00:02:51,160 --> 00:02:53,400 that reifies the program's call stack. 52 00:02:53,560 --> 00:02:57,280 It's an advanced concept we'll study at the end of this MOOC. 53 00:02:57,440 --> 00:03:00,080 We will explain it to you later. 54 00:03:00,240 --> 00:03:03,360 For now, you just need to know it's a pseudo-variable. 55 00:03:04,760 --> 00:03:08,120 Now, shared or global variables. 56 00:03:08,280 --> 00:03:10,680 First, you have all the classes. 57 00:03:10,840 --> 00:03:14,120 All class names start with uppercase 58 00:03:14,280 --> 00:03:17,680 because I can reference a class from anywhere in the system. 59 00:03:18,480 --> 00:03:22,160 Be careful: what starts with uppercase is not always a class. 60 00:03:22,320 --> 00:03:24,600 For example, Transcript: 61 00:03:24,760 --> 00:03:29,640 it's an object name shared in the system. 62 00:03:29,800 --> 00:03:32,840 Everyone can reference this object. 63 00:03:33,000 --> 00:03:36,640 And it's standard output, stdout in other languages. 64 00:03:36,800 --> 00:03:40,120 It's an instance object of a class, globally accessible. 65 00:03:40,280 --> 00:03:42,880 So its name starts with uppercase. 66 00:03:45,440 --> 00:03:48,280 There are also class variables, 67 00:03:48,440 --> 00:03:52,840 which are declared here when declaring a class in classVariableNames; 68 00:03:53,000 --> 00:03:56,520 here, the class #CombinedChar defines two class variables, 69 00:03:56,680 --> 00:03:59,920 one called Compositions and the other Decompositions. 70 00:04:00,080 --> 00:04:02,200 These two class variables 71 00:04:02,360 --> 00:04:06,040 are accessible by the instances of the class #CombinedChar 72 00:04:06,200 --> 00:04:09,000 and of its subclasses. 73 00:04:09,160 --> 00:04:11,880 That's why they're called shared variables. 74 00:04:12,040 --> 00:04:15,480 All the instances of the class and its subclasses share them. 75 00:04:15,640 --> 00:04:19,240 So both of them start with uppercase. 76 00:04:19,400 --> 00:04:22,080 To summarize, you must remember: 77 00:04:22,240 --> 00:04:27,520 all local variables, local to an object, a block, or a method, 78 00:04:27,680 --> 00:04:29,760 start with lowercase; 79 00:04:29,920 --> 00:04:33,600 all global variables, such as class names, etc., 80 00:04:33,760 --> 00:04:35,600 start with uppercase.