Announcement

Collapse
No announcement yet.

Rust 1.21 Released With Minor Updates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • caligula
    replied
    Originally posted by uid313 View Post

    Implicit return statements.
    This is pretty ridiculous. You're giving Ruby way too much credit. Lisp is second-oldest of the programming languages and it had implicit return statements. Well, it doesn't have statements, for that matter, but the idea is there. Such functionality has since 1958 existed in many higher level languages. Ruby did not invent anything.

    Leave a comment:


  • Khrundel
    replied
    Originally posted by uid313 View Post

    Implicit return statements.
    Many modern languages support implicit returns from lambda functions. Rust was designed when lambdas became popular, so it's authors were able to offer short lambdas and solid syntax both. And also implicit return allowed to get rid of ternary operator.

    Leave a comment:


  • uid313
    replied
    Originally posted by unixfan2001 View Post

    Can you please stop comparing it to Ruby or, at the very least, try to explain why exactly you think it looks like that?
    I (and, from the looks of it, quite a few others) just can't see it. The syntax has far more in common with Haskell and similar, functional languages.
    Implicit return statements.

    Leave a comment:


  • Luke_Wolf
    replied
    Originally posted by caligula View Post

    Now do the same without the typedef. It's cheating. The problem here is, C's syntax is totally backwards. For documenting the type, you're better off writing the comments in Rust. Maybe you can handle it, but there are lots of programmers totally lost with this syntax, yet they are fully able to implement monads in Haskell.
    Nope, that's not cheating, any more than this is cheating the lack of the ternary operator:
    Code:
    let i = 5;
    let x = if i == 5 { 3} else { 4 };
    it's just C being C and just how it's done, it won't compile without it, but in a theoretical C where it does compile, since I was talking about the syntactic style as opposed to the language it's just:
    Code:
    int (*return_func) (int) function (int (*input_function) (int) ) {
        //stuff
    }
    Now yeah that's a bit hairy, it really doesn't look nice, but just like with ternary operators anyone who knows what a function pointer looks like knows whats going on here. However since the problem isn't the function signature style but the function pointer declaration syntax, there's plenty of options for non-Rust Syntax alternatives... for example taking a cue from C++ lamda expression:
    Code:
    [](int)->int function ([](int)->int input_function) {
        //stuff
    }
    which is quite clear and still C-Style syntax, it's just not C, much like the earlier C++ example was clear and C-Style syntax but not C. The question is not "is C perfect?" (I'm really not a fan of C itself personally), but rather "Is there an intrinsic expressiveness that Rust syntax has over C-Style syntax where their features are the same but the syntax is divergent? " and corollary to that "For the features that are the same is Rust style syntax necessary to express things" and the answer is simply no.

    Note that we are purely discussing syntax here, Rust and basically every other language other than C++ has vastly superior semantics surrounding strings among other things, and both .NET languages and Rust have a superior vocabulary regarding primitive types.

    Leave a comment:


  • caligula
    replied
    Originally posted by Luke_Wolf View Post
    in C
    Code:
    typedef int (*return_func)(int);
    return_func function(int (*input_function)(int)) {
    //stuff
    }
    Now do the same without the typedef. It's cheating. The problem here is, C's syntax is totally backwards. For documenting the type, you're better off writing the comments in Rust. Maybe you can handle it, but there are lots of programmers totally lost with this syntax, yet they are fully able to implement monads in Haskell.
    Last edited by caligula; 13 October 2017, 04:51 PM.

    Leave a comment:


  • Luke_Wolf
    replied
    Originally posted by uid313 View Post

    I don't know if that is any useful or good, but that is very confusing for me who are mostly used to the languages of C, C++, C#, Java and PHP.
    Or... you could just read The Book as opposed to trying to just wade into code... https://doc.rust-lang.org/book/second-edition/

    just wading into code may work okay when you're shifting from one C Family language to another, but Rust is not a C Family language, and even within C family languages it benefits you greatly to at least read some of the docs before you dive in. Impl isn't confusing at all if you use even a minimum of due diligence in learning the language

    Leave a comment:


  • Luke_Wolf
    replied
    Originally posted by caligula View Post

    Try to express (i32 -> i32) -> (i32 -> i32) in C.
    in C
    Code:
    typedef int (*return_func)(int);
    return_func function(int (*input_function)(int)) {
        //stuff
    }
    or in C++
    Code:
    std::function<int (int)> function (std::function<int (int)> input){
        //stuff
    }

    Leave a comment:


  • uid313
    replied
    Originally posted by Khrundel View Post
    It is a keyword used to add "methods", including associated (i.e. static) to a type.
    impl MyType {...} - adds methods to a type "MyType".

    impl SomeTrait for SomeType {...} - adds implementation of SomeTrait (i.e. interface) to SomeType. Unlike other languages, where you can only implement interfaces for your type, Rust allows you to add implementation of interfaces from your module to any type, including foreign. So, you can create trait Foo, implement it for i32 (builtin type for 32-bit int), then cast pointer to i32 to pointer to Foo and then use that pointer OOP like way, as if Foo is a base class for i32.
    I don't know if that is any useful or good, but that is very confusing for me who are mostly used to the languages of C, C++, C#, Java and PHP.

    Leave a comment:


  • unixfan2001
    replied
    Originally posted by uid313 View Post

    Good point.
    I could guess "Impl" was short for Implement, but I still don't know what it does or what it means.
    Like is it a class, a interface or a trait or something else?

    I wish Rust was more like C, C++, C#, Java, and PHP and that it was less like Ruby.
    Can you please stop comparing it to Ruby or, at the very least, try to explain why exactly you think it looks like that?
    I (and, from the looks of it, quite a few others) just can't see it. The syntax has far more in common with Haskell and similar, functional languages.

    Leave a comment:


  • Khrundel
    replied
    Originally posted by uid313 View Post
    I could guess "Impl" was short for Implement, but I still don't know what it does or what it means.
    Like is it a class, a interface or a trait or something else?
    It is a keyword used to add "methods", including associated (i.e. static) to a type.
    impl MyType {...} - adds methods to a type "MyType".

    impl SomeTrait for SomeType {...} - adds implementation of SomeTrait (i.e. interface) to SomeType. Unlike other languages, where you can only implement interfaces for your type, Rust allows you to add implementation of interfaces from your module to any type, including foreign. So, you can create trait Foo, implement it for i32 (builtin type for 32-bit int), then cast pointer to i32 to pointer to Foo and then use that pointer OOP like way, as if Foo is a base class for i32.

    Leave a comment:

Working...
X