Hacker News new | past | comments | ask | show | jobs | submit login

only tangentially related, but one of the things I miss so much about Perl is that, as in English, you can add an "if" or "unless" clause as an afterthought.

$x++ if (!condition);

like if you start to increment $x++ and then you realize wait a second I only mean if....

"unless" likewise functions as an "if not".

This is such a "natural" way to write.

Let's compare what happens if you have the thought to add a "statement modifier" in any other programmer language.

you're written your statement, and now you have to go back to the beginning of your line, write your condition, open a brace, go back to the end of the line, and close your brace. Or maybe begin an entire code block, since you can't have it on one line anymore.

it is so much less natural. why can't other programming languages have that?




Ruby has that.

  x += 1 if !condition
Better as

  x += 1 unless condition
I use them not as an afterthought but by design. This is the Ruby Style Guide about it https://rubystyle.guide/#if-as-a-modifier


Ruby has that. But you have to be careful that your code stays readable. I know that's not a concern for Perl. :-)

Although the "unless" case very often trips me. Somehow my brain can't parse that correctly and I've found that surprisingly many work colleagues have the same problem.


The greatest difficulty with code is not in writing it but in reading it.


<result> if/unless <condition> is pretty common in natural language for good reason. I find it far more readable than prefix, block-form if for the simple case of one-line results with no alternative branch.,


Agreed. Particularly useful for for constructs like:

  def do_stuff()
    return unless stuff_enabled?

    ...
  end


Forth love if honk then

Be careful what you wish for...




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: