3 ms·
Many times programmers do not even know that their language contains something akin or better than VB's `with` statement. For example, in Ruby `instance_eval` o
by 3pt14159 9y ago
Many times programmers do not even know that their language contains something akin or better than VB's `with` statement. For example, in Ruby `instance_eval` or the even more powerful `instance_exec` could be a drop in replacement for half the stupid fluent interface libraries out there.
The one exception I'll make is query builders like ActiveRecord, as the submitted post mentions. It's hard to figure out how else you can dynamically pass `User.where(age > 18)` to a controller that has the filter to only include men and to paginate by 10 records at a time. I'm not saying it's not possible, it just seems like the one case where the fluent interface is worth the pain it brings. Even so, I really hate them even if I love Rails. Also, scopes are so brittle I avoid them whenever possible. They seem clean and elegant at first, but they're hard to combine and that combining is really only needed as the application gets more and more complicated.
- Mister_Snuggles 9y agoHow do you feel about LINQ[0] (specifically, the query expression syntax) as an alternative to the query builders that you mention? From reading this page[1], I'd guess that the query expression syntax compiles down to the same code that the method-based syntax does. I think it looks great, but I've never had a chance to actually use it. None of the languages that I use regularly have anything even close to LINQ's query expression syntax. [0] https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/ https://docs.microsoft.com/en-us/dotnet/csharp/programming-g... [1] https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/standard-query-operators-overview https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
- 3pt14159 9y agoHaven't used it but it looks like a syntactic improvement even if some of the underlying issues like difficult debugging may remain persistent. Though really, I shouldn't really answer with a gut opinion. I haven't even toyed around with it.