Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,080 --> 00:00:06,120
In the last section, we broke down this line of code right here, remember, the VA name is referred
2
00:00:06,120 --> 00:00:10,580
to as variable declaration because it creates a new variable then the equals.
3
00:00:10,590 --> 00:00:16,110
My name is referred to as variable initialization because it assigns a value to that new variable that
4
00:00:16,110 --> 00:00:16,920
was just created.
5
00:00:17,800 --> 00:00:22,630
At the end of this line, we had a call to the my name function, which was defined down here at the
6
00:00:22,630 --> 00:00:23,460
bottom of the file.
7
00:00:23,920 --> 00:00:27,940
So in this section, we're going to start to take a look at this function declaration down here.
8
00:00:28,800 --> 00:00:33,510
Now, I don't have a terribly large amount to say about functions, mostly because they work almost
9
00:00:33,510 --> 00:00:39,090
identically to how they work and just about every other style language out there, every function we
10
00:00:39,090 --> 00:00:41,140
create can have a name assigned to it.
11
00:00:41,490 --> 00:00:44,790
So in this case, the name of our function is simply my name.
12
00:00:45,830 --> 00:00:51,130
After the name of the function, we then place a set of parentheses which denotes the argument list,
13
00:00:51,500 --> 00:00:55,050
so any time we call a function, we can pass in some number of arguments to it.
14
00:00:55,910 --> 00:00:59,210
We then have a set of curly braces which form the function body.
15
00:00:59,660 --> 00:01:04,400
So inside those curly braces is where we add all the code that's going to be executed any time we call
16
00:01:04,400 --> 00:01:05,030
this function.
17
00:01:06,130 --> 00:01:10,930
And where things start to get a little bit interesting is the word string over here to the left hand
18
00:01:10,930 --> 00:01:11,320
side.
19
00:01:12,360 --> 00:01:18,570
So any time our function returns a value, we can annotate that function with the type of value that
20
00:01:18,570 --> 00:01:22,820
is going to be returned in this case, we are returning a string from the function.
21
00:01:23,040 --> 00:01:28,230
So we wrote out the left hand side of the function name string, because that is the type of value that
22
00:01:28,230 --> 00:01:30,990
we're going to return any time this function gets called.
23
00:01:32,840 --> 00:01:36,800
We're going to have a discussion about type's in just a second, but before we do, I want to mention
24
00:01:36,800 --> 00:01:39,020
one other thing about functions in darte.
25
00:01:40,200 --> 00:01:45,540
Back over here, you'll notice that we had a function called Main, and then we had also defined a second
26
00:01:45,540 --> 00:01:48,150
function called my name in general.
27
00:01:48,150 --> 00:01:50,520
You and I can name functions, anything we wish.
28
00:01:50,730 --> 00:01:57,320
But there's exactly one exception to that rule, and that is the main function in darte.
29
00:01:57,330 --> 00:02:03,120
The main function is a very special function that has to be defined inside of every darte program that
30
00:02:03,120 --> 00:02:04,120
we ever put together.
31
00:02:04,950 --> 00:02:10,310
The main function right here is automatically invoked by darte any time our program is executed.
32
00:02:10,830 --> 00:02:14,280
And so you can kind of think of the flow of operations as being something like this.
33
00:02:14,910 --> 00:02:16,040
So we're up here at the top.
34
00:02:16,350 --> 00:02:21,450
Our program starts up darte, is going to look over all the code inside of our application and try to
35
00:02:21,660 --> 00:02:23,370
find a function called main.
36
00:02:23,970 --> 00:02:26,010
If it finds it, it's then going to run it.
37
00:02:26,220 --> 00:02:31,890
And from that main function, you and I can add some code to do some actual up of our application and
38
00:02:31,890 --> 00:02:34,020
accomplish whatever app is really trying to do.
39
00:02:34,860 --> 00:02:39,660
Now, one thing I want to mention here is that every darte program we put together has to have a main
40
00:02:39,660 --> 00:02:40,150
function.
41
00:02:40,590 --> 00:02:46,260
So, for example, if I take this entire main function back here and delete it and then click run again.
42
00:02:48,070 --> 00:02:52,990
You'll notice that I get an error message over here on the right hand side that says uncaught and essentially
43
00:02:52,990 --> 00:02:57,580
it's an error message that's complaining that there's no main function defined inside of my project.
44
00:02:58,830 --> 00:03:03,990
If I go back to having the main function and run it again, I'll then see the expected output of my
45
00:03:03,990 --> 00:03:04,650
name is Stephen.
46
00:03:05,610 --> 00:03:10,680
So in closing, functions for the most part behave very similar to how they do in just about every other
47
00:03:10,680 --> 00:03:11,440
language out there.
48
00:03:12,060 --> 00:03:15,840
The one requirement of every program is that we have to have one function called main.
49
00:03:16,970 --> 00:03:21,800
The only thing that's kind of unexpected about these functions is that they have to annotate their return
50
00:03:21,800 --> 00:03:25,640
type with a type being listed just to the left of the function name.
51
00:03:26,480 --> 00:03:27,730
Now, let's take a pause right here.
52
00:03:27,770 --> 00:03:31,880
We're going to come back to the next section and we're going to start talking a lot more about how types
53
00:03:31,880 --> 00:03:32,760
work in DART.
54
00:03:33,080 --> 00:03:35,140
So a quick break and I'll see you in just a minute.
5661
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.