Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No language syntax needs return in 2023.



How should an early return if statement work instead?


When if is an expression early returns aren't really a problem.


I understand what you mean. But I expect most potential users want explicit returns because they're familiar and more approachable for beginners.


I disagree. You make two claims: familiarity, and beginner friendliness.

For the first, I think it's a mistake to perpetuate the mistakes of the past. I don't think JS developers have had problems adjusting to the lack of return in arrow functions.

Beginners have no preconceived notions of how a programming language should operate, and return makes the language model more complex.

1 + 1 evaluates to 2, but (in a language that requires return)

def foo = 1 + 1

foo

doesn't for no good reason. This breaks the simple substitution model of evaluation.

These claims could be addressed emperically, but I guess neither of us are going to do the research. :-)


For a very simple, single-expression lambda function I agree you don't need an explicit return. Even Python skips the "return" for lambdas. But for anything more complex, I find explicit returns, especially early returns, makes the code much more readable for people who are used to imperative languages.

For example, which of these is more clear to people who don't know Lisp? I'd argue the second one because of the early return if guard.

    ---- THIS ----

    (defun sum-helper (items total)
        (cond
            (items
                (sum-helper
                    (cdr items)
                    (+ total (car items))))
            (t total)))

    (defun sum (&rest items)
        (sum-helper items 0))

    (print (sum 1 2 3 4))

    ----- OR -----

    (defun sum-helper2 (items total)
        (if (not items)
            (return-from sum-helper2 total))

        (sum-helper2
            (cdr items)
            (+ total (car items))))

    (defun sum2 (&rest items)
        (sum-helper2 items 0))

    (print (sum2 5 6 7 8))


I think I'll write a blog post in response, as I believe this illustrates a much deeper and more important issue.


Great! Please send it my way so I don't miss it. Thank you


I have a draft up here: https://noelwelsh.com/posts/fp-is-based/

(It should be readable but hasn't had a final editing pass.)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: