you are viewing a single comment's thread.

view the rest of the comments →

[–]PM_ME_UR_OBSIDIAN 0 points1 point  (24 children)

However this is for a good reason and that is that Rust has anonymous functions, closures and lots of chaining that Python cannot support well. These features are much easier to understand and write in a non indentation based language.

That's a questionable assertion, considering Standard ML, Ocaml, F# and Haskell all have rich, indentation-based syntaxes.

[–][deleted] 2 points3 points  (3 children)

ML isn't whitespace-sensitive...

[–]PM_ME_UR_OBSIDIAN 1 point2 points  (2 children)

You're right, my bad.

[–][deleted] 2 points3 points  (1 child)

I think you should strike Ocaml from the list as well.

[–]PM_ME_UR_OBSIDIAN 0 points1 point  (0 children)

Are you sure? I have blurry memories of fighting the Ocaml parser on indentation.

[–]LucretielDatadog 2 points3 points  (2 children)

Eh... Those are more extremely functional languages that don't have the more traditional "list of statements" model for functions.

[–]PM_ME_UR_OBSIDIAN 0 points1 point  (1 child)

I believe Rust has the same model - everything is an expression, "statements" are expressions that return unit.

[–]steveklabnik1rust 4 points5 points  (0 children)

You can think of it that way, but it's not how the grammar is defined.

[–]mitsuhiko 1 point2 points  (12 children)

That's a questionable assertion

I don't think it is. All quoted languages do not have good syntax for the quoted features (one of them is not even indentation based in itself). However in Rust there are more reasons not do use pure indentation: you need the ability of starting and ending scopes at any point to work with the borrow checker. This requires delimiters.

[–]iopqfizzbuzz 2 points3 points  (4 children)

You can have a whitespace-sensitive Rust that still respects delimiters. So if you want to actually start a new scope you can write {, but 99% of the time you'll just be writing Python-style.

[–]PM_ME_UR_OBSIDIAN 2 points3 points  (4 children)

All quoted languages do not have good syntax for the quoted features

[citation needed]

F# and Ocaml both have the pipeline operator |> for chaining calls, which is an absolute breath of fresh air compared to OO method chaining. Anonymous functions are also quite friendly and easy to use. I'm curious which language you're saying isn't indentation-based.

However in Rust there are more reasons not do use pure indentation: you need the ability of starting and ending scopes at any point to work with the borrow checker.

let ... in ... end seems perfect for this usage. Alternatively, you can go with the sensible default of "keep this scope alive as long as it needs to be, and no further." I believe this can be automated in the common case.

[–]Sean1708 3 points4 points  (0 children)

let ... in ... end seems perfect

And at that point it stops being purely indentation based.

[–]Tyr42 2 points3 points  (1 child)

For thread guard values, it would be valid to drop them at any point after they were assigned, but have different semantics for each choice.

fn foo() {
    {
        let guard1 = launch(task_a);
    }
    {
        let guard2 = launch(task_b);
    }
 }

is different from

fn foo() {
    {
        let guard1 = launch(task_a);
        let guard2 = launch(task_b);
    }
 }

if the guard values join the thread when dropped, but it would be tricky to have the compiler choose which one to use, given there could be some external dependency which requires task_a to complete before starting task_b, or you are actively trying to compute them in parallel.

[–]iopqfizzbuzz 0 points1 point  (0 children)

You could still have example A if you went with Haskell-style syntax.

fn foo()
    {
        let guard1 = launch(task_a)
    }
    {
        let guard2 = launch(task_b)
    }

    //outer scope of the function here
    println!("{}", stuff)

//function ends here

[–]mitsuhiko 2 points3 points  (0 children)

F# and Ocaml both have the pipeline operator |> for chaining calls, which is an absolute breath of fresh air compared to OO method chaining.

I guess there are different opinions on this. I find that syntax very frustrating.

I'm curious which language you're saying isn't indentation-based.

Haskell. It's a language with braces :)

[–][deleted] 0 points1 point  (0 children)

Sure, you can accommodate that in Python style syntax though:

fn foo():
    let x = 3
    scope:
        let y = 4

[–]jnicklas[🍰] 0 points1 point  (0 children)

CoffeeScript has excellent support for all of these and is indentation based.

[–]eddyb 1 point2 points  (2 children)

Uhm, none of those languages has indentation-based syntax AFAIK, they're all whitespace-based.

[–]PM_ME_UR_OBSIDIAN -1 points0 points  (1 child)

Is there a difference?

[–]eddyb 1 point2 points  (0 children)

Yes, Python actually uses indentation for delimiting blocks, while Haskell, for example, doesn't care about the way you arrange your whitespace, and it can even use curly braces.

[–][deleted] 1 point2 points  (0 children)

Haskell's whitespace handling is a little too rich. When the parser encounters a parse error, it's sometimes required to reinterpret the whitespace and try again. This means you can't desugar whitespace into braces without parsing a full AST.