Thanks for the heads up about mapping! First use case I thought of when watching this but I did think it was a bad code smell. Thank you! Very informative.
I am still not understanding or able to come to an agreement (lack of some explanations) about why Mappers are still considerable than this, for use cases like ViewModel to DataModel conversions, One Db to other Db model conversions etc? Especially when Mapper tools like AutoMapper uses reflection which may be costlier than simply casting it. I dont know about Mapsters behind the scene mapping approach, looking forward for your thoughts/feedback to this?
The main issue with implicit and explicit casting operators is that you usually end up with a different reference in memory. when you have an instance of Milk that derives from Liquid and it's in a IEnumerable then you can test-cast the object to Milk and change its properties and the object in the list will change because it is the same memory reference. When Milk does not derive from Liquid but you have cast operators for them then adding Milk to a List will not actually add the Milk instance you have in your variable. Any further change to the object will not be mirrored in the Liquid object in the list.
Good point. The feature seems very convenient but I would be very uneasy to use it because of problems like these. I think you're masking behavior that might cause dangerous inconsistencies. On top of that they'd be pretty hard to debug. Maybe if you use it responsibly with value types only like the first example in the video that might be fine. But still one should be very careful when making such a decision. I do appreciate the video though!
What is your opinion on having an implicit conversion between a class and a builder of that class? For example, string and StringBuilder. When I have something like that, I always have an implicit conversion from the builder to the class, but string and StringBuilder don't have this and so I wonder if there is a reason for not having it?
Very interesting stuff. Though I would feel a bit wary about using lots of implicit conversions all over the place -- could easily get confusing for other people in the codebase. Though maybe I'm off-base?
You are correct. Implicit/explicit operators have value when the conversion is obvious, like I showed on the first example. If the conversion isn't obvious then don't use them.
@@nickchapsas Speaking of examples of poor implicit operator implementation in one of codebases i have worked with there is a struct "Currency" (a decimal value and a string currency symbol primitive wrapper) that defines Currency(decimal) implicit operator. Guess what? It returns the amount as my national currency and you could say that it is reasonable after all. Unless somebody tries to do var currency = new Currency(10m,"EUR"); currency += 10. You would expect it to be 20 Euro but instead you get an exception that you can't add two different currencies. I can't even count how many times i've seen this mistake.
I would get the JetBrains Toolbox from www.jetbrains.com/toolbox-app/ . On windows, it will be an icon on the lower right side of the task bar Once you have toolbox, you can install Rider from the interface easily, and keep it up to date from there as well!
I agree that its not the objects responsibility to do mappings, but are there any performance benefits over using something like automapper or mapster? just trying to understand why people would use it for mapping other than ease of use
There aren't any performance benefits over mapster (codegen) since a static call and an instance call should have the same performance. Ease of use is why people tend to use it which is the pitfall IMO.
Nope, unless you wrap it with a class/struct with certain interface (like INumericOperation) and use implicit operators. I wouldn't do it, and to make it work 100% it would need type checking and conversions probably. Just a thought of top of my head though. Oh and you can't obviously implicitly convert to an interface so you have to return concrete type but that's not a big issue.
> many devs don't know about implicit/explicit type conversion operators > don't use them as they're confusing as soon as it's not good from a practical perspective it's quite useless knowledge, similar to goto and many other niche stuff...
It is good from a practical perspective, it's just that you need critical thinking to understand of if it's a good idea to add one or not. Value objects are the perfect candidate for them and it's 99% of the usage I'm making for this feature.
Thanks to ABP for sponsoring this video. Check it out here: bit.ly/3f26Mlf
Hey Nick,
thanks for your awesome video!
Can you make a video series about abp.io framework ? This would be awesome :)
@@Ehomer0815 Yeah I would really like to see that!
ABP is pretty awesome
Thanks for the heads up about mapping! First use case I thought of when watching this but I did think it was a bad code smell. Thank you! Very informative.
Same here xD
I am still not understanding or able to come to an agreement (lack of some explanations) about why Mappers are still considerable than this, for use cases like ViewModel to DataModel conversions, One Db to other Db model conversions etc? Especially when Mapper tools like AutoMapper uses reflection which may be costlier than simply casting it. I dont know about Mapsters behind the scene mapping approach, looking forward for your thoughts/feedback to this?
“Completely random number” 😂
int rand () { return 420; }
well explained as always with only the necassary info while including enough to make it make sense.
ty. I needed some other explanation after reeding Rihter.
this really helped explain the concept to me, thanks for the education!
Thank you for the video Nick. I learn something new everyday from you!
Damn that makes so much sense. Nice explaination and demo
4:50, im starting to have doubts that nicks random number generator is biased
So what would be a useful and appropriate use case for these operators?
i liked before watching the video, keep coding, Thanks.
Amazing lessons. Thank you!
It would be helpful to link value object videos as well (mentioned really in this video).
The main issue with implicit and explicit casting operators is that you usually end up with a different reference in memory.
when you have an instance of Milk that derives from Liquid and it's in a IEnumerable then you can test-cast the object to Milk and change its properties and the object in the list will change because it is the same memory reference.
When Milk does not derive from Liquid but you have cast operators for them then adding Milk to a List will not actually add the Milk instance you have in your variable. Any further change to the object will not be mirrored in the Liquid object in the list.
Good point. The feature seems very convenient but I would be very uneasy to use it because of problems like these. I think you're masking behavior that might cause dangerous inconsistencies. On top of that they'd be pretty hard to debug.
Maybe if you use it responsibly with value types only like the first example in the video that might be fine. But still one should be very careful when making such a decision.
I do appreciate the video though!
What is your opinion on having an implicit conversion between a class and a builder of that class?
For example, string and StringBuilder. When I have something like that, I always have an implicit conversion from the builder to the class, but string and StringBuilder don't have this and so I wonder if there is a reason for not having it?
Very interesting stuff. Though I would feel a bit wary about using lots of implicit conversions all over the place -- could easily get confusing for other people in the codebase. Though maybe I'm off-base?
You are correct. Implicit/explicit operators have value when the conversion is obvious, like I showed on the first example. If the conversion isn't obvious then don't use them.
@@nickchapsas Speaking of examples of poor implicit operator implementation in one of codebases i have worked with there is a struct "Currency" (a decimal value and a string currency symbol primitive wrapper) that defines Currency(decimal) implicit operator.
Guess what? It returns the amount as my national currency and you could say that it is reasonable after all.
Unless somebody tries to do var currency = new Currency(10m,"EUR"); currency += 10. You would expect it to be 20 Euro but instead you get an exception that you can't add two different currencies. I can't even count how many times i've seen this mistake.
Wow! Very nice! Thanks for the content =]
how do you get variables visible in main window 6:34 ? Is it possible in visual studio 22?
Perfect! Could you do a video on Rider and how to install and use analyzers? Many thanks!!
I would get the JetBrains Toolbox from www.jetbrains.com/toolbox-app/ . On windows, it will be an icon on the lower right side of the task bar Once you have toolbox, you can install Rider from the interface easily, and keep it up to date from there as well!
Really cool.
what is the previous video called that explains what a guid is? :) thanks in advance to anyone who could tell me
1:35 - "you can check that video if you want"
what video? there's no link to the video
I agree that its not the objects responsibility to do mappings, but are there any performance benefits over using something like automapper or mapster? just trying to understand why people would use it for mapping other than ease of use
There aren't any performance benefits over mapster (codegen) since a static call and an instance call should have the same performance. Ease of use is why people tend to use it which is the pitfall IMO.
Can I use it for converting the video clip to the URL of the web page?
I think this is useful but in context of use case when domain entity convert to dto , I think we are crossing layer and this is not good.
There is sooo many stuff in remember in c#
Fresh haircut
also interesting video
When you try to be professional but your inner meme lord comes out 4:45
I wonder if I can finally make a function take a generic "numeric" type using this.
Nope, unless you wrap it with a class/struct with certain interface (like INumericOperation) and use implicit operators. I wouldn't do it, and to make it work 100% it would need type checking and conversions probably. Just a thought of top of my head though. Oh and you can't obviously implicitly convert to an interface so you have to return concrete type but that's not a big issue.
Nice explanations but how you presented the code / jumping
was a bit chaotic for me.
👍🏽
Random number, 420 dude. Just waiting for 69 for the memes 😆
7:40
@@macurvello I didn’t watch the whole video... would have been better if I had 😂
> many devs don't know about implicit/explicit type conversion operators
> don't use them as they're confusing
as soon as it's not good from a practical perspective it's quite useless knowledge, similar to goto and many other niche stuff...
It is good from a practical perspective, it's just that you need critical thinking to understand of if it's a good idea to add one or not. Value objects are the perfect candidate for them and it's 99% of the usage I'm making for this feature.