5 ms·
Not to golf your code or anything, but that's around the point where I switched to Ruby. It's almost a drop-in replacement, you can be coding in minutes with al
by wnight 15y ago
Not to golf your code or anything, but that's around the point where I switched to Ruby. It's almost a drop-in replacement, you can be coding in minutes with all the handy shortcuts non-PERL coders don't know they're missing.
name = args[:form_name].respond_to?(:call) ? args[:form_name].call(user_options) : args[:form_name]
Fewer sigils, no array/scalar access nonsense, real and convenient objects, etc.
- chromatic 15y agoFewer sigils As with PHP, reusing the same sigil for everything misses the point of sigils rather badly. I count five instances of two sigils in your example and each sigil character has another syntactic meaning within the same line.
- wnight 15y agoIf sigil means non-ascii character, there are six. If you use it to mean name-modifier (changes what the following string means) there is one, the colon. What did you mean? And yes, colon is also the or in the ternary operator. But there are still less than Perl, for the same length of code, and the code is simpler - .call() the thing if it.respond_to?(:call)
- chromatic 15y agoWhat did you mean? A punctuation character considered as part of an identifier by way of a parser rule. The ? in respond_to?, in this case.
- draegtun 15y agoYour example isn't exactly identical because its not making use the $self object. Your example would look more like this in Perl: my $name = ref $args{form_name} eq 'CODE' ? $args{form_name}->(@user_options) : $args{form_name}; Taking the original Perl example I would probably write it like this: my $name = do { my $c = $args{form_name}; ref $c eq 'CODE' ? $self->$c(@user_options) : $c }; Which seems DRYer to me.