←back to thread

22 points atomlib | 1 comments | | HN request time: 0s | source
Show context
up2isomorphism ◴[] No.41916250[source]
What is the benefit of changing

int main(void) {

to:

pub fn main() !void {

Except making it looks like a "new" language and requires other people spends 15min to get to used to it?

replies(5): >>41916321 #>>41916432 #>>41916718 #>>41916842 #>>41917078 #
tmtvl ◴[] No.41916321[source]
There are tradeoffs:

Use of the pub keyword means you can tell whether a function is public in the module without needing to look at a separate place for listing exports (like, say, a header file). Though that itself has tradeoffs, so it's hard to say whether one or the other is better.

Use of the fn keyword makes it easy to find function definitions by grepping for it, whereas finding functions in regular C syntax needs semantic awareness.

What I don't understand is the !void at the end of the declaration, if we're meant to be returning an int, surely !int would be the expected syntax (although I would prefer returns int instead).

replies(4): >>41916414 #>>41916845 #>>41916951 #>>41917615 #