5.0.0.1 .1 hello ruby a scrumptiously delicious intro
DESCRIPTION
5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro. Why Ruby? What’s it look like? So how is it different than Perl? Make it go! dealing with variables. Hi, I’m [email protected] I am not a Perl programmer. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/1.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 1
5.0.0.1 – Hello Ruby
5.0.0.1.1Hello RubyA scrumptiously delicious intro
· Why Ruby?
· What’s it look like?
· So how is it different than Perl?
· Make it go!
· dealing with variables
![Page 2: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/2.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 2
5.0.0.1 – Hello Ruby
Hi, I’m [email protected]
I am not a Perl programmer.
![Page 3: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/3.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 3
5.0.0.1 – Hello Ruby
Things I don’t like to do when programming, but find myself sometimes doing anyway:Spoon-feeding compilers
Sifting through stack trace vomit
Sifting through other people’s less-than-elegant code, searching for what should be obvious
Typing like crazy to do something trivial
I don’t want to be surprised anymore
![Page 4: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/4.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 4
5.0.0.1 – Hello Ruby
Things I want out of a programming experience:
·Minimize time it takes to get into my head
·Minimize time it takes to get out of my head
·Minimize frustration -> minimize effort -> conventional things are easy
code
machine
colleague
![Page 5: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/5.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 5
5.0.0.1 – Hello Ruby
Most important thing I want when programming:
·Happiness
![Page 6: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/6.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 6
5.0.0.1 – Hello Ruby
Why Ruby?
Easy to read
Easy to learn
Great for string processing and system call…calling
Full toolbox (CPAN-like package manager, built-in debugger, built-in interactive session, batteries included)
Designed with programmer joy in mind
![Page 7: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/7.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 7
5.0.0.1 – Hello Ruby
What’s it look like?
# Perl equivalent
@food_list = (qw(gelato chicken garlic beans lobster));
print qq(I’m thinking of $#food_list foods.);
if (grep($_ eq “chicken”, @food_list)) { $feels_like_chicken_tonight = 1;} elsif (@food_list) { # we know food_list is an array # can test references using ref($x) eq "ARRAY" push @food_list, “broccoli”;} else { print “There’s no chicken.”;}
print sort @food_list;
![Page 8: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/8.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 8
5.0.0.1 – Hello Ruby
Let’s write a simple function
# Perl equivalent
sub sort_by_length { @list = @_; for $i reverse(0 .. @list-1) { for $j (0 .. $i-1) { if(length($list[$j]) > length($list[$j+1])) { @list[$j,$j+1] = @list[$j+1,$j]; } } return @list;}
0..list.size-1 0..i-1
![Page 9: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/9.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 9
5.0.0.1 – Hello Ruby
A Ruby approach
# Perl equivalent
sub sort_by_length { sort {length($a) length($b)} @_;}
Ruby's iterator
list do |x| CODE
is like Perl's map
map { CODE } @list
except Ruby defines the local iterator explicitly (|x|, |var|, etc)whereas Perl uses $_
![Page 10: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/10.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 10
5.0.0.1 – Hello Ruby
What can it do?
# Perl equivalent
$fh = open(">sorted_food_list.txt");for $food (sort @food_list) { print $fh $food;}close($fh);
use LWP::Simple;my $html = get("http://www.bcgsc.ca");if($html =~ /Gene/) { print index($html,"Gene");}
![Page 11: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/11.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 11
5.0.0.1 – Hello Ruby
Why should I care?
People are irrational and the world outside changes: dealing with requirement changes and getting help if you need it is easy.
![Page 12: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/12.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 12
5.0.0.1 – Hello Ruby
Pretty graphs are nice (and easy)
![Page 13: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/13.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 13
5.0.0.1 – Hello Ruby
Hitting the fan (debugging)
$ ruby -rdebug broken_program.rb
![Page 14: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/14.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 14
5.0.0.1 – Hello Ruby
When not to use Ruby
Machine speed (write in C and call it from Ruby)
Sadomasochism
![Page 15: 5.0.0.1 .1 Hello Ruby A scrumptiously delicious intro](https://reader035.vdocuments.us/reader035/viewer/2022062314/56813da6550346895da76f07/html5/thumbnails/15.jpg)
04/20/23 5.0.0.1.1 - Hello Ruby 15
5.0.0.1 – Hello Ruby
Same programming time, same programming room
Code jams and an open problem