Speaker 1: 00:00 Frank, it is time. It is that time of the year. We're a new version of C sharp has calmed down from Matt's targets and himself and blessed upon us in visual studio. The great way of creating even better code. It's here. C sharp. Hey Frank, you don't, Speaker 2: 00:17 some people say we shouldn't be chiseling these things into stone, but I like it. I like waiting for it to be chiseled. I want the full C sharp eight spec in rock I guess. Uh, yeah, it's here. James. I feel like it's been here for awhile. I'm an early adopter. I've been rocking the C sharp eight but it's, you're right. I think it's been officially released. Was it officially released with.net core 3.0 that's kind of what I'm assuming. Speaker 1: 00:43 Yes, that is correct. a.net comp officially. Dot. Net core C sharp eight is supported by.net core three and any framework that implements.net standard two one that I believe is the official rich Lander stamp quote thing. Speaker 2: 01:02 Should we explain.net standard 2.1 so just I want to put out there.net standard 2.1 is a cool thing. They, they've added a few things to the standards library that we all use. But if you're a library author out there, I've seen a little bit of weird confusion where people are like, I have to upgrade the dotnet center 2.1 no, no, you really don't. it.net standards, one of those things where you actually want to use the minimum version number that you can kind of get away with. And so a.net standard 2.1 it's just the thing out there. At this point, I recognize it as like what the compilers need, but now I'm wondering, uh, does a unity do unity developers get C sharp eight Speaker 1: 01:41 well, here's the thing is that to use C sharp eight I sat down with email for about an hour to figure this all out and, and I was like, if I can't figure this out then how's anyone supposed to figure out if me and emo can't figure this out? How are we not as anyone's supposed to figure it out. So here is the thing, C sharp eight just like C sharp, seven C sharp seven to C sharp seven one for the most part. These are just compiler changes. So if you enable C sharp eight any in any of your prod, any project, any project Frank, then this means if it compiles, it should just run and it should just work. Now there are specifically libraries that were added into Donnette standard two one but those were even back ported into.net standard two Oh and other ones via and nugget package like asynchronous, like I async enumerable for instance. Speaker 1: 02:42 That's actually a new get package. So even if you want to use those new features that are part of C sharp eight that are kind of part of the runtime or part of the Danette standard to one, you can still get those. So when you're saying you don't need to upgrade to done as standard to one, correct. But there are a few, I believe like indices and ranges. Those are actually run time run times of their RFQ that like they just don't exist. But for the most part, if you go in and you flip on C sharp eight, which you can do in your CS proj in your iOS project, Xamarin projects done this standard to one or even just try to use it visual studio, we'll be like, Hey, do you want to turn on the C sharp? And you're like, yeah, let's do this as part of the time. And then you just use it and everything's readily available. Now officially there's official quotes, right, that is there sort of that, you know, official platform support here. But if it compiles Frank, it compiles. Speaker 2: 03:42 Yeah. Yeah. And uh, tobacco up your point about the extra library is not really being needed. I've been using C sharp a and my.net standard 2.0 libraries for a year now using the preview versions. And I have not needed to include any other libraries at all. I wasn't using the fancy new index and range that I hope we'll talk about on this show, but uh, yeah. And async streams, whatever. We'll get to that anyway. Uh, yeah, that's Senator 2.0 it's still a happy, safe spot. But, uh, we're in this fancy new world of a 2.1. So James, um, what does one physically need to do? I know in visual studio for Mac you can go to a project options and under the language they have a few options, like stable, latest preview, ignore all those, just set the version number that you want to your language. Cause honestly I find it very confusing how the build project picks latest versus preview and all that. So I just go into a drop down and pick C sharp 8.0. What do you do? Speaker 1: 04:49 Yeah, I, I start to use the feature and then make visual studio. Just light it, light it up. Uh, but, but I usually go into my CS proj and then I say, um, Lang version and then I do eight dot. Oh, and save. Yeah. Speaker 2: 05:06 Manually editing. Like a Unix hacker. Speaker 1: 05:10 Yeah. You know, it's there. It's just you, you do it. Um, well it's a little bit tricky because in Donna at standard libraries now when you go to do it, it says, um, automatically selected based on framework version. So it actually doesn't let you do it in visual studio 2019 for some reason a which is on it just uses the default Speaker 2: 05:33 tooling getting in the way I guess in that case just go type it in yourself. Yeah. Speaker 1: 05:38 Yeah. So I just type it in myself or again, when you use the feature, uh, then a little bubble comes down and says, Hey, do you just wanna you know, use like the latest feature of yeah, you know this stuff. Yes. Speaker 2: 05:52 Now that you say that, I, I actually have done that myself. Um, we'll get to my favorite feature C sharp eight that Nobel references eventually, but I would just go to the top of a file type knowable enable and you're right, I could just right click on it and it's like, you want to use the latest C sharp, don't you? And I'm like, yes, yes. Tool. I do. I do. Speaker 1: 06:11 That's right. And there's for, for all intents and purposes here, what is happening is that there is a default language version that is applied via like target files and this is pretty low level, but each project type can specify, Hey, I support this version as my default. Now Donna, core three defaults to eight. Anything done in core two 73 Donna Sandra, two 1-802-073-DONE as Sanders to one, even seven dot three and any framework is seven to three. Now it's not in there in this, you know, overview is what abouts Samarin projects. What about UWP projects? Great question. Because Xamarin projects do implement.net standard two one I literally demoed it at dot Netcom for using GRPC. And since that platform supports it, they should, for all intents and purposes here, change their target files to support it. So I, James mag Magno went off to the magic world of get hub where everything is open source and I wrote a little, a little, a little issue. I said, please default to CCRB for all new projects and uh, it's already done an Android and I'm just waiting on the iOS one for them to flip the switch. And that means inside of the iOS or Android project, it would just automatically default to dot Datto, which would be delightful. Speaker 2: 07:40 That's very good James. Thank you. As the Xamarin community. Thank you sir. Uh, this is again what I was saying about, I don't understand what latest stable preview any of that stuff means. That's why it's easiest to hardcode it, but file new project, that's very important. You don't want people typing their own NOL coalescing assignments like manually, like animals or anything like that. But also roughly speaking, I always think of Xamarin as being, keeping up with the pack if not ahead of the pack most of the time. So I had no doubt that we were going to have good C sharp eight support and we have had it all throughout the previous cycle. It's just a matter of like you said, of uh Oh yeah, the defaults. Those are important. Better get those into shape. Speaker 1: 08:27 Yeah. And the, the one problem that will always sort of come up is, uh, with the Donna sander library. Cause that is a two O projects. If you're doing Xamarin forms, you're gonna want to flip on the switch anyways. Anyways, it's super easy. Flip it on cause then you get to use awesome features. And you may have noticed, what was it maybe two weeks ago or so, I was doing some hack Tober stuff and I tweet stormed when I flipped on C-sharp aid and Xamarin essentials and it just started making all my code so much more readable, so much more elegant. Like there were features in C sharp eight that I was like, Oh, how come no one has ever told me this? Literally we were prepping for this podcast and I will link to this Twitter, um, that are this tweet message that I sent. But I literally went and I said, Oh IMG, no coalescing assignments are the coolest thing ever. Mad targets. And why have you not told me about this? Because no one ever talks about C sharp eight features everyone's talking about. I think a numerable Frank and I don't even want [inaudible] the numerable. I want no coalescing assignments Speaker 2: 09:33 vacuum. So let's go into the nerdy features that maybe aren't getting all the public publicity that they should. Uh, cause yeah, there's um, we, I think we were talking about during the 7.1 7.2 7.3 days about, we liked this editor, iterative refinement, but a whole new language. They, they bit off some big chunks of, uh, syntax here. And I want to explore how we can shorten our code and play code golf more readily these days. Can we start with my favorite one? My favorite one. This is a little bit of performance James, and it is called Reed only members on strucks. Now if you've ever written instructs in a C sharp or whatever, you know, it's a value type and it's not passed around by reference. We like these because they're memory efficient. They don't affect the garbage collector. Lots of reasons to love strokes. But they weren't always super efficient because the compiler had to make some assumptions. Speaker 2: 10:36 If you wrote a struct, you can write a method on it that modifies the state or that struck just like it was, um, an object or something like that. It turns out that's a little nasty because that means every time you call a method on a struct, it has to make a copy of that struct just to be safe about how you're dealing with it. Now, James, now with the glory of C sharp a, we can put the keyword read only, which is a little weird, but whenever you put the word read only on, uh, the methods and maybe even, uh, fields of the strokes, and you can say that I promise, I super duper promise not to modify the data in the structure while this function is running and therefore the compiler can, uh, output more optimized code, which is awesome. Speaker 1: 11:28 Yeah, I'm seeing here, I love the samples on the website too because as you're browsing through and there's links in the show notes for it, they sort of do the before and after. Like, here's what it did look like, here's what you would add and here's why you had added a in general and, and then here's how it's improved. So yeah, they have a good example of like an X and Y points and then you might calculate the distance and you can add a read only to the distance to ensure that you get that optimal performance because the accent Y would never change. So it can, um, auto, yeah, make it better. Speaker 2: 12:06 Well, it can ensure correctness too. So if I declare that, I promise I'm not going to modify, stay and then woopsie Dipsy I try to modify one of the fields. The compiler can actually yell at me and say, you promise not to do it. And so that's good because it's more kind of designed by contract. You're stating your intentions. I don't intend to modify anything in this function. It's good. I like that kind of stuff because you get performance and readability out of it. That's kind of a win-win. Speaker 1: 12:34 Now, you know, I'm all about, um, cleaning up code, Frank. That's what I love about new seashore features is how do you make my code look better, more readable, more maintainable? And there is one thing that I hate Frank and coding. Do you know what? Well, there's multiple things. What is one of them? Oh, Speaker 2: 12:55 Oh, I, um, uh, in version, yes. Speaker 1: 13:00 Control. No, I don't, I do hate IOC. Uh, so I don't like underscores on names. That's one thing. That's old school. Yeah. Gotcha. But I have always been anti arrow. You know what I'm talking about here? Which arrow are you talking about? Like Lambda functions, that arrow or which arrow I'm talking about? Those are also one. No, I like Lambda arrows. Those are good. Those are okay. What I don't like is nested if statements are nested using or nesting things where you're, you're squiggly Lee's create an arrow. Oh, Speaker 2: 13:38 I know what you mean. So like when you zoom out of the code, it's indent and then, and then, and then out that out on, out then out. Then we used to have this in lisp, but instead of out and out and out, down it would be parentheses, parentheses, parentheses. Frances, just an infinite number of parentheses as he tried to pop the stacking, get back to where you want to be. Yeah, I get you. I get you. You know I used to write code that had people used to call it early returns functions that had multiple return statements in it and there was a real dogma against that for quite awhile. I had a boss at Microsoft who yelled at me about it once. It's like, you should only have one return statement per function. I'm like, well then why does the language allow me to write multiple. Gotcha buddy. Speaker 1: 14:23 Hi. Yeah, I've always been a fail fast and which has returned fast. If, if, if I can get out, get out right now it's very clear like I went here and that can't go anymore. So I can look at the code and say, all right, this thing is knowledge. Get out of there buddy. Um, yeah, I'm, I'm a, I'm a return fast type of person too. And because I, when I first got to cannon, we had a same thing. Someone was very much one return statement and then that person left the company and they said, Oh Whoa, let's change all the code to be Frito turned first freedom. We do whatever we want. So, so this one ended up really saving my behind when I was doing some refactoring because I was inside of some deep Android code where I was getting a screen information and window information. Speaker 1: 15:17 And these are all like Java cast objects back and forth. And these were objects that needed to be disposed. And you know what you do with objects that need to be disposed, Frank, you totally ignore them and hope the garbage collector takes care of it until you find out that the garbage collector can. So you better be using a using statement around it. And then if you have using statements inside of using statements inside of you using statements. And what does that Frank, I believe it's referred to as an arrow. James, as Carol has appeared in your code, it is this big hole, that row. Speaker 2: 15:52 I was wondering where you were going with this whole arrow discussions, but now I got it. Okay. So we got some new syntax using VAR. Now all the VAR haters are really going to hate this one, but you can actually still put the type name. But so when you're declaring a variable and you put the word using before the declaration of that variable, then that introduces a new implicit scope just like C plus plus. So we have resource allocation is initialization just from a C plus spots and so when you exit the function, you're guaranteed that your disposed functions will be called. And yes, James, yes. Where has this been all my life? Because like you, I do a lot of interrupt with native libraries, specifically iOS and talking to see programs all the time. And although I know I should be disposing of objects constantly, there's, I create tons of foundation objects that I shouldn't be disposing. I never do because it's annoying. And you got gotta put those curly braces and create indentation and all that, but now you just put the word using in front of the variable declaration and that's all handled for you. This is the best. Speaker 1: 17:05 Yeah. I would really like an analyzer that goes through the code and maybe this exists already. Someone tell us that wherever I'm doing VAR or whatever, I'm assigning something and I'm not rapping in an in a dispose. It should just put a squiggly there and they'd be like, you should use using right now, friend. So you just do that. That's there. That's there. That's how I learned about it. Oh no. Speaker 2: 17:25 Yeah. So the uh, you know me, I'm, I'm in, um, visual studio for Mac and we've gotten all those Roslyn analyzers over those last year to the point where my right column on old code bases is basically like, we want you to change this. We want you to change that. We want you to change. Yeah. It's pretty nasty. Uh, but I've gotten to the point where I maybe five of those Rosalind things and then keep the rest and basically just blindly go through my code saying, yeah, Roslyn, whenever you want, just make it better. Thanks buddy. And that has worked out great. And it does this using one just like you would walk. Yeah. Speaker 1: 18:06 Super duper nice. And somebody's like, Oh, I don't get it because you know, you just, you're just getting rid of some squiggly as I go. Yeah, but you don't have to think about it. The compiler does it for you. And then also when you get into this situation where there are multiple, that's where the real win is. You're just like, I'm just going to do this and it'll handle knolling for you. It'll figure it all out. So now you don't have to worry about is it normal? Do I hit the question Mark. Dot. Dispose. Just you just use the using and it's good to go. And in the code, the before and after that I showed was just mind boggling and it fixed the bug because I wasn't disposing and the bug, by the way, it was like, call this method 24,000 times and then it will crash. And that is correct. But regardless, the using statement did fix it and using VAR. So good. It's my favorite little hidden feature that I think is just absolutely delightful because I do a lot of file IO. Right. When you're, when you're doing IO, what do you do? You create streams, you create stream writers, you do files and those all have to be disposed and you're usually doing those in concurrent, um, lines of code over and over again. So Speaker 2: 19:18 yeah, and even just something as basic as an S string. So that's the string type used by iOS. Uh, those things just lay around and accumulate and wait for the garbage collector to get to them. It would be much more friendly, nice to the system to actually dispose of them when you're actually done with them. And you never do because you have an strings all over your code. But now if it just means I have to put a little using here and there, I'm totally down for that. Good stuff. That might be something that a Speaker 1: 19:51 lot of developers don't realize is, especially in the world of, of, of Xamarin development, you sort of have to have the objects, right? You have your native object and then you have your, your, your managed object and you need to properly dispose of them usually at the same time if you can, especially images. And things like that and circular references. So just letting this handle it for you as much as it can just makes life so much easier. Um, but yeah, there's a lot more goodies. Frank, let's take a quick break and thank our sponsor this week and Ferno red, they make building software easier because they will help you build it or just build it for you themselves. Listen in Ferno, red technology, they're a software development company. They build products for businesses all over the country. They specialize in modern development including web cloud, IOT, mobile apps, TV apps, and even smart refrigerators, right? Run that.net Speaker 2: 20:48 code or write on that refrigerator. They have a long history of Don ed and Xamarin building cross-platform apps and they are here to help you build your next application. Had to in Ferno [inaudible] dot com or find them on Twitter at Inferno red attack. That's right. Head over to in front of red.com if you're looking to build your next project and things in front of red for sponsoring this week's bod. Thank you in for no red James. Can I get a smart refrigerator in an apartment? Can I swap out my refrigerator? Yeah. Ooh, you might have to put back the old refrigerator. Boy, that's a lot of work. Speaker 2: 21:25 Okay. Okay. Back to C sharp a. I gotta do another funny little performance one, but it's also kind of a correctness one. So you, I'm pretty sure like local functions, these are where I have a method on typing, typing, typing, and I'm like, you know, it'd be nice if I could call a little function here, but I don't necessarily want to like have all the other functions have access to it or maybe it's a Lambda, but I want to give the Lambda and names. We've got these cool things called vocal functions. Yes. Trick is, yeah, you like them, right? You're down. I was not a believer, but then Frank, I started to use them in Xamarin essentials when we started to, when you start to have to worry about a synchronizing methods and task completion sources and registering and on registering events and things, it super cleaned up the code. Speaker 2: 22:21 It was mind boggling. Awesome. Yeah, I mean just giving names to things turns out that helps. If you can describe what they do, things like that. Well, they have a new feature, James and C sharp 8.0 called static local functions. And the cool thing here is that anytime you have a Lambda or a local function, you kind of have to assume that you're allocating an object. That function is usually represented by an object. That means it has to get garbage collected at some point, et cetera, et cetera. It has to do that because it has stayed, maintain variable references, things like that. However, if you just declare a local function to be static, you're saying, I'm not going to touch any of the variables that are outside my scope. So none of the variables in the function, none of the variables, uh, in the class. Speaker 2: 23:13 And that seems a little strange efforts. I'm sorry. I think you can access the class variables. Um, it seems a little bit strange, but it's a big hint to the compiler that if you promise not to do that, then it doesn't need to allocate an object. And so we're always pushing this, how do we not allocate objects so that we're not, uh, having a lot of memory in use. And at the same time putting pressure on the garbage collector later to free up objects. Basically code that doesn't allocate is generally faster code. And this is giving us the opportunity. I love all these performance things. I keep picking performance ones but I love this one. Speaker 1: 23:53 That's good. No I, I I, I didn't quite get that one but now I get it because looking at the sample that they have of just adding two numbers, they're like, Oh you could access Y and X directly but you know, we're just going to assign it something different. So per per stuff anomic need to go through all of the Xamarin essential stuff and see, cause we have tons of local functions there and see why or if I can add static to them because most of them are just doing some computational stuff where I'm passing it items anyways. There's one for instance is a good one in our connectivity section. I pass it, I pass it the Android flavor and I returned back the generic version of like internet or no connectivity or limited connectivity and all that local function does is parse and does a few things in it. But I'm passing it, I'm passing it the information anyway, so I just make it static and then done. Wow. Speaker 2: 24:52 You got it. Yup. Uh, hopefully you won't notice performance things unless you are in one of those scenarios where this stuff really counts. Uh, generally speaking, you should write the simplest code possible and just leave it at that. But for scenarios where performance counts, you want these kinds of things, you don't want to be forced into allocating objects all the time. Speaker 1: 25:14 Yeah. Now, now talk now talking about not allocating objects and also talking about getting rid of arrows. I have been a big fan of pattern matching. Oh boy. We're going here, huh? Yes. I, I love pattern matching, but I'm, I'm gonna let you continue because I have sharp forever has had pattern matching. Yes. Yeah, yeah. You use it like every other line of code basically. Yes. Now there are some nice things that were added in C sharp seven such as the is referencing. So you can say if it is this type, assign it to this thing and some things in switch statements that you could switch over an object and you can pattern match if it was a dog or if it was something else. Now this feature snuck up on me and I started using it inside of Xamarin essentials. Um, because there's new pattern matching features. Speaker 1: 26:05 There are things called switch expressions. There are property patterns and Tupelo patterns and positional patterns. There's a bunch of things. I started using switch expressions. Now here's why. In my previous code, what I would do is I needed to get the orientation of the device. So if it was landscape or portrait or whatever the other values were, and in this code, in this little method, I would pass it some information like the window and then I would check to see is the window null and if the windows and I would return unknown and then I would switch case over this thing and then return the value and it sorta looked fine. But I go, man, Speaker 2: 26:54 no it needs a comment. Like you have to explain that code cause they're like, why are you checking for null here? And then doing that. Yeah. It's tricky enough for sure. Speaker 1: 27:03 It's tricky enough. And then I said, well man, wouldn't it just be great if I could somehow put that all into one switch thing and the compiler or visual city was all, I can just just tap this button like we see you're in for an author to do this. So what you can do is it has this fancy syntax where previously you would like say, Oh, I want to switch over, you know, um, orientation and then you would say case orientation dot whores during, you know, landscape. And then return this value or, or then assign it, hit break and then return on, it'd be like three lines of code, you know? So what switch expressions allow you to do is they allow you to say, here's the thing, and then switch over it and just whatever you want it to be. Do it. Uh, so it's a little bit hard to describe in words, but what I would say is I would say window question Mark. Speaker 1: 28:07 Dot. Orientation switch. Okay. Yeah. And that means that that value that I'm switching over could be an interim or it could be no. All right. And then I can say if it's normal Lambda, return on unknown, if it's, um, um, if it's portrait Lambda this and you don't have any returns, you don't have any, you're returning this switch expression, no variables, no extra, no variables. You don't have to assign anything. You, there's no defaults, there's no breaks, there's no tricks. That's the biggest one. None in it. Right? And then there's a magical catchall, which I love, and, and then you can assign anything to it, but they assign underscore to it. So like a default, you say if anything falls in here, return this thing or throw an exception and then boom, you just go to town. So really they have one where you're switching over like a IOM, a color and it just dramatically reduces the scope. But they have all sorts of really cool ones in there that, that show you that really, um, it allows you to pass it all sorts of different parameters too and just really clean up that code. Yeah. Yeah. Speaker 2: 29:26 And I give 'em uh, I have a funny way I think of this, the reason it's called switch expressions is because we've had switched statements in code forever. And if you kinda keep the difference of statement versus [inaudible] versus expression in your head, it's um, a statement does something and expression computes something there. Those are the two, one's in action, one's a value. And so now we're saying we have this version of switch that's not just do something based upon a value, but it's compute something based on a value. It's, it's that simple distinction that I think is really nice to have in the language. Some languages likeF sharps,F sharps, it doesn't have a statements at all. And so they've had, they had they call it match instead of switch, but it's essentially the same thing. But that's because the language never had statements. Speaker 2: 30:17 C sharp was a statement based language. We do semi-colons and we talk about doing things and so that's why uh, it's taken us a little time to get this one and yes, I've been waiting for this forever. The syntax is a little bit funny. It might take a little getting used to, especially if it's the first time that you've seen it. But once you've gotten used to it, I I switch all haha switch. I switch all my code over to uh, to the style. I'm a big fan of it especially because the alternative in the past was uh, gross. If LCFF, LCFF, LCFF things or growth switch, brake switch, break case break case, you know, there was just so much syntax and this just decreases the amount of syntax. Speaker 1: 31:01 Yeah. And when you put it all on one line, it makes a lot of sense to look at it. You're like, this thing is this thing. And I think that's what's nice about it and that it works with just about anything. You can mix and match this with a property expressions. You can also use it with two poles, which is super cool. Um, so if you are passing a tubulin, um, or you know, their example is you pass in two strings, you can actually switch expression over that as a two pole and then compare what first and second are. And that immediately reduces so much if statements or anything that you would have to do previously. So it's really, really nice. Uh, they literally write a rock paper, scissors game in for like, what is this one, two, three, four, five, six, seven lines of code. You know what I mean? And, and it's really nice just to really see how distinct and how straightforward reading the code can be. Speaker 2: 32:02 Yeah. I especially liked the, um, property expressions where you can say, here's an object. I have switch over it and you want to say, uh, if the, uh, whatever, if the name is this, do that. If the name is that through the other thing, and you can write that in very, very cute little syntax. You think curly braces that emulate like kind of a blank object. Then you list just that property names lead to say curly name equals Frank and then it all only um, it'll return whatever. It'll take that code path for Frank's. I like that syntax. I didn't do a good job of explaining it there, but I hope everyone will go look at specifically the property matching expressions that you can do. Speaker 1: 32:43 Yeah, so, so the, the really clear example of this is you have a person and they have a first and last name property, so two strings. So the exact thing that Frank is saying is what you would do is you would pass a method, basically a person and then you would switch over the person. But what you're able to do is say, first name is this, then do this. Or even last name or first name and last name, do this. And you can, you're not, you're looking at the property inside of the object, which is kind of bananas to do. And you can mix and match based on any of the properties that are inside of it. Super Speaker 2: 33:24 cool. Yeah, it's the mixing and the matching is where it becomes powerful because you could say, well it's the same as saying if food.name equals Frank. Okay, that's not much. But what if you have 12 different names or you're accessing different properties under different scenarios. What if their name is James and they're older than 64? Well that's a more complicated scenario so it can handle those better. That's why it's hard to come up with a trivial cases cause this is kind of a power feature in a lot of ways. Speaker 1: 33:51 Yeah. Yeah. It's a, it's a good one. I recommend spending a little bit of time looking at the pattern matching enhancements because it's pretty nice. Uh, and yeah, I swear every time I come into the documentation I just pick out one and I'm like, I'm going to use this today. And I'm like, this thing's amazing. It's so good. So cool. Speaker 2: 34:11 Uh, can I do a favorite? You ready for another one? Oh gosh. Yeah. I don't know if it's big or small or performance, but go for it. It's not performance. This is pure feature, feature, feature, feature, indices and ranges. James, this one's going to take a little bit of explaining, but the idea is instead of just being able to pull one element out of an IRA or a list or whatever, a collection, you should be able to pull out multiple things in the same way that we do substring on strings. You should be able to easily do that with our collections. Now, we've always been able to do this with link. We could date, see it, say M. dot. Skip dot take and those were like clever ways to get sub ranges out of lists, but now we have full on syntax for supporting, well, let's go with indices. First. A into C is just like what you would think. It's, it's the numerical index, so zero through and minus one for an array, but you can use the dot. Dot syntax tax. Say maybe I want elements zero through four or maybe I'm crazy. I want elements three through six. You can say three dot. Dot six kind of crazy Speaker 1: 35:29 use this one. Ah, so this looks like something I've seen or is it like a Python [inaudible] maybe? Yes, Speaker 2: 35:38 yes. This is exactly from Python and this comes up quite a lot when you're doing a higher dimensional math. Specifically in the machine learning realm, we have these objects called tensors and they're just multidimensional matrices. Nothing complicated, just a big bucket of numbers but with many dimensions. And so you're always pulling bits and pieces out of it because it's so big and that's where this ranging is very useful. Speaker 1: 36:06 So this to me is useful. If I am a good at use case for this that I can see is I have a file name and I need to take, you know, the first thing or the last like P and G off the end of it. And I know I could do the, you know, I could do the file path, I could do this, but I'm like, Oh maybe I just want to get the, the last three things off of it and maybe I'm going to parse that off of it. So I'm assuming if I have a string I can be like give me the last three characters of that string. Speaker 2: 36:38 Yes. And this is where a very powerful part comes in. Now Python has funny syntax. So if you have an array and you access the negative first element, so you say blah blah blah, bracket negative one bracket in C sharp, we would say that's a index out of range exception. Throw an error. Someone has some bug in their code. But yeah, but some people found that conceptualizing an array not as a fixed, uh, well it's still fixed but they wanted to be able to um, wrap around. So if you go off the end of the list, then you wrap around to the other end. So that means if I go off the beginning, I would wrap around to the end. If I go off the end, I wrap around to the beginning. You could almost think of it as using modular arithmetic given the base of the length of the array. Speaker 2: 37:34 Okay. The was a lot of words, but it all comes down to your ability to say Fu negative one. And that is actually actually accessing the last element of the array. Now we knew in C sharp that would confuse everyone because forever negative numbers are not allowed as indices. So we have a funny new character, they added a whole new bit of syntax to the language just to support this. And it's the carrot operator, the hat. So you put a little hat in front of the one and you conceptualize that as negative one and he just rolled off the end of the cliff. And you're allowed to do that in C sharp. Now, so I don't know if you've ever done this, but you had an array and you wanted the last element and for some reason you don't remember to use Lincoln dot last you could say like array bracket, array dot length minus one bracket. Speaker 2: 38:26 Yeah. Do you ever do that? I do it all the time. All the time. All the time. So now you can replace that with array bracket. Carrot one, think of it as negative one but rapping bracket. And that's the last element of the array. And that's advanced indexing new to us. It's a little weird. That one. It's a little weird, but, uh, there are definitely doing this to support. I don't know, man. I, I get used to this. I, I very much enjoy the negative, uh, negative indexing to be thoroughly honest. I've been doing a lot of Python lately, so I'm quite kind of used to it, but it's, I think it is semi specialized to these math libraries where it's especially useful. Speaker 1: 39:10 Yeah. This, this seems like a mathy type feature to be honest with you. Yeah. And it, it seems cool in general. I needed to wrap my head around it because they do have a really good breakdown of exactly. Yeah. There you go. Wrap. So how it wraps around. Yeah. It's a peculiar, uh, that's uh, I'm gonna yeah, try it. Meditate on it. Yeah. Well what I'll start using immediately, we're not going to go through every single feature, but at least one or two more here. We mentioned in the beginning, which is no coalescing assignment. This one is straight forward and simple is a delighter. This is the one I just found out about it today as we're recording. In my code all the time, Frank. I have getters and those getters will do something like you could say, if you know person equals equals Nall then person equals new person. Right? Oh, D kind of like delayed initializing Speaker 2: 40:08 sation like a lazy, but you didn't want to use lazy. Speaker 1: 40:11 Yeah, correct. Yeah. So you might do this there. Now the other places I do it is when, um, I'm creating like a view model or something or maybe I'm lazy. [inaudible] getting, yeah, the lazy. It's a good, good way of doing your laser Lee. Um, creating, um, a pro public property getter. So for instance, uh, I might have an HTTP client that's private, but I might have a public one and [inaudible] not even a public one, but I might just have a getter, right? Which is capital HTTP clients that have lowercase HTTP client. And then what I'll do there is I'll say, you know what, lazy Lee create this thing on the fly for me. So I'll say, client question Mark, question Mark. And then in brackets I'll do client equals new HTTP client. And it's actually pretty verbose because you're doing question Mark, question Mark. And that's new even right, the double question Mark. And if it's normal then assign it. So next time when I get it, return it. Well there's a new syntax, Frank and that I'm in love with. It's amazing. All you gotta do is say client equals or question Mark. Question Mark equals new HTTP client done and baffled everyone on your team. Yes, it's easy. So what? That's what that's is. Speaker 2: 41:34 If client is no, then create a new client and assign it. If it's not, no, don't do a thing. So it's kind of like if I already have an object, ignore the rest of what I'm saying here, but if I don't have an object, then you got to do all this stuff. I think it's a little bit weird, but at the same time I know I'm going to use the heck out of this. And so I'm already like kind of apologizing to everyone that I confused with it. But I think, no, I think it's, I think it's elegant and I think it makes a 100% sense. I don't think it's confusing at all. Like I saw it and I go, yes, I get it. I'm in 100% done. Yeah. I'm trying to think of scenarios where I do this. I guess for me it's more like default parameters to methods perhaps. Speaker 2: 42:19 Like I want to have a method parameterize but I know a good default and I don't want to force myself to have to come up with it every time. So I'll, I'll allow know as one of the parameters. I'll check the parameter. If it's normal then I'll do a thing. So this would definitely clean up. Yeah, default parameters. Yeah. I think anytime that you have a null check and then assign, like anytime that you check for Nall and it is normal and you assign that thing a new property, you use this thing instead. Yeah. Yeah. As long as you're not doing anything else in that. Yeah. If, yep. Perfect. Do it a lot. I mean, we're removing a, I'm seeing a theme here, we're removing curly braces and I approve of this. Yeah. Get rid of them. Get rid of them. Well when you don't need them, you can get rid of them. Speaker 2: 43:07 So, but when you needed them, you would, you would use them. So now you don't need them. Yes. Very good. Very well said. When we're speaking of null, should we, should we mention the big one? We did pretty much a whole episode on Nobel references, but maybe we should, uh, give a shout out to them. Once again, uh, I'm a huge fan as far as I understand it. You hate them and you will never used them. Am I getting that accurate? Am I right donor? No. Novel reference sites I'm in for it. Just, I don't, I haven't done, I haven't done it yet, Frank. So it's, it's unknown and it's something that when you, when you read the documentation, they're like, go read this other document that will describe it to you. So it's, it's that involved that it, it can't be summarized in the, what's new in C sharp eight, which means that there's going to take me a little bit of time. Speaker 2: 44:02 Ah, I have a blog post. Lots of people had blog posts. A lot of us are very excited for this. It's found bugs in my code and for that I'm just forever hap happy. And I complained on the last step or not the last but a few episodes ago that I haven't had a crashing NOL reference exception and one of my apps and that just killed my soul. So I'm just going through all my code and enabling C sharp eight snowball reference, uh, tracking. It's a pain you need to set aside a day for it, but Speaker 1: 44:32 it's worth it. Yeah, that's what I think it is. And I need to go into a very small library, maybe my MVVM helpers and then just do that. [inaudible] Speaker 2: 44:45 that's absolutely how I did it. Um, I started with my smallest library and converted it over and that's nice cause you wanna assume that that library is bug free. So everything should go through just fine. It found bugs. So even in the small library, Speaker 1: 44:59 maybe I'll do that on my stream next Friday. So this Friday coming up, if you're listening to this on the fourth, which would be when this episode comes out. So on November 8th, if you have, have you gotten this far? You should head to my Twitch stream or I'll be on my YouTube later, but I think I'll just do it. I've been looking, I might join in for that one. I'll hang out in the chat. Yeah, yeah. I'll ping you. I'll make sure you know, because I think it'll be very brand new to me. And that one's straight forward cause it's just a done at standard 2.0 library. Nothing special and just do it. Yeah, Speaker 2: 45:31 that sounds very doable. Reasonable. What's left James? Well, we're not going to go through everything, but let's say there's a few more, um, weird kind of performance ones and I'm calling them weird. So you know, they're really weird. Yeah. So yeah, so you can, um, uh, you can half initialize objects. Don't do it, but you can now you can stack, allocate a res more with less syntax now, but don't do that. Don't, don't stack out. Okay. Your res. Uh, what else? What else? What am I missing? Um, Speaker 1: 46:06 my favorite is the a, you can use the question Mark and, and, and, and, and sign or, and sign and question Mark. Like either way they're like, that's fine. We figured it out. Which feature was that with a question Mark? It's inter interpolated strings. So it's interpreted verbatim strings. So for instance, you, this is important when you have like wax in your, in your code line multiline. I do it a lot with multiline. Yes. Uh, you need to put an at sign like an, you know, at like an email app and in front of it. So, so that's going to tell those are verbatim string. But the problem was that that before you always had to put the question Mark before the ad sign. Now you can put it after. Speaker 2: 46:52 It's not the question Mark. That's what I was getting confused. It's the dollar sign. James [inaudible] dollar sign. Dollar sign. Yes. Okay. Yes. Yeah. For real. Like which one goes first? I don't know. And neither could the language designers obviously remember. So they're like both, which are wildly dead. Yeah. How have you like our language now? That's right. Um, asynchronous streams, they did it, you can go, I async enumerable it up, go figure it out, watch the videos, we should talk about it. But at the same time we talked about it before and I'm like, I don't have much use for these things, but man, they're getting promoted a lot. I just don't have much use for them. Speaker 1: 47:29 I think if you're doing backer, if you're doing streaming things, obviously that makes a lot of sense. So the time we demoed as always with like GRPC type of stuff like that and that has it built in, but I dunno maybe like web sockets or HTP to something along those lines. Yeah. Yes. So I'm not there yet. It's too, it's, it's, it's already in the future and I'm not ready for that one yet. So that one I'm just going to have to have like an epiphany before I realize how I can effectively use it. Cause right now it's just a feature sitting out there that I don't know, don't know whether I want to take advantage of or probably like half the things I mentioned on this podcast. People are like, do I care? Yeah. I don't know. You should, you should care about everything. Speaker 1: 48:13 All right Frank, let's wrap it up. Favorite feature, go a Nalco references. I'm sorry. Of course. End of no and let's end it. Let's erase it from history. Be gone. I'm, I'm into more pattern matching because as a C sharp developer, I haven't had enough pattern matching in my life and I didn't appreciate the pattern matching until I had the pattern matching. So more pattern matching is what I'm into. So that's my, you know that that is statement like a pattern matching from C sharp seven. I use that everywhere I with that. Yeah. So good. Yeah. More of that. It's coming more of it. All right. We did it. 50 minutes of C sharp eight Frank. Yes sir. Uh, so that means next week's episode of C sharp nine. Can't wait for the previous season. I'm ready. Bring it on. All right buddy. We'll have a great week. And to all of our listeners, you also have a great week to, uh, if you're adding night, I'm adding nights. So you should probably come say hi adding night in Orlando, Florida. Be polite. Yeah. Awesome stickers. You know, that's it. So cool. Alright, thanks Frank. Uh, for talking to C sharp Bay with me, and thanks for everyone for listening in itself. That's going to do it for this week's pod. So until next time, I'm Jane's mountain mag now, and I'm Frank Krueger. Thanks for listening. Peace.