Live data from Hacker News

Such a Little Thing: The Semicolon in Rust

lucumr.pocoo.org

41–50 of 81 posts

Re: Such a Little Thing: The Semicolon in Rust

#41
I still don't understand why they couldn't just introduce a new keyword that has the same meaning as a missing semicolon. Call it 'ret' or something as a 'lesser return'. Relying on ppl to be semicolon hunters is poor for readability.

It also means you can't put more expressions on the same line because doing so requires a semi-colon which then eliminates the special semicolon behavior. Having an explicit 'ret' keyword means you could accomplish that and have more expressions for a separate block on the same line if desired.

Re: Such a Little Thing: The Semicolon in Rust

#42
post #16

Earlier quoted context omitted.

Which keyboard layout is that?

Norwegian. Many european countries use the same placement for semicolon. All the Scandinavian and Baltic countries, Germany and Netherlands to name a few. Russia uses shift+4. Can't imagine how annoying that is.

Russian keyboard layout does not have any Roman letters so apart from obscure even in their time, Soviet-devloped languages like http://en.wikipedia.org/wiki/Rapira, reaching for shift+4 for ';' is going to be the least of your concerns if you try to write code using Russian layout.

Re: Such a Little Thing: The Semicolon in Rust

#43
I haven't looked at Rust, but the semi colon looks like a decision to make some common verbose or "ugly" syntax to be less noisy. Admittedly most syntax has quirks, and this seems more like a quirk rather than an instance of "clever design". Ignoring the explanation of the differences between statements and expressions, the rest of the discussion is about the presence of a semicolon.

Re: Such a Little Thing: The Semicolon in Rust

#45
post #8

Earlier quoted context omitted.

It's odd because people think of semicolons as the end of a statement, not a delimiter between statements.

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".

Re: Such a Little Thing: The Semicolon in Rust

#46
post #10

Earlier quoted context omitted.

Hello American. I'm from one of those other pesky countries that make up most of the human population of earth, and which usually have other keyboard layouts. I have to type shift+, to get the semicolon.

A potential workaround is to always use an American keyboard. It's what I do.

Indeed. On a Swedish keyboard the semicolon is not the biggest problem though. {}[] are since you need to press right-alt+number keys to get them. Really awful. It takes a very short time using an American keyboard for coding to realize its benefits.

Still, even on an American keyboard () are not terribly well placed.

I've been thinking about adopting the NEO2 layout(with some modification so that I get all of åäö) but haven't gotten around to it yet. Has anyone tried that for programming?

Re: Such a Little Thing: The Semicolon in Rust

#47
post #5

Is that really some "special behavior"? As far as i understand the semicolon is just an expression separator like in Erlang and Pascal. In contrast, the semicolon is a statement terminator in C. C uses the comma for expression separation. Practically everything is an expression in Rust, even blocks, so foo() => evaluates to the return value of foo { foo() } => evaluates to the return value of foo { foo(); } => evalua…

There was some discussion about doing this in D, and there was some in C++11, too. I argued that the presence or absence of the ; did not visually stand out very well, and so would be a source of confusion and errors. Hence, ; remained as a statement terminator, and the return keyword served to indicate returning an expression. However, the D lambda syntax does not require a ; when the lambda body consists of only a…

An understandable point of view.

Though I can think of an even more crazy variation. Declare the semicolon a binary operator and allow overloading it.

As funny as that sounds, Haskell provides something like this, as do-notation can behave differently depending on the monad it is in.

Re: Such a Little Thing: The Semicolon in Rust

#48

Earlier quoted context omitted.

A potential workaround is to always use an American keyboard. It's what I do.

Indeed. On a Swedish keyboard the semicolon is not the biggest problem though. {}[] are since you need to press right-alt+number keys to get them. Really awful. It takes a very short time using an American keyboard for coding to realize its benefits. Still, even on an American keyboard () are not terribly well placed. I've been thinking about adopting the NEO2 layout(with some modification so that I get all of åäö) b…

Hej!

I have all my symbol characters easily accessible from the normal A-Z keys using a third shift state. It's awesome, and works with any keyboard layout (QWERTY, or even Swedish QWERTY are all fine, as is Dvorak, Colemak etc). Typing a previously uncomfortable sequence like "for (int i = 0; i It takes about two weeks to get used to. If you try it, make sure the third shift state can be accessed from either hand (i.e. you have to have left and right keys, just like with shift or control).

I wasn't aware of NEO2 so I developed my own symbol layout using a genetic algorithm running over my code corpus, then adjusting to taste.

Re: Such a Little Thing: The Semicolon in Rust

#49

Earlier quoted context omitted.

There was some discussion about doing this in D, and there was some in C++11, too. I argued that the presence or absence of the ; did not visually stand out very well, and so would be a source of confusion and errors. Hence, ; remained as a statement terminator, and the return keyword served to indicate returning an expression. However, the D lambda syntax does not require a ; when the lambda body consists of only a…

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?

Re: Such a Little Thing: The Semicolon in Rust

#50
post #34

Earlier quoted context omitted.

Just like Python, Haskell only ever has significant indentation.

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.
Post reply on HN