SlideShare une entreprise Scribd logo
1  sur  64
Télécharger pour lire hors ligne
@brian_pearce
LEARNING TO
THE UNFAMILIAR
Love
with @brian_pearce
@brian_pearce
@brian_pearce
@brian_pearce
@brian_pearce
LEARNING TO
THE UNFAMILIAR
Love
with @brian_pearce
@brian_pearce
Steep learning curve
at the beginning
1 in 4 People
“
”
- State of Rust Survey 2016
@brian_pearce
@brian_pearce
def read_file()
with open('my_file.txt') as file:
for line in file: process(line)
def process(line)
if is_a_pun(line):
tell_a_friend()
Python
@brian_pearce
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap();
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
}
}
fn process(line: &str) {
if is_a_pun(line) {
tell_a_friend();
}
}
Rust
@brian_pearce
def read_file(argv)
with open('my_file.txt') as file:
for line in file: process(line)
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap();
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
}
}
Python
Rust
@brian_pearce
def read_file(argv)
with open('my_file.txt') as file:
for line in file: process(line)
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap();
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
}
}
Python
Rust
@brian_pearce
Introducing:
The Maybe type
*star wipe*
@brian_pearce
Maybes in the
form of:
Option & Result
@brian_pearce
enum Option<T> {
Some(T),
None
}
Option:
@brian_pearce
Ruby
irb> '7'.to_i
@brian_pearce
Ruby
irb> '7'.to_i
=> 7
@brian_pearce
Ruby
irb> '7'.to_i
=> 7
irb> '❤'.to_i
@brian_pearce
Ruby
irb> '7'.to_i
=> 7
irb> '❤'.to_i
=> 0
@brian_pearce
Ruby
irb> '7'.to_i
=> 7
irb> '❤'.to_i
=> 0
irb> '4520000011112222'.to_i
=> 4520000011112222
@brian_pearce
Ruby
irb> '7'.to_i
=> 7
irb> '❤'.to_i
=> 0
irb> '4520000011112222'.to_i
=> 4520000011112222
irb> '4520not_a_num2'.to_i
@brian_pearce
irb> '7'.to_i
=> 7
irb> '❤'.to_i
=> 0
irb> '4520000011112222'.to_i
=> 4520000011112222
irb> '4520not_a_num2'.to_i
=> 4520
Ruby
@brian_pearce
Rust
rust> '7’.to_digit(...)
@brian_pearce
Rust
rust> '7’.to_digit(...)
=> Some(7)
@brian_pearce
Rust
rust> '7’.to_digit(...)
=> Some(7)
rust> '❤'.to_digit(...)
@brian_pearce
Rust
rust> '7’.to_digit(...)
=> Some(7)
rust> '❤'.to_digit(...)
=> None
@brian_pearce
Rust
rust> '7’.to_digit(...)
=> Some(7)
rust> '❤'.to_digit(...)
=> None
rust> “4520000011112222”.to_digit(...)
=> Some(4520000011112222)
@brian_pearce
Rust
rust> '7’.to_digit(...)
=> Some(7)
rust> '❤'.to_digit(...)
=> None
rust> “4520000011112222”.to_digit(...)
=> Some(4520000011112222)
rust> “4520not_a_num2”.to_digit(...)
@brian_pearce
rust> '7’.to_digit(...)
=> Some(7)
rust> '❤'.to_digit(...)
=> None
rust> “4520000011112222”.to_digit(...)
=> Some(4520000011112222)
rust> “4520not_a_num2”.to_digit(...)
=> None
Rust
@brian_pearce
Rust
rust> '7’.to_digit(...).unwrap()
@brian_pearce
Rust
rust> '7’.to_digit(...).unwrap()
=> 7
@brian_pearce
Rust
rust> '7’.to_digit(...).unwrap()
=> 7
rust> '❤'.to_digit(...).unwrap()
@brian_pearce
rust> '7’.to_digit(...).unwrap()
=> 7
rust> '❤'.to_digit(...).unwrap()
=> thread 'main' panicked at 'called
`Option::unwrap()` on a `None` value'
Rust
@brian_pearce
puts "Enter a number"
num = gets.chomp.to_i
if num.is_a?(Numeric)
puts "Great number choice: #{num}"
else
puts "That wasn't a number"
end
Ruby
@brian_pearce
Ruby
puts "Enter a number"
num = gets.chomp.to_i
if num.is_a?(Numeric)
puts "Great number choice: #{num}"
else
puts "That wasn't a number"
end
@brian_pearce
Rust
fn main() {
println!("Enter a number");
let mut input = String::new();
io::stdin().
read_line(&mut num).unwrap();
let int = num.to_digit(10).unwrap();
println!("Great number choice: {}", int);
}
@brian_pearce
fn main() {
println!("Enter a number");
let mut input = String::new();
io::stdin().
read_line(&mut num).unwrap();
let maybe = num.to_digit(10);
if maybe.is_some() {
let i = maybe.unwrap();
println!("Great number choice: {}", i);
} else if maybe.is_none() {
println!("That wasn't a number");
};
}
Rust
@brian_pearce
fn main() {
println!("Enter a number");
let mut input = String::new();
io::stdin().
read_line(&mut num).unwrap();
let maybe = num.to_digit(10);
if maybe.is_some() {
let i = maybe.unwrap();
println!("Great number choice: {}", i);
} else if maybe.is_none() {
println!("That wasn't a number");
};
}
Rust
@brian_pearce
fn main() {
println!("Enter a number");
let mut input = String::new();
io::stdin().
read_line(&mut num).unwrap();
let maybe = num.to_digit(10);
match maybe {
Some(n) => {
println!("Great number choice: {}", n);
},
None => {
println!("That wasn't a number");
}
};
Rust
@brian_pearce
thread '<unnamed>' panicked at 'cannot access a TLS value during
../src/libcore/option.rs:330
fatal runtime error: Could not unwind stack, error = 5
thread'<unnamed>'panickedat'cannotaccessaTLSva
fatalruntimeerror:Couldnotunwindstack,error=5
Error Handling
@brian_pearce
try {
} catch {
}
Java
@brian_pearce
begin
rescue
end
Ruby
@brian_pearce
try:
expect:
Python
@brian_pearce
try!(my_func())
@brian_pearce
enum Result<T, E> {
Ok(T),
Err(E)
}
Result
@brian_pearce
def read_file(argv)
try:
with open('my_file.txt') as file:
for line in file: process(line)
except:
# Failure
Python
@brian_pearce
Rust
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap()
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
}
@brian_pearce
Rust
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap()
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
}
@brian_pearce
Rust
fn read_file() {
let mut data = String::new();
let mut f = File::open("my_file.txt").unwrap()
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
}
@brian_pearce
Rust
fn read_file() -> Result<String, String> {
let mut data = String::new();
let mut f = try!(File::open("my_file.txt"));
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
}
@brian_pearce
Rust
fn read_file() -> Result<String, String> {
let mut data = String::new();
let mut f = try!(
File::open("my_file.txt").map_err(|e| e )
);
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
}
@brian_pearce
fn read_file() -> Result<String, String> {
let mut data = String::new();
let mut f = try!(
File::open("my_file.txt").map_err(|e| e )
);
f.read_to_string(&mut data).unwrap();
for line in data.lines() {
process(line);
};
Ok(“Success”)
}
Rust
@brian_pearce
fn my_func() { … }
#[test]
fn my_funct_test { … }
Testing
@brian_pearce
bash
@brian_pearce
def setup
@dir = '/tmp/rb_tests'
Dir.mkdir(@dir) unless File.directory?(@dir)
end
def teardown
FileUtils.rm_r(@dir)
end
def test_file_write_one
file_name = "#{@dir}/test_one"
File.open(file_name, 'w') { |f| f.write "I failed a google code interview" }
assert File.exists?(file_name)
end
def test_file_write_two
file_name = "#{@dir}/test_two"
File.open(file_name, 'w') { |f| f.write "had a mixup with the interviewer" }
assert File.exists?(file_name)
end
def test_file_write_three
file_name = "#{@dir}/test_three"
File.open(file_name, 'w') { |f| f.write "a mis-understanding of sorts" }
end
Ruby
@brian_pearce
def setup
@dir = '/tmp/rb_tests'
Dir.mkdir(@dir) unless File.directory?(@dir)
end
def teardown
FileUtils.rm_r(@dir)
end
def test_file_write_one
file_name = "#{@dir}/test_one"
File.open(file_name, 'w') { |f| f.write "I failed a google code interview" }
assert File.exists?(file_name)
end
def test_file_write_two
file_name = "#{@dir}/test_two"
File.open(file_name, 'w') { |f| f.write "had a mixup with the interviewer" }
assert File.exists?(file_name)
end
def test_file_write_three
file_name = "#{@dir}/test_three"
File.open(file_name, 'w') { |f| f.write "a mis-understanding of sorts" }
end
Ruby
@brian_pearce
def setup
@dir = '/tmp/rb_tests'
Dir.mkdir(@dir) unless File.directory?(@dir)
end
def teardown
FileUtils.rm_r(@dir)
end
def test_file_write_one
file_name = "#{@dir}/test_one"
File.open(file_name, 'w') { |f| f.write "I failed a google code interview" }
assert File.exists?(file_name)
end
def test_file_write_two
file_name = "#{@dir}/test_two"
File.open(file_name, 'w') { |f| f.write "had a mixup with the interviewer" }
assert File.exists?(file_name)
end
def test_file_write_three
file_name = "#{@dir}/test_three"
File.open(file_name, 'w') { |f| f.write "a mis-understanding of sorts" }
end
Ruby
@brian_pearce
def setup
@dir = '/tmp/rb_tests'
Dir.mkdir(@dir) unless File.directory?(@dir)
end
def teardown
FileUtils.rm_r(@dir)
end
def test_file_write_one
file_name = "#{@dir}/test_one"
File.open(file_name, 'w') { |f| f.write "I failed a google code interview" }
assert File.exists?(file_name)
end
def test_file_write_two
file_name = "#{@dir}/test_two"
File.open(file_name, 'w') { |f| f.write "had a mixup with the interviewer" }
assert File.exists?(file_name)
end
def test_file_write_three
file_name = "#{@dir}/test_three"
File.open(file_name, 'w') { |f| f.write "a mis-understanding of sorts" }
end
Ruby
@brian_pearce
fn setup(dir: &String) {
let _ = fs::create_dir(dir)
}
fn teardown(dir: &String) {
let _ = fs::remove_dir(dir);
}
#[test]
fn test_file_write_one() {
let dir_name = format!("/tmp/rs_tests");
let dir = PathBuf::from(dir_name);
setup(&dir);
let file_name = format!("{}/{}", dir_name, "test_one");
let file = File::create(&file_name);
assert! file.exists();
teardown(&dir);
}
#[test]
fn test_file_write_two() {
...
}
Rust
@brian_pearce
fn setup(dir: &String) {
let _ = fs::create_dir(dir)
}
fn teardown(dir: &String) {
let _ = fs::remove_dir(dir);
}
#[test]
fn test_file_write_one() {
let dir_name = format!("/tmp/rs_tests");
let dir = PathBuf::from(dir_name);
setup(&dir);
let file_name = format!("{}/{}", dir_name, "test_one");
let file = File::create(&file_name);
assert! file.exists();
teardown(&dir);
}
#[test]
fn test_file_write_two() {
...
}
Rust
@brian_pearce
fn setup(dir: &String) {
let _ = fs::create_dir(dir)
}
fn teardown(dir: &String) {
let _ = fs::remove_dir(dir);
}
#[test]
fn test_file_write_one() {
let dir_name = format!("/tmp/rs_tests");
let dir = PathBuf::from(dir_name);
setup(&dir);
let file_name = format!("{}/{}", dir_name, "test_one");
let file = File::create(&file_name);
assert! file.exists();
teardown(&dir);
}
#[test]
fn test_file_write_two() {
...
}
Rust
@brian_pearce
fn setup(dir: &String) {
let _ = fs::create_dir(dir)
}
fn teardown(dir: &String) {
let _ = fs::remove_dir(dir);
}
#[test]
fn test_file_write_one() {
let dir_name = format!("/tmp/rs_tests");
let dir = PathBuf::from(dir_name);
setup(&dir);
let file_name = format!("{}/{}", dir_name, "test_one");
let file = File::create(&file_name);
assert! file.exists();
teardown(&dir);
}
#[test]
fn test_file_write_two() {
...
}
Rust
@brian_pearce
To prevent from
accomplishing a
purpose or fulfilling
a desire.
“
”
@brian_pearce
For the world was built to
develop character, and we
must learn that the
setbacks and grieves which
we endure help us in our
marching onward.
“
”
- Henry Ford
@brian_pearce
LEARNING TO
THE UNFAMILIAR
Love
with @brian_pearce

Contenu connexe

Tendances (7)

PuppetDB: One Year Faster - PuppetConf 2014
PuppetDB: One Year Faster - PuppetConf 2014PuppetDB: One Year Faster - PuppetConf 2014
PuppetDB: One Year Faster - PuppetConf 2014
 
Basics of python 3
Basics of python 3Basics of python 3
Basics of python 3
 
3. python intro
3. python   intro3. python   intro
3. python intro
 
Defcon 18: FOCA 2
Defcon 18: FOCA 2Defcon 18: FOCA 2
Defcon 18: FOCA 2
 
Be Lazy & Scale
Be Lazy & ScaleBe Lazy & Scale
Be Lazy & Scale
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
21 spam
21 spam21 spam
21 spam
 

Similaire à Learning to love the unfamiliar

file handling1
file handling1file handling1
file handling1
student
 
Files let you store data on secondary storage such as a hard disk so that you...
Files let you store data on secondary storage such as a hard disk so that you...Files let you store data on secondary storage such as a hard disk so that you...
Files let you store data on secondary storage such as a hard disk so that you...
Bern Jamie
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
Muhammed Thanveer M
 
The problem is called Name Search and it has to be in C# 6. .pdf
The problem is called Name Search and it has to be in C# 6. .pdfThe problem is called Name Search and it has to be in C# 6. .pdf
The problem is called Name Search and it has to be in C# 6. .pdf
karymadelaneyrenne19
 

Similaire à Learning to love the unfamiliar (20)

file handling1
file handling1file handling1
file handling1
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
 
Python files / directories part16
Python files / directories  part16Python files / directories  part16
Python files / directories part16
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Files let you store data on secondary storage such as a hard disk so that you...
Files let you store data on secondary storage such as a hard disk so that you...Files let you store data on secondary storage such as a hard disk so that you...
Files let you store data on secondary storage such as a hard disk so that you...
 
Chap 5 php files part 1
Chap 5 php files part 1Chap 5 php files part 1
Chap 5 php files part 1
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Data Structure Using C - FILES
Data Structure Using C - FILESData Structure Using C - FILES
Data Structure Using C - FILES
 
Unit5
Unit5Unit5
Unit5
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
File handling-c
File handling-cFile handling-c
File handling-c
 
C# to python
C# to pythonC# to python
C# to python
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
The problem is called Name Search and it has to be in C# 6. .pdf
The problem is called Name Search and it has to be in C# 6. .pdfThe problem is called Name Search and it has to be in C# 6. .pdf
The problem is called Name Search and it has to be in C# 6. .pdf
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Learning to love the unfamiliar