1 00:00:00,910 --> 00:00:06,920 Inevitably, whoever you are writing code for will dictate how you format code. 2 00:00:06,940 --> 00:00:08,710 So sometimes it makes sense. 3 00:00:08,710 --> 00:00:15,820 For example, if you use some form of pre-processing to extract code and definitions to create a documentations 4 00:00:15,820 --> 00:00:16,630 for the code. 5 00:00:16,660 --> 00:00:25,460 In many cases, this style that is imposed on you is the personal preference of someone else or you. 6 00:00:25,480 --> 00:00:33,910 So there are two broad formatting styles in C plus plus and R and all men. 7 00:00:34,510 --> 00:00:44,500 So in general K and R places the opening brace of a code block on the same line of the list. 8 00:00:44,500 --> 00:00:46,990 Last statement, as you can see here. 9 00:00:47,020 --> 00:00:51,970 Same line of line statement and same line of first statement, as you can see here. 10 00:00:52,510 --> 00:00:53,530 But. 11 00:00:56,060 --> 00:00:57,620 Uh, here. 12 00:00:57,620 --> 00:01:06,980 As you can see, this is the typical typically used in Unix operating systems, but there is an Allman 13 00:01:06,980 --> 00:01:07,700 still. 14 00:01:07,730 --> 00:01:15,110 Allman still style is typically used in Windows, Microsoft Systems. 15 00:01:15,110 --> 00:01:23,780 So the Allman style named after the developer Eric Allman, so places the opening brace on a new line. 16 00:01:23,780 --> 00:01:25,790 As you can see here, this is the new line. 17 00:01:26,150 --> 00:01:33,800 So the nested examples look nested example looks as follows here. 18 00:01:33,830 --> 00:01:34,640 This is the. 19 00:01:36,300 --> 00:01:37,710 An Allman style. 20 00:01:38,730 --> 00:01:44,210 Um, and actually we will miss the else statement here. 21 00:01:44,240 --> 00:01:49,180 Else and the test is false. 22 00:01:49,190 --> 00:01:52,670 And here the second test. 23 00:01:53,270 --> 00:01:57,980 Second test is false. 24 00:01:57,980 --> 00:02:01,610 And this is the Allman Allman style. 25 00:02:01,820 --> 00:02:06,530 So remember, remember that your code is unlikely to be presented on a paper. 26 00:02:06,530 --> 00:02:13,280 So the fact that an R is more compact will save no trees. 27 00:02:13,280 --> 00:02:17,450 If you have the choice, you should choose the style that is the most readable. 28 00:02:17,660 --> 00:02:27,860 The decision of so for it's my decision is the is that R is more readable I think. 29 00:02:27,860 --> 00:02:31,550 But if you choose Allman, it's completely okay. 30 00:02:31,610 --> 00:02:34,430 So you can choose however you want. 31 00:02:34,460 --> 00:02:35,390 Just don't mix. 32 00:02:35,870 --> 00:02:43,280 Just don't mix those two code styles because it the code will become the unreadable here. 33 00:02:43,280 --> 00:02:51,290 For example, if you mix the R and Allman, it's not okay, but it's syntax and compiler will compile 34 00:02:51,290 --> 00:02:53,330 it with no problem. 35 00:02:53,570 --> 00:03:03,200 So if you have a multiple nested blocks, the intense can give you an idea of which block the code resides 36 00:03:03,200 --> 00:03:03,440 in. 37 00:03:03,440 --> 00:03:06,710 However, comments can help to here. 38 00:03:06,800 --> 00:03:13,880 So in particular, if a code block has a large amount of code, it's often helpful to comment the reason 39 00:03:13,880 --> 00:03:14,720 for the code block. 40 00:03:14,720 --> 00:03:22,970 So for example, if an if statement is the it is helpful to put the result of the test in the code block 41 00:03:22,970 --> 00:03:26,000 so you know what the variable values are in that. 42 00:03:26,000 --> 00:03:31,400 BLOCK So it's also useful to put a comment on the closing brace of a test here. 43 00:03:32,210 --> 00:03:32,930 So. 44 00:03:34,290 --> 00:03:37,290 Uh, let's, let's write an example program here. 45 00:03:37,500 --> 00:03:38,220 Example. 46 00:03:38,220 --> 00:03:38,850 Just an. 47 00:03:40,400 --> 00:03:41,210 Example. 48 00:03:41,360 --> 00:03:42,740 Example one. 49 00:03:43,220 --> 00:03:43,850 Here. 50 00:03:44,850 --> 00:03:48,500 So let's create an if blocks here. 51 00:03:48,510 --> 00:03:50,370 If X, let's create first. 52 00:03:50,550 --> 00:03:51,750 Let's create an integer. 53 00:03:51,750 --> 00:03:53,940 Integer X equals one. 54 00:03:55,920 --> 00:04:04,080 If X is is greater than zero, you will learn about all of this if and else statements in next lectures. 55 00:04:04,080 --> 00:04:05,400 This is just an example. 56 00:04:05,400 --> 00:04:14,670 So just keep in mind and here then x greater than this. 57 00:04:14,670 --> 00:04:21,450 And here we will add the lots of code codes here. 58 00:04:21,600 --> 00:04:25,380 And then lastly, if. 59 00:04:27,100 --> 00:04:27,790 If. 60 00:04:29,000 --> 00:04:31,340 X less than zero. 61 00:04:31,340 --> 00:04:35,030 And let's add add an else statement to. 62 00:04:36,770 --> 00:04:37,580 Else. 63 00:04:38,720 --> 00:04:39,530 Else here. 64 00:04:40,920 --> 00:04:41,370 Um. 65 00:04:41,730 --> 00:04:44,340 Then as X. 66 00:04:44,970 --> 00:04:47,970 Is greater than or equal to zero if. 67 00:04:48,090 --> 00:04:54,900 So if x not less than zero, then x is greater than or less than zero. 68 00:04:54,900 --> 00:04:56,790 So we just wrote it as comment. 69 00:04:56,790 --> 00:04:58,650 So it just a comment. 70 00:04:58,650 --> 00:05:05,640 So it's for easy to understand in next cplusplus programmers. 71 00:05:05,790 --> 00:05:09,120 So here lots of quotes again. 72 00:05:09,300 --> 00:05:12,090 Again lots of quotes and then. 73 00:05:13,400 --> 00:05:14,360 If. 74 00:05:15,190 --> 00:05:19,090 Here X is less than zero. 75 00:05:19,570 --> 00:05:26,170 Just mentioning that this else is the if statement else. 76 00:05:26,170 --> 00:05:28,990 So there's nothing else here. 77 00:05:28,990 --> 00:05:35,860 If you put the this is a comment on a closing brace, it means that you have a search term that you 78 00:05:35,860 --> 00:05:43,510 can use to find a test that resulted in the code block So the preceding lines make this comment redundant. 79 00:05:43,510 --> 00:05:51,160 But when you have the code blocks with the many tens of lines of code and with many levels of nesting, 80 00:05:51,160 --> 00:05:53,320 commenting like this can be very helpful. 81 00:05:53,320 --> 00:05:58,330 So for example, oh, I'm searching for my x less than zero statement. 82 00:05:58,330 --> 00:05:59,710 Where is the statement? 83 00:05:59,710 --> 00:06:03,610 You just press the control plus f here. 84 00:06:04,270 --> 00:06:04,660 Oops. 85 00:06:04,840 --> 00:06:09,790 So ctrl plus f here and then x less than zero. 86 00:06:09,790 --> 00:06:15,610 As you can see here, our idea of or you can use just a text processing application as well. 87 00:06:15,610 --> 00:06:20,740 If you just use this commenting type, you will get the. 88 00:06:22,070 --> 00:06:25,160 Uh, you desired search result. 89 00:06:25,700 --> 00:06:29,000 In next lecture, we're going to learn about the writing statements. 90 00:06:29,000 --> 00:06:32,000 So I'm waiting you in next lecture.