Random tip: You can exchange value between 2 variables without setting one of the values aside by doing this int a = 2; int b = 4; (b, a) = (a, b); a will then be 4 and b 2 Instead of int a = 2; int b = 4; int c = a; a = b; b = c;
Btw I learned to program, thanks to your videos. On the past they used to be a boring 2 hrs videos, but little by little I noticed that the way you explain things are unique and very useful. Thank Mr Cory for you dedication on this
I think it was not a complement. And I agree with that. JS is the king of bad patterns, lazy written features (undefined this, inheritance etc) and bad written code. Is that because JS is most used by students, freelancers who don't have team or someone with development knowladge or just people who just started programming. Later those bad patterns starts to spread and became somthing normal across JS community.
1.Thank you for the video. 2. I get feeling that c# is becaming over complicated. Like c++. The feature shown in the video is not very useful at least maybe for someone who like to use anonymous types and to write code that is hard to read and maintenance. I like KISS principle and in my opinion Microsoft is going in bad direction.
I'm not sure how this makes things harder, though. You don't have to use this if you don't want. However, returning Tuples from methods is a pretty common thing to do when you don't need a full class (and the added complexity) to return multiple values. Tuples actually reduce complexity. So now being able to declare our Tuple to return in a way that makes better sense for the situation actually makes our code simpler as well. For instance, let's say you have a method called ValidateAddress that takes in a streetAddress property. We could pass in an address like "123 sesame st". The goal of the method would be to properly format the street address and then let the user know if it is a valid street address. You could do the following: 1) Update the streetAddress variable to be capitalized and change "st" to "Street" 2) Look up the formatted address to see if there is a match in the database. 3) Output data = (validatedStreetAddress, bool isValid) output = (streetAddress, true); You just made your return simpler (no "out" variables and you mixed the inline declaration with the existing value). You don't have to use this but as you can see, in this scenario, the new changes actually conform to KISS.
@@IAmTimCorey As a long-time Java developer, I agree that multi-value results from methods are quite common and their handling can be a pain in the a** in Java - therefore I really appreciate the tuple feature in C#. And I also have programmed in Haskell for a number of years during the 90s, where tuples and decomposition/pattern-matching is used all the time, and considered clean and good practice.
Can you deconstruct just a part? So in a tuple with 3 keys, get only 2? Can you deconstruct directly to method params? I'll take a look after but those are my questions after viewing the vídeo.
I haven't shortened my videos. This is a new series with a different focus. Monday videos will still be the long format, which is best for learning a topic fully. This series is about having a quick reference to a specific thing.
Tried this recently in a unit test, where (in a SetUp method) I called some helper method that returned a tuple, and where I wanted one of the tuple components to go into a field (part of the test fixture), whereas I wanted the other component to be stored in a fresh variable to be used only within the SetUp method. There are a couple of more minor language features that may not be widely used in production code, but can come quite handy within tests. This may be one of those.
Don't really care about the deconstruction but more of using ternary operator when returning tuples inside of classes which I believe is available in the new release
I dont know so much about deconstructors, but this is not the same as a class deconstructor right? I always thought a deconstructor is to dispose? Or is that still something different from a destructor? Im confused! :D
A deconstructor isn't the same as disposable. A deconstructor breaks down an object into its parts. A dispose is used to properly close down any open resources before an object is destroyed.
@@IAmTimCorey Hey Tim, thanks for your answer. I have one more question if you don't mind, but, a deconstructor is not the same as a destructor? As far as I understand these are still 2 different things. I have not used any of this ever (yet), but it is def. some interesting stuff. Have a nice day!
IMO, not great. Abbreviated syntax does not always make the code more readable. Great Video Tim! I would know know what to think about this if not for you showing it to me so well. Please keep doing what you do for us!
This is great but it would have been better if instead of parenthesis there was a bracket so Javascript objects could simply be plugged. Imagine being able to deconstruct a Javascript object expression in the fly.
Another random tip: You can use var in the deconstructor as well, like so: var person = (fn:"Tim", ln:"Corey"); (var fn, var ln) = person; If you _should_ do so is another story :)
@@IAmTimCorey yes! Solidity has a very similar syntax as what you showed with Tuple in C# Tim, thank you for putting out such a great content. I have been watching you for more than 2 years now and your tutorials helped me personally a lot and also, helped me during in-office training sessions with my devs.
That deconstruction syntax is super non-intuitive. Another dubious feature from the school of "reducing the amount of text". Great job, less text that's even less clear in intent.
IMO - What's wrong with explicitly doing it for each element you care about? This syntax is yet more cryptic syntax that's in no way intuitive. I see code like this all the time where devs are excited to use some new syntax, at the cost of code readability. Every second I have to spend "ok, this is ACTUALLY doing XYZ" because someone thinks that 1 line of code is always inherently better than 2 or 3 lines of code is wasted time.
When can we hear you thoughts over the debacle of removing hot reload from dotnet watch , or the possibility of removing dotnet watch entirely from the SDK to keep it behind a VS license ?
I'm waiting for an upcoming announcement before I do a video on the situation. Right now, it isn't good, but there is hope that this will be reversed. Remember that the .NET team is not behind this. This is a management decision that they don't like either. I'll definitely be doing a video on it soon, though, even if we don't hear from Microsoft.
With a title mentioning "Deconstructor" I immediately thought; doesn't C# call that a finalizer? Also, as your example is using string, it actually makes no difference that you can re associate to an existing variable. Strings are immutable, so the assignment would create a new instance anyway.
That isn't the point. The point is that we don't need to have a new variable name. Sure, behind the scenes there is a new string created either way but now we don't have a new variable and assignment just to properly fill the tuple.
@Roel I think what you mean is called a "destructor", not "de-con-structor". C# offers special syntax for the object finalizer (a .NET feature), the same "~CLASSNAME()" syntax as in C++. This is completely unrelated to the feature presented here.