Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,360 --> 00:00:00,990
All right.
2
00:00:00,990 --> 00:00:03,060
Let us just jump right into it.
3
00:00:03,060 --> 00:00:05,340
So here we've got two functions.
4
00:00:05,370 --> 00:00:07,950
This one returns a double when called.
5
00:00:07,980 --> 00:00:10,260
This one returns a string, one called.
6
00:00:10,260 --> 00:00:13,890
But for the sake of variety, let us add another function.
7
00:00:14,310 --> 00:00:18,330
But this one, unlike these two, is not going to return a value.
8
00:00:18,360 --> 00:00:20,640
You guessed it, it's going to be void.
9
00:00:20,640 --> 00:00:24,360
And this void function is going to be called print area.
10
00:00:24,360 --> 00:00:29,490
And this function is not only going to print the area, but the length and width that we're used to
11
00:00:29,490 --> 00:00:30,690
produce that area.
12
00:00:30,690 --> 00:00:40,620
So it's going to need to define three parameters double length, double width and double area.
13
00:00:42,010 --> 00:00:47,860
And you might be wondering why is this function void and why are these returning values?
14
00:00:48,010 --> 00:00:50,170
I will get to that in just a second.
15
00:00:50,170 --> 00:00:52,000
But bear with me here.
16
00:00:52,000 --> 00:00:53,200
We're just going to print.
17
00:00:55,020 --> 00:01:01,080
Um, a rectangle with a length of.
18
00:01:02,140 --> 00:01:03,040
Length.
19
00:01:05,660 --> 00:01:09,680
And a width of width.
20
00:01:13,710 --> 00:01:16,290
As an area of.
21
00:01:17,000 --> 00:01:19,760
Whatever area that gets passed in.
22
00:01:20,490 --> 00:01:21,150
Okay.
23
00:01:22,670 --> 00:01:26,300
So why is this void and why is this returning a value?
24
00:01:26,300 --> 00:01:28,010
And why is this returning a value?
25
00:01:28,400 --> 00:01:34,010
Well, as I mentioned before, a function should only be performing a single task.
26
00:01:34,160 --> 00:01:37,890
This one performs the task of calculating an area.
27
00:01:37,910 --> 00:01:41,070
The function is already performing a computation.
28
00:01:41,090 --> 00:01:45,830
It should not be the one to also handle the final result of that computation.
29
00:01:45,980 --> 00:01:51,920
It should return the final result and let whoever is calling the function to deal with that result as
30
00:01:51,920 --> 00:01:53,090
they see fit.
31
00:01:53,720 --> 00:01:56,960
The explained area function is performing one task.
32
00:01:56,990 --> 00:02:02,930
It takes in a language and based on the provided language, it compares it against three possible cases
33
00:02:02,930 --> 00:02:06,260
and it explains the area in their preferred language.
34
00:02:06,500 --> 00:02:08,560
This is a form of computation.
35
00:02:08,570 --> 00:02:14,210
The function is already doing so much work, so it should not be the one to handle the final result.
36
00:02:14,240 --> 00:02:17,600
It should simply return the result of that computation.
37
00:02:17,600 --> 00:02:22,400
Whenever a function is performing a calculation or a computation of some sort.
38
00:02:22,490 --> 00:02:24,560
It should not handle the final result.
39
00:02:24,590 --> 00:02:31,010
It should just return the result and let whoever is calling the function to deal with that result as
40
00:02:31,010 --> 00:02:32,270
they see fit.
41
00:02:34,070 --> 00:02:38,530
But the function print area, its only task is to print the area.
42
00:02:38,540 --> 00:02:43,100
It's not performing any calculations, it's not performing any computations.
43
00:02:43,100 --> 00:02:45,880
So we cannot expect it to return any values.
44
00:02:45,890 --> 00:02:48,200
That's why it remains void.
45
00:02:48,230 --> 00:02:52,520
Void means the function does not return a value when called.
46
00:02:52,520 --> 00:02:56,810
It's simply going to print a message depending on what gets passed in.
47
00:02:56,810 --> 00:03:00,050
So what we're going to do is we're going to keep this simple.
48
00:03:00,080 --> 00:03:03,170
We're only going to call explain area once.
49
00:03:03,170 --> 00:03:06,200
We're only going to call calculate area once.
50
00:03:08,130 --> 00:03:14,100
When we calculate an area for the following length and width, we're going to print that area using
51
00:03:14,100 --> 00:03:15,570
the print area function.
52
00:03:15,570 --> 00:03:18,210
The first value that we pass in is the length.
53
00:03:18,990 --> 00:03:24,930
The second value that we pass in is the width, and the third value that we pass in is the area that
54
00:03:24,930 --> 00:03:27,540
was produced from the length and the width.
55
00:03:28,170 --> 00:03:32,040
And here we're just going to print the English explanation normally.
56
00:03:33,170 --> 00:03:33,890
All right.
57
00:03:33,890 --> 00:03:36,080
Putting breakpoints here, here and here.
58
00:03:36,080 --> 00:03:37,790
Re visualizing the runtime.
59
00:03:38,860 --> 00:03:46,390
So when you calculate an area for a length of 2.3 and a width of 3.6, you get a value of 8.28.
60
00:03:46,390 --> 00:03:54,160
And inside of the print area function, we're simply printing that a rectangle with a length of 2.3
61
00:03:54,160 --> 00:04:00,160
and a width of 3.6 has an area of 8.28.
62
00:04:00,280 --> 00:04:03,610
If I just simply continue to the next breakpoint.
63
00:04:04,590 --> 00:04:06,440
We're going to see that in our terminal.
64
00:04:07,580 --> 00:04:13,820
String English explanation is going to equal whatever the explain area function computes based on the
65
00:04:13,820 --> 00:04:15,230
language that was passed in.
66
00:04:15,230 --> 00:04:18,700
So the language that was passed in is English.
67
00:04:18,709 --> 00:04:22,670
We expect the explained area function to return the following text.
68
00:04:24,960 --> 00:04:26,520
That's exactly what it does.
69
00:04:26,550 --> 00:04:32,510
The English explanation variable stores, whatever the explain area function returns when we pass any
70
00:04:32,520 --> 00:04:33,610
value of English.
71
00:04:33,630 --> 00:04:36,120
And here we're just printing it.
72
00:04:38,350 --> 00:04:38,920
All right.
73
00:04:38,920 --> 00:04:45,160
The point I wanted to drive home was that when your function isn't performing any sort of computation
74
00:04:45,160 --> 00:04:51,040
or calculation, if it doesn't need to return anything of significance, then it needs to be void.
75
00:04:51,070 --> 00:04:55,330
Void means the function doesn't return anything when it performs its task.
76
00:04:55,330 --> 00:04:59,320
So when you're just printing something, there is really nothing to return.
77
00:04:59,320 --> 00:05:04,810
But when your function is performing some sort of calculation, some sort of computation that is needed
78
00:05:04,810 --> 00:05:10,180
to produce a final value, then you need to return that value from the function and then let whoever
79
00:05:10,180 --> 00:05:14,530
is calling the function to handle that value as they see fit.
7307
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.