On return type syntax #618
Replies: 9 comments 7 replies
-
I think this is the only viable candidate among your proposed ones. The last one, without |
Beta Was this translation helpful? Give feedback.
-
I think you'll need a better example. |
Beta Was this translation helpful? Give feedback.
-
There's some overlap with #540. |
Beta Was this translation helpful? Give feedback.
-
vs
Okay, but the current syntax with named returns is this, which is even less due to implicit return:
|
Beta Was this translation helpful? Give feedback.
-
An important thing to keep in mind is declaration-use symmetry. I mentioned this in the Design note: Postfix operators. Consider examples like this:
where as we add to the expression, we just move items from the rhs to the lhs:
I realized that the For example, consider:
It would be grammatically unambiguous to omit the
but to me that that just felt surprisingly harder to read. |
Beta Was this translation helpful? Give feedback.
-
I don't know if it's the point you were trying to make, but the
Go omits the package main
import "fmt"
func main() {
g := func(i int, j int) (name string, addr string) {
return "alice", "home"
}
fmt.Println(g(7, 8)) // Prints "alice home\n"
} Like |
Beta Was this translation helpful? Give feedback.
-
I have to say, neither syntax is familiar to me, but reading in phone, with lots of automatic line wrapping muddling the picture, the punctuation really helps me to parse what is going on at a glance, without actually reading every character and thinking about it.
The punctuation gives my eyes places to jump to, and context to quickly ascertain what neighbouring tokens mean without breaking my flow, I don't know about you, but if I have to think too hard about every little bit of code, I find it harder to see the bigger picture, making the code easier to parse by eye really helps with this in my personal experience.
On 31 August 2023 03:15:21 Nigel Tao ***@***.***> wrote:
expression type
f (int) -> * string
f(42) * string
f(42)* string
I don't know if it's the point you were trying to make, but the -> there sticks out as inconsistent (unlike * or (), it's only on the first line) with what's otherwise a very regular pattern.
But it felt like the -> had readability value (and follows Cpp1 and most languages)...
g: (i: int, j: int) -> (name: string, addr: string) = ...
Go omits the ->. Here's a runnable example<https://go.dev/play/p/6O8KKbHnDWf>:
package main
import "fmt"
func main() {
g := func(i int, j int) (name string, addr string) {
return "alice", "home"
}
fmt.Println(g(7, 8)) // Prints "alice home\n"
}
Like i: int versus int i, "harder to read" might just be "unfamiliar".
—
Reply to this email directly, view it on GitHub<#618 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQIQRW6HVL2OFX6ME5LXX7XTNANCNFSM6AAAAAA4B6OMP4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
One argument here is about Go, which doesn't have |
Beta Was this translation helpful? Give feedback.
-
I feel it rather reduce cognitive load,compared with situation where similar char, say I need more time parsing string, where |
Beta Was this translation helpful? Give feedback.
-
I perhaps understand why you chose
->
, but I don't see this as a specially safe choice. Someone working between languageshas lots of additional cognitive load trying to track the current context of what this means.
There are several obvious ways you could simplify this for reader/writer/parser:
main: (args) -> int = {}
as perhapsmain: (args): int = {}
,main: (args) int = {}
,main: (args) = int: {}
, ormain: (args) = int {}
.I feel though that the spirit of this project calls for repeating a pattern you already called out for its superior safety:
For example:
Beta Was this translation helpful? Give feedback.
All reactions