Re:Be wary of functions which take several parameters of the...
by yawgmoth on Friday September 27, 2019 @08:00AM
(#21090901)
Personally, in C#, I don't enjoy debugging and maintaining Fluent APIs. An exception thrown in the chain is sometimes opaque and the necessary extension methods to make everything come together is not neat code. The former reason is why I also discourage use of object initializers.
Re:Be wary of functions which take several parameters of the...
by tluyben2 on Friday September 27, 2019 @09:39AM
(#21091796)
I like those API's much better for reading, but when there are issues with them, like you say, debugging is often a right pain compared to the other examples. Especially when a chain became a bit too long (over time) and there is suddenly a null somewhere (for whatever reason). VS indicates the error in the first line of the chain and debugging can become quite hairy.
Is that better in other language runtimes/debuggers?
Re:Be wary of functions which take several parameters of the...
by GordonS on Friday September 27, 2019 @06:17PM
(#21096751)
If you want to be more opaque, I guess you could do:
```c# var file = File("source"); file.CopyTo("target"); ```
(apologies if this is formatted badly; no clue what HN supports here, and I'm on mobile)
Re:Be wary of functions which take several parameters of the...
by lonelappde on Friday September 27, 2019 @01:57PM
(#21094495)
The proper place to pay the dev cost is once in the library, not in all its callers.
Re:Be wary of functions which take several parameters of the...
by stouset on Friday September 27, 2019 @03:11AM
(#21089262)
Your suggestion is basically Ruby’s `Pathname` class (sans convenient copy method).
Re:Be wary of functions which take several parameters of the...
by xeeeeeeeeeeenu on Friday September 27, 2019 @08:55AM
(#21091362)
That's how Perl's Path::Tiny[1] works, for example:
path("/tmp/foo.txt")->copy("/tmp/bar.txt");
[1] - https://metacpan.org/pod/Path::Tiny
Re:Be wary of functions which take several parameters of the...
by kragen on Friday September 27, 2019 @10:09AM
(#21092165)
Amusingly, this has the same ambiguity problem the original post was trying to solve!
Re:Be wary of functions which take several parameters of the...
by anonytrary on Friday September 27, 2019 @01:31AM
(#21088737)
> also nice when learning because an IDE can give very useful help about possible operations
Why is chaining necessary for this? On-instance tab-autocomplete list-all on-tab accomplishes the same thing.
Re:Be wary of functions which take several parameters of the...
by skrebbel on Friday September 27, 2019 @03:10AM
(#21089261)
> On-instance tab-autocomplete list-all on-tab
I have no idea what you just said.
Re:Be wary of functions which take several parameters of the...
by nurettin on Friday September 27, 2019 @04:11AM
(#21089586)
I think it means:
(While editing code, position the cursor) on (a class) instance (and press) tab (to swith to) autocomplete (mode and) list all (members of that instance by clicking) on tab (again).
Re:Be wary of functions which take several parameters of the...
by coldtea on Friday September 27, 2019 @04:57AM
(#21089828)
He said that clicking TAB on an instance in an IDE
(e.g. foo.[TAB])
can list all possible operations available on that instance -- in other words, you don't need a fluent interface for this.
Funny, I don't think I've actually seen a fluent file API like this before. I guess most languages have file I/O built in to their standard libraries.
My immediate reaction to this, though, is that you could make it more general:
You could then also have This is readable and solves the problem the original post is discussing, but it's also nice when learning because an IDE can give very useful help about possible operations, and all you have to remember is the File() function.