|
|
|
|
|
by ziml77
1546 days ago
|
|
You can get something similar via method chaining: x.something().somethingElse().anotherThing() C# extension methods aren't the perfect solution for this, but I love that they exist to at least make chaining possible without needing to modify the class that I'm applying the function to. D has an even better version of this called UFCS which makes it so `Bar something(Foo f)` can either be called as `something(x)` or `x.something()` without needing any special annotations like C# requires. |
|
To illustrate:
Compared to: Not necessarily the best way to write this (you would probably use a sequence library) but hopefully conveys the idea.Extension methods are definitely useful in OOP languages. However, a much cleaner language design is to remove the need for a "class" altogether and just have free-functions, function composition and a pipe operator.
None of this is something you can't simulate in OOP / procedural languages, it's just much more clunky.