Spacc BBS Spacc BBS
    • Categorie
    • Recenti
    • Tag
    • Popolare
    • Mondo
    • Utenti
    • Gruppi
    • Registrati
    • Accedi
    La nuova BBS è in fase Alpha. I post precedenti al 22 luglio 2024 potrebbero non essere trasferibili, ma rimarranno disponibili per la lettura su /old/.

    I thought `unless` and postfix conditions (`return if blah`) in Perl/Ruby were kind of pointless when I first saw them, but honestly I'm kind of finding myself wishing more languages had them?

    Pianificato Fissato Bloccato Spostato Uncategorized
    1 Post 1 Autori 1 Visualizzazioni
    Caricamento altri post
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti
    Rispondi
    • Topic risposta
    Effettua l'accesso per rispondere
    Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
    • emily@sparkly.uni.horseE Questo utente è esterno a questo forum
      emily@sparkly.uni.horse
      ultima modifica di

      I thought `unless` and postfix conditions (`return if blah`) in Perl/Ruby were kind of pointless when I first saw them, but honestly I'm kind of finding myself wishing more languages had them?

      I don't know that they should be broadly used outside of a few specific cases (where the LHS is something very short where you won't miss that there's a condition at the end), but e.g. `return unless condition` seems like a nicer way to write the very common `if (!condition) { return; }` form. (Early returns of this form are good and teaching students not to use them because they're supposedly confusing is actively harmful. I'm glad most people who were taught that seem to eventually realize otherwise.)

      I also find myself wishing for something like `continue iff condition` as a synonym for `return unless condition`, but `continue` already means something else. (I kind of like `next` more as a keyword for "skip remainder of this loop iteration", but not much else outside of Perl uses it.)

      Maybe `require condition` as an assert, and `require condition else return` as an early return?

      ... also I should learn Raku

      1 Risposta Ultima Risposta Rispondi Cita 1 0
      • gustavinobevilacqua@mastodon.cisti.orgG gustavinobevilacqua@mastodon.cisti.org shared this topic on
      • Primo post
        Ultimo post