Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rustlang for students

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Rustlang for students

Rustlang presentation at converge conf 2017,kakinada

Avatar for krishna kumar T

krishna kumar T

December 16, 2017

Other Decks in Programming

Transcript

  1. About me q I am Krishna Kumar. q Worked in

    TCS as Erlang Developer. q Currently working as application developer/consultant at Thoughtworks. Free time: q Robotics q Industrial automation q 3D animation and graphics q Embedded systems.
  2. Segmentation Fault ØDereference a null pointer ØModifying the read only

    code ØRunning outside array bounds ØIllegal memory access ØAnd so on….
  3. Rust features ØImmutability by default. ØOwnership and borrowing. ØChannels for

    concurrency. ØTraits for extensibility. ØZero cost abstractions. ØType inference as much as possible. ØNo GC.
  4. Ownership ØExplicit memory deallocation – Low level languages like C/C++

    ØAutomatic Garbage collection – High level languages like Java, Python, Go and any language with a runtime ØNo Garbage collection – Rust approach
  5. Stack and heap Both are used at runtime Stack: ◦

    LIFO ◦ Each frame is fixed size ◦ Faster – as one place for pushing and popping the data Heap: ◦ Size is only known at runtime. ◦ Less organized – slower to respond. ◦ Allocation – Find suitable memory location for the size, mark the location as in use, return the pointer on to the stack
  6. Strings - Immutable by default - Directly stored as text

    in the executable - No runtime overhead of allocating on heap String literals: String Type: - Can be mutated - Allocated on heap at runtime - Drop is added to end of the scope during compile time to deallocate as soon as moves out of scope.
  7. Advantages of ownership ØWhat data is actively being used by

    the code/runtime. ØMinimizing duplicate data on heap. ØCleaning up data end of lifetime.
  8. Rules of ownership Each value has a variable(owner). Each value

    has only one owner at a time. Value is dropped when owner / variable goes out of scope.
  9. Enums enum Option<T> { Some(T), None, } Ø Value could

    be something or nothing. Ø Unwrap method on Option panics if it returns None.
  10. Enums enum Result<T,E> { Ok(T), Err(E), } ØReturns a value

    or an error ØUsed for recoverable errors
  11. Unrecoverable error with panic! Ø Unwinds the stack Ø Function

    data cleanup Ø Prints error message and Ø Quits
  12. Iterators Ø Iterators are lazy by default. Ø Cannot run

    out of bounds and hence no segmentation faults.
  13. Thread Communication - Channels Do not communicate by sharing memory;

    instead, share memory by communicating. – Effective Go
  14. More about concurrency ØARC<T> might cause dead locks ØAll the

    concurrency primitives are just libraries and hence more improvement may come soon. ØThere is still scope for improvement in rust concurrency primitives. ØYou can also contribute.
  15. Add ons ØRayon is data parallelism library which is widely

    used. ØThere is an operating system in rust called REDOX os. ØRocket, Nickel are some of the webservers in rust. ØCargo is the package manager for rust. ØTokio is a networking library for rust.
  16. Friends of Rust npm, Inc : Replacing C and rewriting

    performance-critical bottlenecks in the registry service architecture. Dropbox : Optimizing cloud file-storage. Atlassian : We use Rust in a service for analyzing petabytes of source code. Many more…. @ https://www.rust-lang.org/en-US/friends.html