News for hackers. Stuff that matters.
Re:Writing good code: how to reduce the cognitive load of yo... by brobinson on Wednesday March 08, 2017 @12:52AM (#13818248)
Ruby version is a pretty clear one-liner:

    validated_items = items.select { |item| is_validated?(item) }
Though I'd expect a check for validation to be an instance method, so it'd probably look like:

    validated_items = items.select(&:validated?)
Re:Writing good code: how to reduce the cognitive load of yo... by Singletoned on Wednesday March 08, 2017 @01:40AM (#13818443)
I don't find either of the Ruby versions clear at all. Both contain unnecessary syntax.

Ruby seems to be going down the same path as Perl in trying to make all possible combinations of characters valid programs.

Re:Writing good code: how to reduce the cognitive load of yo... by mfontani on Wednesday March 08, 2017 @02:02AM (#13818513)

    my @validated = grep { is_validated($_) } @items;
I'd argue the Perl version is clearer... assuming you know its syntax, that is.
Re:Writing good code: how to reduce the cognitive load of yo... by lparry on Wednesday March 08, 2017 @07:37AM (#13819803)
Even if it's not an instance method you can write the first as

  validated_items = items.select(&method(:is_validated?))
(Typed on my phone but I'm pretty sure that's the right syntax)
Re:Writing good code: how to reduce the cognitive load of yo... by brobinson on Wednesday March 08, 2017 @10:35PM (#13826733)
It is! I'd forgotten about Kernel.method. Thanks!