News for hackers. Stuff that matters.
Re:Avoid Null Checks by Replacing Finders with Tellers by sambeau on Monday June 17, 2013 @02:08PM (#5894812)
I once wrote a programming language that had a localised 'this' called 'it' exactly for this pattern.

  if (something_exists) {
    do_something_to(it)
  }
It was really useful (and readable).

I believe Perl has something similar but it was less readable.

Re:Avoid Null Checks by Replacing Finders with Tellers by draegtun on Tuesday June 18, 2013 @04:53AM (#5898227)
re: Perl - You're probably thinking of $_, which most Perl programmers call it.

However this only gets topicalised in bare for & while but not if.

So you could do...

  for (something_exists) {
    do_something_to($_);
  }
... as long as something_exists doesn't return a list :)

More common approach I've seen in Perl (and other languages where variable declarations return its value) is this:

  if (my $it = something_exists) {
    do_something_to($it);
  }