Комментарии:
So Automapper is still slow... But another specific library that is a lot less popular is slower.
Ответитьthe great news is: you don't need mappers. Don't bother.
Same goes for things like MediatR.
Don't complicate your life.
Long story short, if you wouldn't name your method parameter 'x' than maybe don't do that in lambdas either? After all not rarely they are extracted to methods.
ОтветитьAll true about Automatter and listening to random blokes on the interner. On the other han I don't get why some devs, apparently yourself included, pretend good practices for params naming simply DONT APPLY TO LAMBDAS and they use some arbitrary 'xyz' instead. It really takes only a bit more brain work to figure the first letter, so do that at least. Oh, unless you're just copy pasting your stuff all over the place... In that case good variable names are against you, indeed...
It's all fine when you're having a 5 lines example on YT, but in real life this single lambda is soon becoming one of several, and later will have a nested friend.... If at this point you simply add 'y' and 'z' instead of renaming it to something meaningful it's a lost case. If your nested type has 'type' and 'topic', also don't use 't' so the next person won't need to wonder which one is it and have to read the whole preceeding code. If the line ends up too long, that big key on the keyboard does the job.
Personally I'm not a fan of the single letter lambda variables. Even in simple lambda expressions I still prefer to have a more clear variable name.
After all, if I were to write the LINQ statement in full (from student in context.Students ...), EF style, I'd also use the full 'student' variable name rather than 's'. Especially throwing in some joins and whatnot.
Though, in code reviews/PR's I accept it when people just drop 'x' everywhere on lambda's. Seems to be a common thing.
I consider that to be a preference type of thing really, not a sign of bad code.
When I do NOT accept it however, is in cases where it is indeed not obvious.
Like more complex LINQ statements that change context halfway through (you start with students, then select their grades, then continue the lambda's with grades ... but still keep 'x' everywhere).
Or like shown in the video, in predefined delegate signatures that aren't exactly obvious at first glance (even though you can 'hover' over the variable to figure out the type in the IDE).
Nick you need a police cap to wear while making this series.
ОтветитьAgree about expressions/delegates syntax, but I usually use 'e' as shortcut (entity), but when you have inner closures (lambda inside lambda) I am already trying to give some names which make sense (as you would have it overlapped by parameter name, and at some cases you don't want that).
Ответитьwe are removing every usage of automapper in our project
ОтветитьI prefer manual mapping just because it gives me more control and, to be honest, it's faster to understand something. It's clearer, no magic, no shenanigans.
No issues with Automapper, I just prefer not to, it doesn't really make sense to me, specially with records and required properties now.
Regarding AutoMapper, the creator himself has said that it was only intended to be used for simple cases, and that people often use it in complex scenarios where it shouldn't be.
The guidance, therefore, might be to only use AutoMapper when your mappings are so simple that you don't need AutoMapper.
If I have a Species object, what do I call a list of these if I can't say speciesList? Now we have a naming exception and inconsistency in the application code.
Postpending List, Collection, etc. should therefore be the preferred method.
student1 =>
Ответитьim also the x => x guy
ОтветитьI never understood the hype about these automapper-like tools. Why not have a static method that converts object a into object b instead, or having these transformations as methods of the service itself? Unless the class are identical entities to dto you'll end up writing custom code anyway, and the mapper function will be usually in a far file far away from where the transformation is actually made.
ОтветитьI will start using Automapper more now. We will not submit to this terror of the psychic 😭
ОтветитьThat middleware looks suspicious. It looks like it will call take request's URL, do another request to that URL and thus keep looping. I'll need to check it when I have time.
ОтветитьThe version of Automapper shown in the benchmark (v4.0.4) was released in 2015. Version 4 advertises it's support for SIlverlight and Windows Phone 8 🤣
ОтветитьGood 101 advice.
ОтветитьGood advice. Thank you Nick
ОтветитьI really really really hate videos and advice like "Dont use, STOP use, quit you career if you use this and that" ffs it was added to the language for a reason no ? Do you know my situation ? Do you know that I have a reason to use the thing you are telling me not to use it ? No. So I will probably use it. I find these videos super aggressive and makes me thing I am doing something terribly wrong and elevates my imposter syndrome. It should be more like "I found something better to use than this and that, try it" ... Nick thanks, please continue debunking these stupid videos
ОтветитьI like this series, most of linkined advice are generated by India users, they want to develop their linkined profile. but instead of bring good advice, they do like a bot, might be this is result of using chatgpt instead of thinking
ОтветитьMean 👍
ОтветитьI agree with single character in Linq variable and my preference is always use the first letter of alphabet `a`, so not to overthink it. :D. Modern IDE can also show the type easily by just hovering your mouse at the variable.
ОтветитьWith the naming of objects students.Where(s => s .... );
I use underscores, Is it a bad approach? eg students.Where(_ => _.HasStartedSchooling);
Too fast speaking
ОтветитьWhat about cqrs? I see new templates including this thing call mediatr.
ОтветитьKeep it up. It was a great post and I'm waiting to watch his kind of videos again!
ОтветитьGood video! I'm a fan of these style.
If you are one of these people:
I don't care if you think being a guru looks good to employers, stop sharing your crap advice you don't understand, it's doing more harm than good.
This reminds me of Sabine Hossenfelder's advice about statistics in science: "Never trust a statistic without a confidence interval, especially in psychology."
ОтветитьOh hell yeah! You go Nick! 😂
Ответитьclick bait 🤣
Ответить💯
ОтветитьGood points! I will say I prefer the LINQ lambda variable short-hand for more compact code (i.e. `students.Where(s => s ...)`). However, I take it one OCD step further with the use of `x` as my lambda only when I'm dealing with a projection of something (i.e. an EF `.Join()`) or the list name actually begins with the letter `x` (i.e. `var xrays = new List<Xray>();`)... and if I'm doing multiple projections, I'll start using `x0`, `x1`... Good stuff man! Keep it up.
ОтветитьHonestly I like led Zeppelin's version of Ramble On better.
Or maybe I'm just annoyed by the clickbait title of the video. Change it to something else.
Wow. I need to pay better attention to what people are posting on LinkedIn so I can take them to school. That middleware screenshot made my eye twitch.
ОтветитьMy advice: do your mapper.
ОтветитьIt's interesting how much "advice" we can get on linkedin, yet so little is actually useful :) About naming, one-letter names are not neccessarily bad in my oppinion - if the reader is expected to understand them! If you are implementing an algorithm from a mathematics paper, for instance, then it would probably be very confusing for the reader if the symbols had totally different names in the code. If you are doing statistics calculations then "p" should be a perfectly valid name for a variable, or if you are doing linear algebra, then "i", "j" and "k" are common when denoting matrix multiplication etc. So at least in a context where short names already have a conventional meaning it should be ok, or even preferred I think!
ОтветитьBack when I was younger and much stupider, using automapper was a hill I was ready to die on. Jesus christ... 😂 Just implement a handmade method.
ОтветитьI know it is bad idea but can you make a video about using other programming languages in .NET (python etc.)
ОтветитьGood video, thanks!
ОтветитьStop using mappers. FTFY
ОтветитьFirst you blame an author of the article that he didn't show any code that he measured to get his results, then you show your benchmarks showing that automapper is faster than tiny mapper also without any proofs with code. So basically you repeat the article author's error. Good job 👍
ОтветитьPutting "Stop Using Automapper in .NET" in the name of the video is clickbait, please don't do this, your videos are too good to have clickbait naming
ОтветитьBefore writing to response in middelware or execute next middelware in the pioeline you must check if response is not started to be written. There is a boolean for that - read do about middelware.
Ответить<insert thank you.gif here>
I totally agree with the student naming. It is stating the obvious twice. Unfortunately, its on our code naming standard (sigh)