"Stop Using Automapper in .NET!" - Code Cop #001

"Stop Using Automapper in .NET!" - Code Cop #001

Nick Chapsas

9 месяцев назад

108,295 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@QuickZ_
@QuickZ_ - 01.02.2024 18:15

So Automapper is still slow... But another specific library that is a lot less popular is slower.

Ответить
@scosminv
@scosminv - 03.01.2024 00:33

the great news is: you don't need mappers. Don't bother.
Same goes for things like MediatR.
Don't complicate your life.

Ответить
@kocot.
@kocot. - 12.12.2023 16:07

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.

Ответить
@kocot.
@kocot. - 12.12.2023 16:06

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.

Ответить
@ThekillingGoku
@ThekillingGoku - 12.11.2023 04:13

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).

Ответить
@sealsharp
@sealsharp - 30.10.2023 00:18

Nick you need a police cap to wear while making this series.

Ответить
@TheXX113
@TheXX113 - 28.10.2023 00:44

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).

Ответить
@tonebanderas
@tonebanderas - 19.10.2023 02:47

we are removing every usage of automapper in our project

Ответить
@mwzndev
@mwzndev - 18.10.2023 23:40

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.

Ответить
@WilliamCWayne
@WilliamCWayne - 12.10.2023 20:59

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.

Ответить
@WilliamCWayne
@WilliamCWayne - 12.10.2023 20:57

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.

Ответить
@MarcioLaubstein
@MarcioLaubstein - 07.10.2023 04:11

student1 =>

Ответить
@FireDragon91245
@FireDragon91245 - 06.10.2023 22:26

im also the x => x guy

Ответить
@MT-qz7ne
@MT-qz7ne - 03.10.2023 22:34

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.

Ответить
@oathkeepersapphirelands
@oathkeepersapphirelands - 30.09.2023 12:05

I will start using Automapper more now. We will not submit to this terror of the psychic 😭

Ответить
@BlazingMagpie
@BlazingMagpie - 29.09.2023 14:10

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.

Ответить
@CalebBertsch
@CalebBertsch - 28.09.2023 04:55

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 🤣

Ответить
@Gioandgoose
@Gioandgoose - 25.09.2023 10:01

Good 101 advice.

Ответить
@mrsajjad30
@mrsajjad30 - 23.09.2023 07:37

Good advice. Thank you Nick

Ответить
@marh122
@marh122 - 22.09.2023 10:46

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

Ответить
@ericsnguyen4649
@ericsnguyen4649 - 22.09.2023 10:23

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

Ответить
@M4pster
@M4pster - 22.09.2023 07:03

Mean 👍

Ответить
@PinoyDIY
@PinoyDIY - 22.09.2023 03:25

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.

Ответить
@princeowusu9854
@princeowusu9854 - 22.09.2023 01:31

With the naming of objects students.Where(s => s .... );
I use underscores, Is it a bad approach? eg students.Where(_ => _.HasStartedSchooling);

Ответить
@yl3707
@yl3707 - 21.09.2023 22:46

Too fast speaking

Ответить
@noswag5773
@noswag5773 - 21.09.2023 13:48

What about cqrs? I see new templates including this thing call mediatr.

Ответить
@saeedbaninosrat9293
@saeedbaninosrat9293 - 21.09.2023 11:44

Keep it up. It was a great post and I'm waiting to watch his kind of videos again!

Ответить
@FroboDaggins
@FroboDaggins - 20.09.2023 22:16

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.

Ответить
@jameshoiby2530
@jameshoiby2530 - 20.09.2023 21:30

This reminds me of Sabine Hossenfelder's advice about statistics in science: "Never trust a statistic without a confidence interval, especially in psychology."

Ответить
@Yupmoh
@Yupmoh - 20.09.2023 12:59

Oh hell yeah! You go Nick! 😂

Ответить
@Serotonindude
@Serotonindude - 20.09.2023 10:26

click bait 🤣

Ответить
@Null-byte
@Null-byte - 20.09.2023 06:45

💯

Ответить
@jacobphillips9235
@jacobphillips9235 - 20.09.2023 04:26

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.

Ответить
@MotoWilliams
@MotoWilliams - 19.09.2023 23:35

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.

Ответить
@AmateurSpecialist
@AmateurSpecialist - 19.09.2023 21:38

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.

Ответить
@MrFreddao
@MrFreddao - 19.09.2023 21:34

My advice: do your mapper.

Ответить
@lambda-snail
@lambda-snail - 19.09.2023 20:59

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!

Ответить
@mikaelfrosthage4375
@mikaelfrosthage4375 - 19.09.2023 18:21

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.

Ответить
@cagr2725
@cagr2725 - 19.09.2023 17:52

I know it is bad idea but can you make a video about using other programming languages in .NET (python etc.)

Ответить
@jannickbreunis
@jannickbreunis - 19.09.2023 16:29

Good video, thanks!

Ответить
@jonb8869
@jonb8869 - 19.09.2023 14:33

Stop using mappers. FTFY

Ответить
@distractednine_di
@distractednine_di - 19.09.2023 13:35

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 👍

Ответить
@MrN893
@MrN893 - 19.09.2023 13:02

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

Ответить
@psdmaniac
@psdmaniac - 19.09.2023 12:45

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.

Ответить
@NextProgrammer
@NextProgrammer - 19.09.2023 11:23

<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)

Ответить