Live data from Hacker News

Such a Little Thing: The Semicolon in Rust

lucumr.pocoo.org

71–80 of 81 posts

Re: Such a Little Thing: The Semicolon in Rust

#71
post #44

I'm all with the author with the Ruby love and it looks like Rust managed to implement them in a cleaner syntactic way compared to Ruby. However, that template code was utterly hideous.

Normally in Rust you'd never use a trait like that without bringing it into the local namespace, so you wouldn't need to qualify it with its module like Armin does. And in future versions of Rust, Num will inherit from both the Eq and Copy traits, so the signature would instead look like this:

  fn find_even(vec: &[T]) -> Option {

Re: Such a Little Thing: The Semicolon in Rust

#72
My kingdom for a TL;DR!

(As a prerequisite to making its point, the article teaches many intricate details regarding two dynamic languages which even most of their practitioners probably never think about, then dives into more intricate details regarding a language which most of us have probably never even used, let along grokked all the details of. I sense that there's something important here for me to learn, but from where I sit this article is a lot to bite off all at once.)

A tight summary by someone who understands all this would be appreciated by many readers, not just myself.

Re: Such a Little Thing: The Semicolon in Rust

#73
"But the alternative to semicolons is making line endings significant."

Only sorta - consider Haskell's indent rule: code which is part of an expression should be indented further than the start of that expression. Generally, this is something you should be doing to make your code readable regardless of the statement termination.

Re: Such a Little Thing: The Semicolon in Rust

#75
post #67

Earlier quoted context omitted.

Ruby and CoffeeScript do and their syntax relies heavily on it.

For Ruby at least "heavily" is a big exaggeration. It is significant as a token separator and in cases where inserting a line break makes the expression up to the line break a valid expression in itself, in which case it is treated as one. You pretty much only need to remember to separate tokens where lack of whitespace might create a different vald token, and ensure any expressions that you want to let span more tha…

`foo()` and `foo ()` are different things in ruby, so are `foo[x]` and `foo [x]`. That is significant whitespace.

Re: Such a Little Thing: The Semicolon in Rust

#76

As an aside, the "power_it" function in Python can also be written as: map(lambda t: t ** 2, [1,2,3,4]) or even: [(lambda t: t**2)(x) for x in [1,2,3,4]]

> [(lambda t: t2)(x) for x in [1,2,3,4]]

Why would you have that lambda?

    [x**2 for x in range(1, 5)]

Re: Such a Little Thing: The Semicolon in Rust

#77

My kingdom for a TL;DR! (As a prerequisite to making its point, the article teaches many intricate details regarding two dynamic languages which even most of their practitioners probably never think about, then dives into more intricate details regarding a language which most of us have probably never even used, let along grokked all the details of. I sense that there's something important here for me to learn, but f…

> A tight summary by someone who understands all this would be appreciated by many readers, not just myself.

A tight summary of all of it would be as long as the article. However, the point about semicolons in Rust is:

1. ; is a separator, not a terminator.

2. a;b separates a and b.

3. a; is a special case which means a;nil(or whatever is the equivalent in Rust)

4. The last expression in a function will be the return value of the function.

5. If the last line in a function is "a", it returns a. If it's "a;", it returns nil(from 3)

Re: Such a Little Thing: The Semicolon in Rust

#78
post #77

My kingdom for a TL;DR! (As a prerequisite to making its point, the article teaches many intricate details regarding two dynamic languages which even most of their practitioners probably never think about, then dives into more intricate details regarding a language which most of us have probably never even used, let along grokked all the details of. I sense that there's something important here for me to learn, but f…

> A tight summary by someone who understands all this would be appreciated by many readers, not just myself. A tight summary of all of it would be as long as the article. However, the point about semicolons in Rust is: 1. ; is a separator, not a terminator. 2. a;b separates a and b. 3. a; is a special case which means a;nil(or whatever is the equivalent in Rust) 4. The last expression in a function will be the return…

Perfect, thank you.

Re: Such a Little Thing: The Semicolon in Rust

#79

My kingdom for a TL;DR! (As a prerequisite to making its point, the article teaches many intricate details regarding two dynamic languages which even most of their practitioners probably never think about, then dives into more intricate details regarding a language which most of us have probably never even used, let along grokked all the details of. I sense that there's something important here for me to learn, but f…

I don't think parent deserves to be modded down. The article did take a pretty long time to get to the point.

Why all this talk about Python and Ruby? Rust is not really competing with those languages-- it is quite specifically designed as a C++ replacement. They should be comparing themselves against C++, Golang, or D.

The Golang solution would just be a function which returns the next element or nil if there are no more elements. That function might be part of an interface, if you wanted to generalize it across several types. To me, this is a lot simpler than the other stuff that was discussed.

To go back to Rust specifically, rather than having magic semicolons, why not make the "break" statement take a value, which becomes the return value of the block? Despite all the tl;dr there was not much discussion of design alternatives.

Re: Such a Little Thing: The Semicolon in Rust

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

Nitpick: Almost. There is a Dutch keyboard layout, but nobody uses it. Nobody, as in, there's more people in the Netherlands that use Dvorak than people that use the Dutch keyboard layout.

The Dutch commonly use the US keyboard layout, which makes sense because Dutch and English have the same alphabet.

Post reply on HN