ECS 36A Lecture Notes - Lecture 12: Integer Overflow, Database Server, Type Inference

151 views4 pages
9 Nov 2018
ECS 36A - Lecture 12 - Types, Variables, Control Flow in Rust
Why our focus is shifting to Rust and away from Python:
- Python was a decent language in the 1990s
- There is no integer overflow in python, integer can be of arbitrary length = a pro
- Programmer can’t provide detailed information to compiler,compiler can’t
aggressively optimize
- Not good b/c don’t have to worry about memory or runtime -- garbage collection
- Makes programs easier, but also more inefficient
- When accessing index, python will check if index is out of bound → avoids index
- Iterator validation -- end up in infinite loops (python can’t do anything about it)
- Not easy to write concurrent programs to take advantage of multiple cores on
- Python isn’t applicable to certain things like databases in the real world --never heard of
efficient database server implemented in Python -->nor web servers and never an
operating system in Python
Qualities of an efficient language:
Doesn’t have garbage collection, program has to manage memory themselves
In C, you have to allocate and deallocate yourself
C++: sometimes the compiler can help you deallocate memory ,
dangerously, doesn’t make sure if other parts of the program can use that
= serious security vulnerability (slightly better than C)
Rust MAKES you allocate memory
Learning how Rust avoids most memory-management problems while being almost as efficient
as C/C++
- Rust is a kernel -- manages the operations of the computer and the hardware - most
notably memory and CPU time
- Mozilla is used in Rust to implement Firefox
Integer Overflow Examples in Rust: (didn’t see examples bc won’t see these in python)
Let x: i8 = 127; in rust, you have to bind each variable
& each variable needs a type
Let y = x+1_i8 type inference: sees x which is i8 → so assumes answer should be i8
x = “foo” python catches no error, whereas rust sees that “foo” is not an i8
Let x: i8 = 127;
Let y = x+ “foo” type mismatch again, rust knows you cannot add integer & string
Can explicitly declare type of variable when introduced
In general, compiler cannot recognize integer overflow at Compile Time → will check at runtime
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.