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

You do realize that comes from english right?

    if $you-are-hungry { make-a-sandwich() }

    make-a-sandwich() if $you-are-hungry;
If you remove all of the non-letter characters, you are left with very understandable english sentences.

    if you are hungry make a sandwich

    make a sandwich if you are hungry
So unless english is a second language to you, it should be fairly easy to understand.

If you pay attention to how people use those different forms in english, you will also notice that the infix form of “if” tends to be used for simple short sentences. Which is exactly how I use it in Perl and Raku.

    sub factorial ( UInt $n ){
      return 1 if $n == 0;
      return 1 if $n == 1;

      return $n * factorial($n - 1)
    }
Though I might consider using `when` instead.

    sub factorial ( UInt $_ ){
      return 1 when 0;
      return 1 when 1;

      return $_ * factorial($_ - 1)
    }
Of course a junction would be useful

    sub factorial ( UInt $_ ){
      return 1 when 0|1;

      return $_ * factorial($_ - 1)
    }
You are probably having fits with that to.

The thing is, that also reads fairly well in english.

    return one when [it is] zero or one
Often times in informal english the “it is” in such a sentence is left off for brevity. So I left it off, because we are obviously talking about “it" (`$_`). I mean, what else could we be talking about? I could easily see this being said as a response to another person.

    > Alice: What result should we give the user?
    >
    > Bob: Return one when zero or one.  
    > Otherwise multiply it by …
You are probably thinking that communicating with a computer should be more formal. You should also be wearing nicely ironed clothes with a jacket and tie.

The problem with that is that you aren't communicating with a computer. You are communicating with everyone that is going to read your code. Reading a technical manual can be very tiring for even the most stoic of readers.

I prefer to read a well written novel. Good Perl and Raku code often reads more like a novel than a technical manual. Even when it is kept very precise about its semantics.

Which means that when I am done doing something in Perl or Raku, I want to continue doing more of that. I don't want to stop.

Sometimes I will find myself re-reading the same line repeatedly at 3am.

---

Further, note how I used the infix form of “if”.

    return 1 if $n == 0;
    return 1 if $n == 1;
The result on the left is very simple. Not only is it simple, it is the same for both lines.

It is very common to use it in this manner. Where they sit at the very beginning of a function as a kind of guard clause. The real important bit is the right part of the lines. Which actually stands out more than the left half, because it is closer to the center of the screen.

After those two lines, we know two things about `$_`. It is neither a `0` or a `1`, because we already dealt with both cases. So we don't have to worry about them in the rest of the function.

For the most part, when I see a line like that I know that I can safely skip over it. That is because it is almost only ever used for that type of thing. As a way to deal with simple cases early in the lifetime of a function. It also means that I can very quickly glean the information I need for that very same reason.

---

People tend to have a lot of bad things to say about Perl and Raku.

Almost everyone who has used them enough to get comfortable with either of the two languages would say just about the opposite to most of those things.

Basically, it's bad in theory, but it's good in practice.

Reminds me of a video “Clay Shirky on Love, Internet Style” https://www.youtube.com/watch?v=Xe1TZaElTAs (9m14s long)

Particularly this line:

> And it was at that moment that I understood what was going on. Because they didn't care.

> They didn't care that they had seen it work in practice, because they already knew it couldn't work in theory.

---

I very much agree that it is far more important to be easy to read. Which is why I find Perl and Raku to be awesome.

I can write things in the most readable way for a person as possible, rather than the only way the compiler can understand.




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

Search: