martes, 13 de enero de 2015

En que anda Rust?


Recuerdan a Rust? La verdad es que me había olvidado de este lenguaje, fue que en la encuesta de infoQ sobre "quien ocupara el lugar de C?" lo vi. Ahora tuve un poco de tiempo y decidí ver en que andaba...

Para los que no recuerdan Rust es un lenguaje similar a C pero más evolucionado, con muchas características interesantes. Como por ejemplo pattern matching, inferencia de tipo, clausuras, etc...

A la vez es multiparadigma, se puede programar de modo funcional o imperativo y tambien orientado a objetos. Pero por ejemplo no se encuentra mucha info de la programación orientada a objeto en rust.

Yo lo veo como un c++++, es decir con capacidades que hacen fácil programar pero a la vez tiene una orientación a tareas de bajo nivel. A la vez existe mucha documentación, lo que hace de este lenguaje un digno competidor de go.

Por ultimo les dejo unos ejemplos de rustbyexample :

// This is a comment, and will be ignored by the compiler
// You can test this code by clicking the "Run" button over there ->
// or if prefer to use your keyboard, you can use the "Ctrl + Enter" shortcut

// This code is editable, feel free to hack it!
// You can always return to the original code by clicking the "Reset" button ->

// This is the main function
fn main() {
    // The statements here will be executed when the compiled binary is called

    // Print text to the console
    println!("Hello World!");
}

Otro ejemplo:

fn main() {
    let x = 5u32;

    let y = {
        let x_squared = x * x;
        let x_cube = x_squared * x;

        // This expression will be assigned to `y`
        x_cube + x_squared + x
    };

    let z = {
        // The semicolon suppresses this expression and `()` is assigned to `z`
        2 * x;
    };

    println!("x is {:?}", x);
    println!("y is {:?}", y);
    println!("z is {:?}", z);
}

Otro ejemplo:

fn main() {
    let number: i32 = 13;
    // TODO ^ Try different values for `number`

    println!("Tell me about {}", number);
    match number {
        // Match a single value
        1 => println!("One!"),
        // Match several values
        2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
        // Match an inclusive range
        13...19 => println!("A teen"),
        // Handle the rest of cases
        _ => println!("Ain't special"),
    }

    let boolean = true;
    // Match is an expression too
    let binary: i32 = match boolean {
        // The arms of a match must cover all the possible values
        false => 0,
        true => 1,
        // TODO ^ Try commenting out one of these arms
    };

    println!("{} -> {}", boolean, binary);
}

Dejo link:
https://github.com/rust-lang/rust
http://doc.rust-lang.org/book/
http://www.rust-lang.org/
http://rustbyexample.com/

No hay comentarios.:

Publicar un comentario