I love fluent APIs. But please, please don't make fluent APIs mutable! They become very confusing. Consider this code using your class:
var x = MyFluentClass.WithValue(5).Add(1); var y = x.Subtract(6); Console.WriteLine(x.Result()); // most people would expect 6, but the result is 0
This is one of the things that is killing moment.js that otherwise was pretty great.
moment.js
I would agree 100%. The class I used in the article actually wouldn't work in the snippet you made 😉
The second line of your code snippet would throw an exception since the only available method would be Result, which I highlighted in the article.
Result
It should actually do what you want (immutable) 👍
You are right, sorry, my bad! Try this:
var x = MyFluentClass.WithValue(5); var y = x.Subtract(5); Console.WriteLine(x.Add(1).Result()); // correctly returns 6 Console.WriteLine(y.Result()); // 6 again?!
Sure, anyone can try to misuse code if they really want 😜😂
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I love fluent APIs. But please, please don't make fluent APIs mutable! They become very confusing. Consider this code using your class:
This is one of the things that is killing
moment.js
that otherwise was pretty great.I would agree 100%. The class I used in the article actually wouldn't work in the snippet you made 😉
The second line of your code snippet would throw an exception since the only available method would be
Result
, which I highlighted in the article.It should actually do what you want (immutable) 👍
You are right, sorry, my bad! Try this:
Sure, anyone can try to misuse code if they really want 😜😂