|
Maximilien wrote: Is there a reason to write ugly code like that ?
I was curious to what extent, ok, extreme, I could go. One of the things I love about functional programming is the pipe operators |> and <| which have no equivalent in C#, the best one can do is the dot operator.
So I wanted to play with the concept, see how far I could take it, what extension methods I needed to create to maintain the "continuation", how hard it would be to debug, and if the result looked in any way maintainable.
One of the things I discovered is that, as usual, wrapping simple things like "where" expressions into a named extension method improves readability but potentially decreases the "well, how is that actually accomplished" immediate comprehension, and naming can be quite difficult when creating bizarre functions that iterate over a collection and pass in both the collection item and some other pre-computed value.
So consider it a "thought experiment" in actual implementation.
|
|
|
|
|
IMO the biggest problem with overly complex linq is that it's all one statement to the debugger. If you to step from one . to the next being able to view the data being passed around without having to spam replace each . with ;\r\n foo = and turning anonymous functions into normal ones (and of course undoing all of that when done) troubleshooting would be much easier.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Chances are it's less efficient because of the overhead inherit in LINQ itself.
|
|
|
|
|
There is no overhead "inherit" in LINQ. There is some in the current JIT implementation of lambdas, but a better JITter could inline them, which would make them more efficient than functions.
Truth,
James
|
|
|
|
|
|
Beautiful!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Functional programming )))
|
|
|
|
|
stepan hakobyan wrote: Functional programming )))
For dysfunctional programmers
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
stepan hakobyan wrote: Functional programming )))
Yes! That was the point of the experiment.
|
|
|
|
|
I read it aloud and accidentally summoned and eldritch horror.
Please provide the unsummon chant.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Give Bob[^] a call.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
den2k88 wrote: Please provide the unsummon chant.
You really do not want to see the one-liner for that! It summons several other beasts to defeat the eldritch horror, then you have those beasts to contend with, which requires summoning more beasts -- recursive stack overflow exception!
|
|
|
|
|
say:
oh
wa
tagu
sigh
am
ten times as fast as you can. if that doesn't work, try
me
we
todd
ed
instead.
/trollface
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
Why?
Who hurt you?
|
|
|
|
|
Strictly speaking, this is not LINQ.
LINQ stands for Language-Integrated Query and is a query language that can be embedded within C#.
You have written C# code using the classes that support LINQ.
As an exercise, try rewriting your code using LINQ.
|
|
|
|
|
|
There is a module for using actual, real SQL statements in code, rather than LINQ. I had to use it once for ad hoc sorting, because LINQ was way too cumbersome. Too bad the LINQ creators couldn't incorporate it.
|
|
|
|
|
Huh? I'm very confused by that statement.
Are you attempting to sort a database table/query or an in-memory collection?
Either way, I don't see how a proper SQL syntax would be any less "cumbersome" than the LINQ syntax.
Truth,
James
|
|
|
|
|
The more they complicate the plumbing, the easier it is to stop up the drain.
One look at that, and I would start asking:
1. "What other ways can I do the same thing"
2. "Of those other ways, which provides the most value over the full SDLC?"
|
|
|
|
|
I appreciate the power of LINQ.
I also love how Entity Framework can use the power of LINQ to turn a simple SQL query into a multiple library, dozen of files, partial files and nonsense cluster elephant.
I hate everyone because of this.
|
|
|
|
|
Nice! However, I'm surprised you used old fashioned SQL to do the database update in light of what you are trying to illustrate.
|
|
|
|
|
Is Scrabble all fun and games until someone loses an 'I'?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: all fun and games until when someone loses an 'I' eye?
That's more like it.
|
|
|
|
|
20212 wrote: That's more like it. Actually, it's not.
Either you have a sense of humor that is truly "unique" and see something that none can comprehend or you really don't get "Thought of the Day" at all (or you've no idea what Scrabble is).
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
W∴ Balboos, GHB wrote: and see something Indeed I do.
|
|
|
|