|
|
|
|
|
by ignurant
894 days ago
|
|
I'm fluent in Ruby, and have nearly zero experience in the other languages featured in this article. The `implicit return` is often something people find rather willy-nilly when first learning Ruby. As such, I always thought that was a feature explicit to Ruby and its peers (historical influences like Lisp, Smalltalk, and futures like Elixir and Crystal). I am surprised and delighted to learn that in fact, many modern languages have been doing this. Particularly seeing this in Rust raised my eyebrows, given how system-focused it is. I'm curious from the Rustaceans out there: Is it common to use the conversational nature of expressions and implicit returns? Or does it frequently create unwelcome dissonance? Whenever I switch to Python, JS, C#, the explicit returns catch me for a day or two. I always think "We're already reserving this value in memory to evaluate that last line, why don't you let me do something with it if I want?". But I know folks who swing the other direction and feel quite the opposite -- things feel out of place and not-obvious. Either way, thanks for the well-written article. It has added influence to my "I think I want to look at Rust -- it feels familiar." |
|
In GNU C, if a braced compound statement is put into parentheses, it becomes an expression. The value of the last expression in the compound is implicitly returned:
Never mind that; the standard C macro preprocessor has "implicit return": Note that the "implicit return" in Lisp is just from mathematics: Not: the return keyword is kind of a disease/blemish, introduced by way of Blub programming languages."Implicit return" is like saying "face with implicit warts" in reference to a face that is perfectly smooth and never had a blemish.
In functional languages, there is only one expression which makes up the body of a function and of course that expression's value is yielded; it's the definition of the function.
Explicit return is a form of goto; it's required only in imperative programming, and even there we can leave it out for the last statement.
The C preprocessor doesn't have a return operator because it's a functional, term rewriting language. Every definition has one replacement in which there are no side effects or goto.