Live data from Hacker News

Such a Little Thing: The Semicolon in Rust

lucumr.pocoo.org

31–40 of 81 posts

Re: Such a Little Thing: The Semicolon in Rust

#31
post #23
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…

That's what makes it elegant: it lets you omit the return statement (safely) but otherwise looks exactly the same as C, even though it's semantically different.

parsimony =/= elegance

Re: Such a Little Thing: The Semicolon in Rust

#32
post #2

I memorably referred to Rust's significant semicolons as "the worst thing in the language" after my very first read through the tutorial, last November. Almost a year later, I'm just as in love with Rust's semicolon rules as Armin is. However, I bet new users will still be just as instinctively revolted as I initially was.

I guess it depends on what languages you're experienced with. I just read through the Rust tutorial for the first time 2 days ago, and I fell in love with the semicolon rule at first sight.

Re: Such a Little Thing: The Semicolon in Rust

#33
post #23

Earlier quoted context omitted.

That's what makes it elegant: it lets you omit the return statement (safely) but otherwise looks exactly the same as C, even though it's semantically different.

parsimony =/= elegance

Uh, it depends on taste. There are a few reasons to want it, such as lambdas as WalterBright mentioned, but I like it because when this is done in a language where statements and expressions are unified, ";" can neatly replace "," from C, and comma can be reused for something else. (Unifying statements and expressions has its own benefits, but we can start with avoiding GNU C's hideous "({ foo; bar; })", which evaluates to the value of bar...)

Re: Such a Little Thing: The Semicolon in Rust

#34
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...

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

Re: Such a Little Thing: The Semicolon in Rust

#35
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.

Which keyboard layout is that?

here's a bunch (scroll down)

http://keyboard-layout.info/

Re: Such a Little Thing: The Semicolon in Rust

#36
post #10

Are semicolons annoying to type? Probably, I got used to them The semicolon is the least-annoying non-letter character to type. It's right there on your home row.

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.

I feel your pain, I have to jump through all kinds of høøps to get some characters on my keyboård.

Re: Such a Little Thing: The Semicolon in Rust

#37
Is it just me or is this kind of ugly in the first place?

We're trying to mix logic that executes on each element in a sequence, with logic that controls how to iterate over that sequence. That is, a "return 42" statement will tell .each to stop iterating, but its contained within a block that is supposed to do things to individual elements.

The mathematical concept just doesn't sit right with me.. I guess if all you have as an iterator is 'each' then that would necessitate finding an additional way to modify iteration in some way, but still.. I don't like the fact that a return statement can break out of something outside of its own scope

edit: even the low-level alternative seems nicer

    for(blah;blah;blah) { 
        stuff;
    }

Re: Such a Little Thing: The Semicolon in Rust

#38
post #24
post #13

Take a look at Haskell for a very clean and expressive syntax without (required) semicolons.

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.

Re: Such a Little Thing: The Semicolon in Rust

#40
post #10

Are semicolons annoying to type? Probably, I got used to them The semicolon is the least-annoying non-letter character to type. It's right there on your home row.

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.

I switch from my native layout to the US layout for coding.
Post reply on HN