|
I don't see that there is much more to understand. You claim there is an ambiguity that isn't there. You insist that it nevertheless is there, but refuse to explain when, where and why it is there.
Your 48 years of Pascal experience is not explanation for why it should be ambiguous. Nor is the number of Pascal compilers you have been using. Your unambiguous code snippet is not made ambiguous by your saying that it is.
The only thing that needs explanation is why you claim some sort of ambiguity in these samples. You are the one making the claim, you must provide the arguments for it. You refuse to. Fair enough. Then you are not providing any support for the ambiguity you claim.
You are quite right: I do not understand the ambiguity that isn't there
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
That Pascal code isn't anything fluent at all, it's just a series of method calls. The direct equivalent of the C# code would be (removing the use of WITH as an anti-pattern):
var myFluentThing := TFluentThing.Create
.DoThis(x)
.DoThat(y)
.DoAnother(z);
This is only possible, as is true for C#, if the DoThis and DoThat functions return an instance of the TFluentThing class.
|
|
|
|
|
But at the end comes nearly to the same
|
|
|
|
|
Ermmm, no, because that is like saying 2 + 2 = 3, because 3 is nearly 4
|
|
|
|
|
In the C# chain, methods may return the same or different objects at any stage.
The WITH block just calls the methods on the original object.
IThing thing = new ThingBuilder()
.AddTitle("I'm a Thing!")
.CreatePreciousThing()
.SetPreciousLevel(100);
|
|
|
|
|
Finally it comes up to the same from a user point ...
|
|
|
|
|
Well, no. I must admit that I do not use C#, only know the very basics of it.
"new" in C# is creating an instance of an previously defined object (MyFluentAPI) and executes those 3 methods.
As for "Pascal", you did not mentioned which kind of Pascal you are using.
In "standard" Pascal (including but not limited to ISO7185), the "with" statement is used to set the scope for the statements within the begin...end block, and is used in connection with "records" ("struct" in C) to save on some typing, as you would not have to precede each record element with its associated record name. But in this case, those elements within that record are purely data!
It is purely what sometimes these days is referred to as "syntactic sugar".
But the major difference is that the record (and in extension, this applies mostly to objects/classes in Object Pascal (Delphi/FreePascal) as well) needs to be existing (already instantiated) when you are referring to it using the "with" statement (block).
If you are using the "with" statement in either standard/procedural Pascal or Object Pascal, you need to do this carefully, as, while it saves some typing and the source code lines shorter, it can lead to some nasty side effects/bugs (or features ) if you have elements, like data or methods/procedure/functions with the same names in different records/methods/etc...
|
|
|
|
|
Not quite.
While the code sample you posted may look fluent, in reality the functions DoThis() , DoThat() and DoAnother() all operate on a myFluentThing . A truly fluent piece of code contains chained methods each of which operate on the context of the previous returned type.
So unless I misunderstood what you wrote, I don't think you'd be able to simulate this in Pascal:
int i = new FooBuilder()
.Build()
.DoSomethingToFoo()
.DoSomethingElseToFoo()
.GetAnEnumerableIntPropertyOfFoo()
.Sum(); /ravi
|
|
|
|
|
Of course you are right, nitpicker
|
|
|
|
|
So stringing things together is great?
Then you should try Lisp.
|
|
|
|
|
Wordle 1,065 4/6*
⬛🟨⬛⬛⬛
⬛🟨🟨⬛🟨
⬛🟩⬛🟨🟩
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 1,065 4/6
⬛⬛⬛⬛🟨
🟨⬛⬛🟨⬛
🟨🟨🟨🟩⬛
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 1,065 6/6*
⬜⬜⬜⬜⬜
🟨⬜⬜🟨🟨
⬜🟩🟩🟩🟩
⬜🟩🟩🟩🟩
⬜🟩🟩🟩🟩
🟩🟩🟩🟩🟩
Close ... too close ...
"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!
|
|
|
|
|
Wordle 1,065 5/6
⬜⬜🟨⬜⬜
⬜⬜⬜🟨⬜
⬜🟩⬜⬜⬜
🟨🟩⬜🟨⬜
🟩🟩🟩🟩🟩
|
|
|
|
|
🟨⬜⬜⬜⬜
⬜🟩⬜⬜⬜
⬜🟩🟩🟩🟩
⬜🟩🟩🟩🟩
🟩🟩🟩🟩🟩
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 1,065 6/6
⬛⬛⬛⬛⬛
⬛🟩🟩🟨⬛
⬛🟩🟩⬛⬛
⬛🟩🟩🟩🟩
⬛🟩🟩🟩🟩
🟩🟩🟩🟩🟩
This one took me too long!
Ok, I have had my coffee, so you can all come out now!
|
|
|
|
|
Wordle 1,065 3/6
🟩⬛⬛⬛🟨
🟩⬛⬛🟨⬛
🟩🟩🟩🟩🟩
Jeremy Falcon
|
|
|
|
|
You'll strain your voice.
*runs away*
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
good one
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Did you hear about the elephant who ran into a screen door? He strained himself.
(Heard on Dr. Demento in the 80s if I recall correctly.)
The Lounge[^]
modified 19-May-24 12:15pm.
|
|
|
|
|
See title - doctors and nurses should get more attention than this crap - just sayin
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
had to look up the names to see what it is supposed to be about. I'll just reinsert my head into the sand, it's nice and warm there !
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I do not know what it is, but looking at your comment, I think I'll be happier preserving my ignorance.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I decided not to search the term too.
Ah...Ignorance truly is bliss.
|
|
|
|
|
what's worse? Ignorance or indiference?
I don't know it and I don't care
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|