The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
No, no, I wasn't looking at it from a code review perspective. I realize this is demo code.
I was just using it's an example of why I would never have long lines like that, in any code. The validation check for the values doesn't have to be there because this is demo code. I was pointing out the case that breaking the lines out of the chain makes spotting such missing functionality easier.
ou're really not saving yourself anything by piling it all into a single statement.
Debugging is key for me. A fellow coder loves to chain things together ... but if there is a problem with one parameter, it's harder to nail down when it's part of a large chain.
Plus it's not immediately obvious what parameters are in many cases. Name the variables well and it lends to self documenting code. [Although I want a comment explaining the business and/or technical reason for the code.]
I do have a penchant for extension methods. As in:
var face = allFaces
.AnyBetween(f => f.Proportion, "LowerBound".AppSetting().to_f(), "UpperBound".AppSetting().to_f())
.OrderBy(f => f.Proportion)
.ThenByDescending(f => f.Rectangle.Height)
As bizarre as it is to extend string, I find it a lot more readable.
The ToList() seems superfluous. Not sure you want to output an image if no images meet the selection criteria. I might move FirstOrDefault into OutputImage(file, face.FirstOrDefault()); as well, who knows, the way you get the faces might be re-usable.
I leave it to the reader to figure out to_f, AnyBetween, and AppSettings Should be obvious.
You're my hero. I also find myself writing lines like this. I kinda consider them a guilty pleasure, they may not look nice, but I like them. Started all the way back at the end of my school time, I was in the Maple math class and my teacher always told me to use variables, they're aplenty and free. He kept telling me every single time.
In theory, you can write your entire application on a single line.
You're writing for people though, not for machines.
So yeah, make two separate lines that make it more readable and the compiler will inline them giving you no added memory or performance impacts.
I'd probably also do this:
It won't barf, but yes, those ToString()s are redundant. This is some code ripped from a very Q&D POC project that just seemed to be a good example of the more general issue of how to format long lines.
Love the dirkBenedict variable name - my new mission is to find a way to get dwightSchultz in there!
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
Last Visit: 2-Apr-20 17:57 Last Update: 2-Apr-20 17:57