Python Forum
alternative to python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
alternative to python
#31
(Nov-06-2016, 06:55 PM)micseydel Wrote: I've heard that Rust is largely replacing C. Assembly I think is useful for learning more about hardware, which is great, but shouldn't be misunderstood as (generally) useful. JS is a necessary evil right now  :(

So I've been reading the Rust Book (https://doc.rust-lang.org/book/), and Rust is a crazy impressive language.  Everything is immutable by default, and objects have a sense of 'ownership' and scope, which the compiler enforces, which makes cleanup easy.  What I like is the way error handling is done... a given function can only raise a single type of error, if you want to return more than one, you need to create a new error type to represent it.  If a function CAN return an exception, the compiler FORCES you to handle it (even if handling it is just re-raising it).

And almost everything is an expression.  It almost feels like ruby, in that the last line of a function is that function's return value, even if you don't explicitly use the keyword "return".  And almost everything returns a value... like match (their switch/case), or if.  So you can do things like...
// this is a complete program
// writes "The value: foobar" to console

fn main() {
    let spam = "eggs";
    let some_value = match spam {
        "12" => "twelve",
        "eggs" => "foobar",
        _ => "default value"
    };

    println!("The value: {}", some_value);
}
Reply
#32
Wow, that match looks like an awful lot like Scala. But yeah, that's what I've heard about Rust being so powerful, is that you get a lot of compile-time guarantees about correctness.
Reply
#33
match can do more impressive things, like do pattern matching (...so can let, for that matter), but I tried to keep it simple so as to avoid confusion.  But it seems to do a lot of things specifically to be safe, so almost no errors can bubble up at runtime.  All while having for loops that look almost exactly like python syntax lol.  I'm still reading, but I'm liking what I've seen so far.

The only thing I'm not sure how I feel about yet, is that any ffi call has to be wrapped in an "unsafe" block, so the compiler knows that you know that it can't verify the safety of whatever the other language is doing.  It makes code look unnecessarily dangerous.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020