All language subtitles for 28. Clean Code

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,750 --> 00:00:06,560 I want to talk quickly about the idea of clean code something that we've talked about before and this 2 00:00:06,560 --> 00:00:10,930 is a good example to do with something like a function. 3 00:00:10,970 --> 00:00:21,580 For example let's say we had a function that perhaps checks if a number is even or odd so let's say 4 00:00:22,780 --> 00:00:33,310 is odd or even as a function that takes in a number and we're going to hear say well how are we going 5 00:00:33,310 --> 00:00:34,200 to check. 6 00:00:34,210 --> 00:00:45,350 Well we can use the modulo operator I can say if no modulo 2 which remember gives us the remainder. 7 00:00:45,460 --> 00:00:49,780 And if it's an even number the remainder is always going to be zero. 8 00:00:49,780 --> 00:00:52,570 So this is going to tell us if it's an even number. 9 00:00:52,570 --> 00:01:05,350 So if it's an even number then I want you to return true and if it's not an even number. 10 00:01:05,350 --> 00:01:13,000 So let's say now to doesn't equal zero. 11 00:01:13,040 --> 00:01:21,030 So if this is an odd number there is always a remainder in that case we return false. 12 00:01:21,230 --> 00:01:27,140 So maybe let's change this function to be more descriptive is even. 13 00:01:27,410 --> 00:01:33,870 So it's going to return true if it's even false if it's not even so in here. 14 00:01:34,060 --> 00:01:43,300 If I do is even and give it 50 and I run I get a narrow because I have to make sure that I do an L. 15 00:01:43,600 --> 00:01:55,650 If statement here we have to print here so let's do print and click Run I get true if I do 51 and click 16 00:01:55,650 --> 00:01:58,450 Run I get false. 17 00:01:58,470 --> 00:01:58,740 All right. 18 00:01:58,740 --> 00:02:02,220 It seems to be working but how can we clean up this code. 19 00:02:02,880 --> 00:02:04,190 Well here's the thing. 20 00:02:04,200 --> 00:02:10,750 We have some ways that we can actually make this a little bit tighter. 21 00:02:10,800 --> 00:02:22,820 For example if we're only checking for is even we don't really need to check this again because if no 22 00:02:22,830 --> 00:02:24,570 module or two doesn't equal 0. 23 00:02:24,570 --> 00:02:29,460 That is if a number divided by two doesn't always have a remainder of zero. 24 00:02:29,460 --> 00:02:30,900 We always know that that's. 25 00:02:30,990 --> 00:02:31,890 Well it's not gonna be. 26 00:02:31,890 --> 00:02:34,860 Even so we don't even need the statement. 27 00:02:34,860 --> 00:02:39,140 We can just say else right. 28 00:02:39,330 --> 00:02:42,990 So that if I run this this still works. 29 00:02:42,990 --> 00:02:43,280 Sorry. 30 00:02:43,310 --> 00:02:45,750 So we've cleaned up our code a little bit. 31 00:02:46,490 --> 00:02:47,270 But here's the thing. 32 00:02:47,390 --> 00:02:54,980 Another thing we could do is we know that return access the function automatically so we don't even 33 00:02:54,980 --> 00:02:56,940 need the else statement. 34 00:02:57,140 --> 00:03:05,910 I can just say return here because it's only going to get to line 5 if this statement is not correct. 35 00:03:05,930 --> 00:03:11,230 So if it's not even well I'm going to skip line four and go to line five. 36 00:03:11,540 --> 00:03:15,300 So that if I run this this still works. 37 00:03:15,490 --> 00:03:15,850 All right. 38 00:03:15,850 --> 00:03:18,340 But we can make this even cleaner. 39 00:03:18,400 --> 00:03:18,920 Right. 40 00:03:19,000 --> 00:03:21,090 Because right now we're just returning. 41 00:03:21,090 --> 00:03:27,950 True or false and usually if you have something like this we're returning true false directly. 42 00:03:28,110 --> 00:03:34,110 There is usually a better way and that's using an expression that evaluates to a Boolean. 43 00:03:34,560 --> 00:03:44,930 We can actually do is simply say hey remove all of this and I want you to just return like this and 44 00:03:45,230 --> 00:03:55,110 if we run this this still works and if I do 50 this still works because what we're saying here is I 45 00:03:55,110 --> 00:03:58,290 want you to return whatever this value is. 46 00:03:58,290 --> 00:04:03,360 And this is an expression right that's going to evaluate TRUE FALSE directly. 47 00:04:03,360 --> 00:04:07,560 So we get the exact same result as we had before. 48 00:04:07,590 --> 00:04:09,900 But look how much cleaner that is. 49 00:04:09,900 --> 00:04:12,140 That is just nice simple code. 50 00:04:12,150 --> 00:04:15,530 And as a developer I can come in here and right away see that. 51 00:04:15,540 --> 00:04:15,940 All right. 52 00:04:15,990 --> 00:04:20,830 Is even is just performing this operation and returning true or false. 53 00:04:20,880 --> 00:04:23,520 So this is a good way to think about clean code. 54 00:04:23,520 --> 00:04:26,180 How can you clean up your code and mind you. 55 00:04:26,220 --> 00:04:27,630 There's no perfect solution. 56 00:04:27,630 --> 00:04:29,420 You can always clean up code. 57 00:04:29,520 --> 00:04:36,520 But thinking like this really allows you to develop the way that advanced programmers think I'll see 58 00:04:36,520 --> 00:04:37,470 you in the next room. 59 00:04:37,510 --> 00:04:37,740 Bob. 5491

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.