Live data from Hacker News

Such a Little Thing: The Semicolon in Rust

lucumr.pocoo.org

51–60 of 81 posts

Re: Such a Little Thing: The Semicolon in Rust

#51

Earlier quoted context omitted.

Which is usually wrong.

That's not the point. Most programmers are not language lawyers. It is very bug-prone, which could in itself enough to remove the confusion from a language that advertises itself as "safe".

Bug prone? The compiler will inevitably warn you about your error at compile time. No such bug will have any consequence beyond that.

This is also not such a big problem when a human reads the function. We can always see at a glance the return type of the function. Either it's explicitly declared, or it's a lambda whose usage is readily visible. Semicolon or not, you can easily guess if the function is supposed to return its last expression, or not.

By the way, the compiler could do the same. Knowing that, there probably will be helpful error messages such as "did you forget the last semicolon?", or "should you remove the last semicolon?".

The semicolon is really just a small confirmation. That's why they didn't chose a heavier syntax.

Re: Such a Little Thing: The Semicolon in Rust

#52
post #34

Earlier quoted context omitted.

Untrue. While it's true that most people use the 'layout' rule, which is the significant whitespace, there is a non-whitespace-significant variant that uses braces and semicolons. You can see an example of how layout is expanded to the alternative syntax at http://www.haskell.org/onlinereport/lexemes.html#lexemes-lay...

No, I meant that Haskell doesn't consider any whitespace that isn't indentation as significant.

Very few languages consider non-indentation whitespace as significant (not counting using whitespace as a token delimiter, which Haskell definitely does, e.g. "foo bar" =/= "foobar").

Re: Such a Little Thing: The Semicolon in Rust

#53
post #49

Earlier quoted context omitted.

Ignoring a potentially wanted return value with ";" is a hazard. I'd like to institute some set of "warn-unused-result" warnings in Rust to combat this.

Wouldn't the type system complain that you're returning nil in a function that is not declared/inferred as returning nil?

What if foo() could return nil in some cases?

Re: Such a Little Thing: The Semicolon in Rust

#55

Earlier quoted context omitted.

That's not the point. Most programmers are not language lawyers. It is very bug-prone, which could in itself enough to remove the confusion from a language that advertises itself as "safe".

Bug prone? The compiler will inevitably warn you about your error at compile time. No such bug will have any consequence beyond that. This is also not such a big problem when a human reads the function. We can always see at a glance the return type of the function. Either it's explicitly declared, or it's a lambda whose usage is readily visible. Semicolon or not, you can easily guess if the function is supposed to re…

Ok, I misunderstood then. I thought it would subtly return no value instead of a value, and you'd only discover this at run time. That would be bug prone. If it simply generates a compilation error, no problem.

Re: Such a Little Thing: The Semicolon in Rust

#56
post #52

Earlier quoted context omitted.

No, I meant that Haskell doesn't consider any whitespace that isn't indentation as significant.

Very few languages consider non-indentation whitespace as significant (not counting using whitespace as a token delimiter, which Haskell definitely does, e.g. "foo bar" =/= "foobar").

Yes, but many people assume whitespace everywhere will matter when they hear Python's offside rule described. It's a misconception I've found is worth dispelling, since almost no one minds meaningful indentation.

Re: Such a Little Thing: The Semicolon in Rust

#57
post #24

Earlier quoted context omitted.

I'd rather have significant semi-colons than significant whitespace[1]. Don't mix presentation and semantics. 1: http://c2.com/cgi/wiki?SyntacticallySignificantWhitespaceCon...

I'd rather have the ability to choose between and freely mix significant whitespace and significant semi-colons within a single source file.

No you wouldn't. See Javascript for all the pain that causes. Language syntax needs to be dictatorial so that the language is consistent for reading (which is more important than writing).

Re: Such a Little Thing: The Semicolon in Rust

#58
post #15

Earlier quoted context omitted.

Which keyboard layout is that?

Czech; German; Polish; French; Spanish; Italian; Portuguese; etc etc etc.

I've never seen QWERTZ keyboard in Poland and I live there. Typewriters indeed were using this layout, but not many people use them to program.

"practically all computers (except custom-made, e.g., in public sector and some Apple computers) use standard US layout (commonly called Polish programmers layout, in Polish: polski programisty) with Polish letters accessed through AltGr (AltGr-Z giving “Ż” and AltGr-X giving “Ź”)." http://keyboard-layout.info/#Polish

Re: Such a Little Thing: The Semicolon in Rust

#60
And with Rust's strong static typing, it's even easier to spot. While I love a preference for expressions, in CoffeeScript I've had to put a single null at the end of functions several times.

The presence/absence of the ; is both explicit and subtle enough to not annoy.

Post reply on HN