 All right, this time around we're going to talk about loops and this little guy I guess is going to help or not loops control constructs in general So that's going to include loops, but it's going to extend much more beyond just that control constructs are you know your bits of code the part of the actual syntax of the language that Typically it doesn't necessarily have to be It can be part of a like a framework that you utilize as well, but typically part of the actual syntax of the language that you That you use to things like Various conditions or to repeat the same thing over and over again and Pretty much everything is based off of that Just you know can combine them in interesting ways, but pretty much everything is that That being said there's a fairly decent amount to talk about here, but it's Generally pretty straightforward One thing I will need to point out is that these various control constructs can be divided into two categories statements And expressions and this is actually super important When necessary, I'm going to talk about them When necessary, I will add at the specific thing I am talking about so if statement versus if expression Those are different things So what what is the difference? A Statement is an individual Thing that does not return a value afterwards Kind of like a procedure in atta it executes The next thing executes the next thing executes and unless they're passing values between each other through like in-out parameters So, you know some kind of global that that exists Even if it's thread local or routine local or whatever that's that's still you know the shared state Then no information is passed between them Doesn't Sound like there's much significant there, but the big difference most programmers will immediately recognize when using a statement versus an expression Is that you can use an expression To assign something because again something is returned out of an expression so You can if you have if expressions in your language assign A value to the result Um to the result of that if expression Okay This I don't know if I want to say is the major Difference between them, but it is it's This this matters It varies a lot depending on how your languages work But oftentimes statements are much more limited in where you can use them whereas expressions are not That being said In the languages There are certain languages C sharp and edda are not them at all But there are certain languages where everything is an expression and you make something a statement by not caring about the return at all And just ending it with a semi colon That approach is super useful. There are some complexities for managing it inside the compiler, but It's not too bad, but that that approach is super useful So As far as edda and c sharp How do they stack up? We'll cover some other notable things later As far as if goes You know your if then if else If else if else all that crap Is that right? Is that right? Both of them Have if statements that are Completely identical You know, I'm not really going to be talking about syntax. I don't really give a shit about the Minor syntactic differences and arguing that oh well semicolons are less typing therefore. It's better or oh Keywords are more clear therefore. It's better. Those are subjective things I'm caring about what the actual implications are for the code that is written and honestly considering templates exist and Tab completion and tons of other things really not that much actual typing T tab gives you then shift Curly bracket gives you the curly bracket. It's It's really not that different so one thing C sharp has that's Rather convenient Is the ternary operator now being an operator? This is part of an expression So this is essentially c sharps If expression syntax Ternary operator, however, is rather limited Until target typing is implemented There's a bit of coercion that has to happen at times. It's rare as all fuck though So you typically don't need to worry about it, but that Is a thing you need to be aware of at times Um Generally not something you want to involve in an expression, but you nested ternary operators become a huge problem to read Um Typically speaking you should just write a function in that instance and use the function call instead of the nested ternary operators How about it is something to to keep in mind um Because of the very simple nature of the expression Because anything inside of it is just another simple expression Uh, typically just the value that it's going to result into um You're very limited in what can be included inside of a ternary operator Um, again, typically it's just going to be the value So any kind of more complex logic It's going to be really difficult to put in there Um, again, that's sort of justified in that you should probably be just be using a function in that instance and return the thing that you need Because function calls can be used in expressions. So Yeah um Method in the dot net world, but this does apply to ara as well because ara has if expressions And they're more powerful and useful Rather useful in certain situations um, I do particularly like how You can do the things like constant assignment and then with an if expression to get different constants depending on certain conditions um Ada constants are noticeably different from dot net constants. So that's that's an important thing to keep in mind um Constancy and ada has to do more with The value never changing rather than just being like some kind of macro expansion kind of thing kind of like read only in the c-sharp actually A read only field is very similar to an ada constant but even then there's some differences so anyways, um If expressions are definitely more powerful you do you have to be using more modern versions of an ada compiler to Utilize them, but honestly by this point pretty much anything that's even remotely worthwhile should be supporting at a 2012 So you should be able to get them um You can nest Much more complex expressions inside of them Which can be handy However, again, you should probably be using a function call at that point so They're nice level of sophistication the syntax you really don't need to learn new syntax you put the thing inside of um parentheses, which is the norm for expressions anyways and boom you just Write it out Like your normal if statement I do Very much appreciate the syntax of that. I know I said I wouldn't be saying too much about that um But it's a discoverability and consistency thing With a ternary operator you need to learn entirely new syntax That's where this differs I'm not Going to argue that one form of consistent syntax is better than the other form of consistent syntax but When you've got one language that tries to keep it as a consistent syntax and another that introduces some new syntax The one that keeps it consistent is a clear winner there Similarly you have another construct the switch case Thing Different names depending on what language we're talking about, but it's um In a way a more sophisticated If else if else if else if then kind of Kind of construct You got a single value and a single expression that you know will evaluate to a single value That you then go through a bunch of cases that get compared against Now it's complicated because the exact mechanism behind this works varies and I do Appreciate how added does not require you to put a break at the end of every single one um That being said it is actually sometimes convenient in the c world Where you don't have to Put the break and you can fall through to another case because there are times you want to fall through to another case and it's not just Clever tricks. I think it's called the jensen's device, but I might be mixing up my my things But there's a situation where you actually want to do that In some Very bizarre code, but Very useful kind of thing That being said uh see sharp requires that break statement Or some kind of equivalent I'm done this case so it operates Pretty damn similarly to ita's in that regards, but the mandatory break is Superfluous It's typing that I really don't want to do similarly in ita's There is the convenient side of being able to put multiple things in a single when clause In c sharp much like in c you have to have multiple cases that Actually do fall through but since there's no statements inside of them. It's considered valid That should make a lot of sense. That's how you get the multiple cases with the same Code that gets executed you Have multiple checks and just fall through C sharps a little bit more transparent about what's actually going on But I definitely appreciate ita's syntax for it a little bit more it you can cluster things together in the same case And even use ranges, which is super lovely that being said Or about at the end of where ita is actually winning C sharp switch case statements Have a number of benefits It's very easy to do go-tos between these. That's essentially c sharp's solution to fall throughs but it allows Cleverness like instead of falling through actually going up to a case above where you are currently at um This is not something you're going to want to do very often That is a very complex code strong to construct in is similar to a lot of the Uh clever trickery that you wind up seeing with c and switch case statements That I like having the option and I like how you don't have to Do anything to Not use that option. You get the reasonable good. I'm not using this default You clearly have to opt into it And a lot of people don't even realize that you can just write go-to and then the case label But yeah, you you can do that another major thing C sharp in an effort to introduce a lot of the things that ebb sharp has introduced which is super bizarre I don't understand why microsoft is doing this You'd think you'd want f sharp to specialize in that shit and then use the appropriate language for the appropriate task, but Whatever It's sort of becoming clear that they want c sharp to be the only language that they really do because they pretty much abandoned visual basic and F sharp really isn't getting the support that should be Concerned about the the future of other languages, but still the the cls compliances. They are and that's my major reason for using it the Big thing introduced It's originally done with f sharp not In the dot net world originally with f sharp not f sharp was the first language to ever do it. That was not the case is uh pattern matching C sharp utilizes pattern matching through its switch case statements, and there's a bunch of clever things that you can do especially now um What the c sharp nine introduced introduction when that when that's gets finalized There's going to be a lot of very clever things that you can do But even at the c sharp 8.0. There's there's A ton of incredibly useful stuff Polymorphic switches are absolutely fantastic. The idea behind that is you pass it a variable that is a class specific specifically not a struct Well, no, you can do a struct and then switch on the interfaces But either way you can switch on any of the things that it inherits from That covers much more broadly than what I was saying Oh, excuse me Actually with that in mind you could even pass it in something that's just typed as an interface and then just switch on Other interfaces that interface depends on neat but the idea is that each case is a type That the type obviously has to be able to become it'll yell at you if it could never actually hold true But then you can also pass it a new name That name is then used to reference that same Value But now Through the type that you just matched So no casts no coercions nothing You already know because you already checked that it is that type so you can now reference it exactly as a type using the new name This is Super useful simplifies a lot of code where you would want to do such a thing which is actually quite often and I'm so glad that exists They're going to be and to an extent already are Introducing a lot of More sophisticated situations adding certain clauses on top of that like if this is this other type that also Requires a certain condition to hold true like the one of the fields within this Object also has this specific value or this value within this range or whatever Then there's a specific case and you can see the level of sophistication this has this is very useful for Um Doing these operations doing very complex operations very useful for managing very complex systems And it's all done through the same syntax because it's all essentially the same thing I like it another important construct that I had mentioned with the switch cases Whatever you want to call it is just cases Case wins Whatever Um, it's just the simple go-to Both languages have them and I'm glad they do One thing I do want to say about eddas however That is absolutely fucking bizarre and I cannot believe this is actually part of the language at all It is asinine and I want to bitch slap somebody because of how stupid it is Ada has two different syntax for declaring labels That's right. See when People criticize the language over being bloated They're not wrong the language is bloated Because again, there's two entirely different syntax for declaring labels And that's just asinine And see sharp. There's only the one syntax There's only one thing that you need to learn and you can use that label for in To sit that label syntax in any situation where you can put the label That's a lot better Next up as far as control constructs go would I supposed be the loop? Loops and that are better. I'll flat out say that but first loops and C sharp got The while loop nice and simple Give it a condition. It does that End of story You've got the standard for loop very C style for loop I appreciate you're having that syntax to be perfectly honest. I understand some people don't like it, but there are certain situations where that syntax is useful, you know, not Meaning to declare a variable that exists outside of the for loop scope is handy But you still can the fact that each part of the for loops You know preamble Does not necessarily need to be filled in is rather useful as well It's a very nice generalized syntax But I still think it pales in comparison to something that I had I can do But Then you've got the for each. I do appreciate how C sharp is very clear that it's a for each And that it utilizes a different syntax from the for loop For each makes it very clear that it's an iterator and that is going to do every Go through every single element And that what you do inside the loop body is for each element Right on the other hand Has a generalized loop You can add specific things to it, but it's still always a generalized loop I appreciate how generalized that is actually because together with some other unique things that it has It becomes very easy to create Some rather unique loops So you can put the exit condition Or even just an exit statement Wherever in the loop and it is essentially just a go-to to the You know position after where you would jump back up Um, but it's clear syntax and using a go-to of course Which is good. You always want that when you can The ability to put an exit wherever or an exit when And then whatever the condition is is Super convenient putting them wherever gives you basically any loop you can possibly have That being said there are some high level loops that already exist Well add a lax a for loop it does still have the while loop you can give it a condition and it will go and do that whole thing As for a do while loop That's pretty easy to synthesize just by putting the exit when condition at the very end of the loop Now it'll just go through the first iteration regardless Check the condition and then if that condition doesn't hold goes back up. There is the For in-range loop and the for in-collection loop Both of these are for each loops, but it's Confusing For in and for of Probably not the best of choice Or am I mixing up my languages? That's always a possibility JavaScript does that and it's Super fucking confusing. I regularly forget which one I actually meant to write No, I confuse those in atta too So it's both As far as iterators go and the for each loop syntax C sharp wins, but otherwise I think atta has overall the better loop system it's more I mean a lot of the high level loops still exist, but you Have more freeform options You can add exit conditions all over the loop if you want to honestly if you need to I've had to at times That's helpful Now I'm running off memory here. I've only done this once so I may be wrong But it is it's possible. This is a definite thing. It's possible to label Loops and atta and that's that's useful. There's situations in which you need to break out of a specific loop but not The most immediate loop you're in that that's a thing um As part of the exit clause, this is the part I think I think I remember right As part of the exit clause you can between the exit and when or even just after exit and then just It's done. There's no clause You can put the label name and it'll exit out of that loop that you specified If you want to do something like that In C sharp you have to use a go-to Dedicated syntax makes it a little more clear Having the loops labeled is nice I mean shit it even describes the intention of the loop. What is the loop? That's something I often comment in the dot net world, but The label I mean technically is the comment That's handy as I mentioned pretty much Every other control construct is just Those in certain combinations. In fact, some of the ones mentioned like the while loop is Very obviously an if condition and then the loop The if being inside the loop actually at the very beginning, but it's you you you get the point I'm not going to consider the control constructs that are part of edis tasks as being actually control constructs Because they are fundamentally just those And they're only applicable in the csp world talking about those would largely be frivolous because it's the same as with The video I already did on concurrency We already know we've already covered how those are different Sure, I might not have mentioned the specific control constructs that are associated with csp, but that's not the point The point was that without it, you'll only have csp And since there's nothing to really compare there that hasn't already been compared, there's no point in going into that You see where I'm going Hopefully Everything's already had to been said as far as that goes has already been said As far as non-standard control constructs or you know things that aren't part of the language itself The syntax of the language, but they are part of the standard library Or are things coming soon? Parallel operations. That's a big one Add a 22x is getting parallel loops Parallel loops the idea is that you write them as similar to as a normal loop as possible But it just has parallel at the beginning The operations will be attempted to be implemented in parallel I'm not sure exactly how they're going to deal with that I'm not sure Where they're at as far as that proposal goes. I haven't been tracking at a 22x very closely. I just know it's Something that they're working on Regardless though You write it exactly like a normal loop, but the operations happen at the same time If certain operations for whatever reason take longer than others You don't actually resume control at the end of the loop until the entirety of the loop is done Okay Ida has dedicated syntax for this dedicated syntax is always preferable C sharp the dot net world in general really implements this through the parallel Stash class It's a static class that provides methods which provide this behavior But there is the Parallel for parallel for each that kind of stuff They feel certainly more Procedural than really part of the language itself but Is I Still gives you access to the stuff, but it's certainly not The syntax that you ideally like to be using but um another form of parallelism I mentioned it a bit with the Intrinsics but the quick primer on it another way to do things in parallel is to have Them just happen under the hood Have them as intrinsics that just happen C sharp allows that with certain types Falls back to reasonable behavior and it doesn't but could The standard library would have to code for it Would have to install specific runtimes on specific architectures, but you certainly could do it as far as Other languages go though F sharp I tend to mention a lot in this for obvious reasons F sharp doesn't have a whole lot to say especially a C sharp pattern matching is catching up to f sharps There's not really going to be a whole lot of a difference the syntax is certainly different and f sharp syntax is almost sort of Better but funky to read because of course functional programming does just It's not It's great on the fingers not in the eyes And again tab completion You don't really need to worry about great on the fingers because tab is always just right there You really don't need to type that much There is a major Place where this is significant though Seed seven I believe I've mentioned in one of these previous videos I do not remember at all which one but in seed. Oh, it would actually just be in the introduction In seed seven however, it is possible to introduce entirely new syntax into the language itself That is significant because that means seed seven can easily have the single Best control construct for every single situation That's a big deal Parallel loops wouldn't need to be part of the language itself because they can be Added in by the parallelism library that somebody else writes special control constructs that are useful for you know text processing which Tends to rely on control constructs that are unlike anything ever used anywhere else Could be implemented And not have everybody else pay the burden of it Because they exist within a library that somebody depends on that somebody writes That is again not part of the language itself You get them when you need them But they're simply not there when you don't that really Wins out over anything else Because of the sheer power of it essentially the syntax is just A fourth form of subroutine The syntax is just Another name for a function or procedure or operator That's a clear winner There's probably a few isolated cases that I could talk about but didn't but you largely get my point We've covered any of the major stuff and My ideals as well. So that's it for this video guys Have a good one