1 00:00:00,980 --> 00:00:07,000 Inevitably, whoever you are writing code for will dictate how you form a code. 2 00:00:07,010 --> 00:00:08,780 So sometimes it makes sense. 3 00:00:08,780 --> 00:00:15,890 For example, if you use some form of preprocessing to extract code and definitions to create a documentation 4 00:00:15,890 --> 00:00:16,760 for the code. 5 00:00:16,790 --> 00:00:24,860 In many cases, this style that is imposed on you is the personal preference of someone else of you 6 00:00:24,860 --> 00:00:25,550 or you. 7 00:00:25,580 --> 00:00:33,950 So there are two broad formatting styles in C++, R and all men. 8 00:00:34,640 --> 00:00:44,570 So in general can are places the opening phrase of a code block on the same line of the list. 9 00:00:44,570 --> 00:00:45,620 Last statement. 10 00:00:45,620 --> 00:00:51,920 As you can see here, same line of statement and same line of statement as you can see here. 11 00:00:52,730 --> 00:00:53,540 But. 12 00:00:57,240 --> 00:00:57,690 Here. 13 00:00:57,690 --> 00:01:06,810 As you can see, this is the typical typically used in UNIX operating systems, but there is an all 14 00:01:06,810 --> 00:01:15,180 months stale, all meant stale style is typically used in Windows Microsoft systems. 15 00:01:15,180 --> 00:01:18,990 So they are all style named after the developer. 16 00:01:18,990 --> 00:01:20,490 Eric Amen. 17 00:01:20,490 --> 00:01:23,850 So places the opening brace on a new line. 18 00:01:23,850 --> 00:01:25,770 As you can see, it is the new one. 19 00:01:26,310 --> 00:01:33,390 So the nested examples look nested example looks as follows. 20 00:01:33,390 --> 00:01:33,870 Here. 21 00:01:33,900 --> 00:01:34,650 This is the. 22 00:01:36,550 --> 00:01:37,780 Allman Style. 23 00:01:39,690 --> 00:01:44,250 And actually, we will miss the LS statement here. 24 00:01:44,280 --> 00:01:49,200 LS And the test is false. 25 00:01:49,380 --> 00:01:52,710 And here's the second test. 26 00:01:53,370 --> 00:01:58,130 Second test is false. 27 00:01:58,140 --> 00:02:01,710 And this is the almost all man style. 28 00:02:02,100 --> 00:02:06,600 So remember, remember that your code is unlikely to present that on a paper. 29 00:02:06,600 --> 00:02:13,410 So the fact that an R is more compact will save on trees. 30 00:02:13,410 --> 00:02:19,470 If you have the choice, you should choose the style that is the most readable that the decision of. 31 00:02:20,460 --> 00:02:27,990 So for it's my decision is the is that keener is more readable I think. 32 00:02:28,020 --> 00:02:31,350 But if you choose all, it's completely okay. 33 00:02:31,770 --> 00:02:34,560 So you can choose however you want. 34 00:02:34,560 --> 00:02:35,430 Just don't mix. 35 00:02:36,070 --> 00:02:37,380 Just don't mix. 36 00:02:37,380 --> 00:02:43,380 Two is to code styles because the code will become the unreadable here. 37 00:02:43,380 --> 00:02:50,840 For example, if you mix the Key and R and Allman, it's not okay, but it's a syntax and the compiler, 38 00:02:50,860 --> 00:02:53,280 the compiler with no problem. 39 00:02:53,820 --> 00:03:03,300 So if you have multiple nested blocks, the intense can give an idea of which block the code resides. 40 00:03:03,300 --> 00:03:06,690 And however, comments can help too here. 41 00:03:06,960 --> 00:03:13,950 So in particular, if a code black has a large amount of code, it's often helpful to comment the reason 42 00:03:13,950 --> 00:03:21,510 for the code block So for example, if an if statement is the it is helpful to put the result of the 43 00:03:21,510 --> 00:03:22,770 test in the code. 44 00:03:22,770 --> 00:03:26,370 BLOCK So you know what the variable values are in that block. 45 00:03:26,370 --> 00:03:31,410 So it's also useful to put a comment on the closing brace of a test here. 46 00:03:32,340 --> 00:03:33,060 So. 47 00:03:34,390 --> 00:03:37,350 So let's let's write an example program here. 48 00:03:37,430 --> 00:03:38,920 Example just an. 49 00:03:40,410 --> 00:03:41,270 Example. 50 00:03:41,460 --> 00:03:42,150 Example. 51 00:03:42,150 --> 00:03:43,830 One year. 52 00:03:44,980 --> 00:03:47,230 So let's create an if. 53 00:03:47,740 --> 00:03:48,640 What's here? 54 00:03:48,640 --> 00:03:49,660 If X. 55 00:03:49,750 --> 00:03:50,180 Let's create. 56 00:03:50,200 --> 00:03:51,700 First, let's create the integer. 57 00:03:51,880 --> 00:03:53,980 Integer x equals one. 58 00:03:56,050 --> 00:04:04,130 If X is is greater than zero, you will learn about all of this if and ll statements in next lectures. 59 00:04:04,150 --> 00:04:05,470 This is just an example. 60 00:04:05,470 --> 00:04:06,910 So just keep in mind. 61 00:04:07,570 --> 00:04:14,680 And here then X greater than this. 62 00:04:14,950 --> 00:04:21,490 And here we will add the lots of code quotes here. 63 00:04:21,880 --> 00:04:25,420 And then lastly, if. 64 00:04:27,170 --> 00:04:27,830 If. 65 00:04:29,040 --> 00:04:31,320 It's less than zero. 66 00:04:31,500 --> 00:04:35,010 And let's add our statement to. 67 00:04:36,780 --> 00:04:37,650 Else. 68 00:04:38,920 --> 00:04:39,780 Let's hear. 69 00:04:41,950 --> 00:04:44,410 Then as X. 70 00:04:45,160 --> 00:04:47,740 Is greater than or equal to zero. 71 00:04:47,770 --> 00:04:54,990 If so, if it is not less than zero, then X is greater than or less than zero. 72 00:04:55,000 --> 00:04:58,720 So we just wrote it as common so it doesn't comment. 73 00:04:58,720 --> 00:05:05,710 So it's for easy to understand in the next C++ programmers. 74 00:05:06,040 --> 00:05:09,160 So here lots of codes again. 75 00:05:09,370 --> 00:05:11,110 Again, lots of codes. 76 00:05:11,110 --> 00:05:12,160 And then. 77 00:05:13,650 --> 00:05:14,400 If. 78 00:05:15,410 --> 00:05:19,250 Here X is less than zero. 79 00:05:19,640 --> 00:05:25,670 Just mentioning that this ls is the if statement. 80 00:05:25,700 --> 00:05:26,300 Else. 81 00:05:26,300 --> 00:05:29,050 So there's is nothing else here. 82 00:05:29,090 --> 00:05:36,230 If you put this as a comment on a closing brace, it means that you have a search term that you can 83 00:05:36,230 --> 00:05:39,200 use to find the test that resulted in the code. 84 00:05:39,200 --> 00:05:39,550 BLOCK. 85 00:05:39,560 --> 00:05:43,630 So the preceding lines make this comment irrelevant. 86 00:05:43,640 --> 00:05:51,200 But when you have the code blocks with the many tens of lines of code and with many levels of nesting, 87 00:05:51,200 --> 00:05:53,410 commenting like this can be very helpful. 88 00:05:53,420 --> 00:05:58,460 So for example, oh, I'm searching for my x less than zero statement. 89 00:05:58,460 --> 00:05:59,780 Where is the statement? 90 00:05:59,780 --> 00:06:09,890 You just press the control plus F here of some control plus F here and then x less than zero. 91 00:06:09,890 --> 00:06:15,710 As you can see here, our idea of or you can use just the text processing applications as well. 92 00:06:15,710 --> 00:06:20,750 If you just use this commenting type, you will get the. 93 00:06:22,920 --> 00:06:25,170 Your desired search result. 94 00:06:25,920 --> 00:06:29,130 In next lecture, we're going to learn about the writing statements. 95 00:06:29,130 --> 00:06:32,040 So I'm weighting you in next lecture.