5 ms·
Ugh. I have to say, that's one of my least favorite features of blocks. In Clojure (which has no blocks or return statement), I would write that code as (
by arohner 17y ago
Ugh. I have to say, that's one of my least favorite features of blocks.
In Clojure (which has no blocks or return statement), I would write that code as
(defn outer []
(first (filter close? something_or_other))
What advantage does the block+return code have over that?
- jerf 17y agoI have this problem with Ruby and even moreso with Perl. It's not that I don't understand the reasoning behind $GLORIOUS_FEATURE, my question is how come I don't miss it when I have to go program in other languages? And how come even though the other language doesn't have $GLORIOUS_FEATURE it sometimes still works better in the other language? Perl <-> Python is my canonical example; I program professionally in Perl and only as a hobby in Python, so the time spent with each language is probably about 5:1 (but still quite substantial with both, as I've been programming with Perl for a long time), so I'm actually more familiar with Perl if anything. Perl is shot through with features, syntactic nuances, and all sorts of magical features both by default and in CPAN, and I even use some of them (selectively), but if it's all so awesome how come I never miss any of it in Python? (And how come the feature I really miss is the ability to use objects as the key for hashes, which Python has and Perl does not? Yes, I know about the CPAN modules, which are hacks and not something I trust, not like Python's built-in support.) When I look at languages, I want to look at and talk about the global effects the language has on my programming. It is far too easy to get caught up in how awesome this little feature is and how awesome that little feature is and miss what global effect it is having on your code.
- yesimahuman 17y agoI agree. I've even noticed this with python <-> java. Python is great and has a lot of time saving features, but I haven't really noticed that my work is better or more well tested than what I do with Java. I also haven't even noticed that the work gets done any faster, and I've been doing a lot of python lately.
- james2vegas 17y agoBecause an object does not match the definition of a hash key in Perl, viz. 'Hashes are unordered collections of scalar values indexed by their associated string key'. You can also use a number or filehandle as a hash key, but don't expect to use the keys as anything other than strings without some manipulation. Just like with ordered hashes, using hashes with non-string keys needs programming on your part (perhaps overloading stringification for your object and providing a way to get your object back from the string) or others (CPAN). Or you could overload (or just add to) the object and provide an accessor for your value so you can set it on the object itself.
- jshen 17y agoFor starters, they don't do the same thing right? You're returning the matching something_or_other and he's returning the string 'close' if something_or_other matches.