Posts

Showing posts with the label c# performance

ach - why we do not put attention to what we are doing???...

Image
 Ach, humans don't want to be fast, they just CTRL+C and CTRL+V, shit over shit, but it is working so what do you want a...!!! see this snippet: Is there anything suspicious for you? NO??? Yesterday I was reading Aaron Stannard blog entry about DRY and above snippet just jumped at me from the corner of my screen.  DRY DRY DRY. Now: what's wrong with this one? It is not human friendly (formatting) It is not CPU friendly as there are two string interpolations instead of one we could introduce a helper variable to make it nicer to read (and this is a bit of WTF -  see below) So what we can do with this? Firstly use a single interpolation with a proper formatting like {date:MMM-yy} , this will do the job nicely and we don't need to decipher two statements to get the output when reading the code, now we also could format it a bit, so it is not spread on the wide screen edge to edge... So what do you think about this: Looks better? For me this is true, but is...

when a new guy joins a team...

Image
Not so long ago, I was browsing merged pull requests to check quality of the work that was done. I don't know why, but in 202X C# is rather a modern language and some language syntax shall be adjusted to newer standards. When I was starting my developer journey - I was told to always add a code that looks similar to the one that already is there, unless it is total crap and adding new stuff needs more effort today, to not to die tomorrow. But in this case, we have a project that is created in in 202X and there is a lot of good looking and working lines of code around, so anyone can follow it. First time, when I was a student and helped my colleague, I was in shock that the teacher recognized my help, I turned all red and asked him "how you were able to recognize that?". He said that most of us have a kind of style that identifies us as developers, so this is spacing, the way how we organize braces (even when autoformated), how we write and solve problems,  and finally var...

the code need to be secure, all need to be checked... sarcasm

Image
In my days I am sometimes wondering why we humanins are so hateful to computers. We ask them to make a job that is not used, even we order them to do it twice or more in a process flow. A time ago I was shocked when I saw a code review that was approved by a senior developer with more than 8 years of experience and written by other senior with more than 10 years of experience in the .Net area. What killed me is that nicely looking code makes more noise and brings no value, but cost precious CPU ticks. Please read below listing: What do you think? I hope that this not look familiar to you!!! So let's try to add some context, so the parameter is received by api endpoint, and then passed down. Now firstly we can see that it is converted from string to int , in a safe manner using int.TryParse . Next we see the same method invocation (as Int32 is return type of try/parse) and then this parameter is passed down to document generator, then to submethod where we can see an expensi...