Second lecture for 159.707
Last active
August 29, 2015 13:56
-
-
Save grahamjenson/9319368 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/extensions/goto/deck.goto.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/extensions/menu/deck.menu.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/extensions/navigation/deck.navigation.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/extensions/status/deck.status.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/extensions/scale/deck.scale.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/themes/style/swiss.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/isagalaev/highlight.js/master/src/styles/monokai_sublime.css"> | |
<link rel="stylesheet" href="https://rawgithub.com/imakewebthings/deck.js/master/core/deck.core.css"> | |
<link rel="stylesheet" media="screen" href="https://rawgithub.com/imakewebthings/deck.js/master/themes/transition/horizontal-slide.css"> | |
<script src='http://code.jquery.com/jquery-2.0.3.js'></script> | |
<script src='http://code.jquery.com/ui/1.10.3/jquery-ui.js'></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/modernizr.custom.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/core/deck.core.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/extensions/menu/deck.menu.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/extensions/goto/deck.goto.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/extensions/status/deck.status.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/extensions/navigation/deck.navigation.js"></script> | |
<script src="https://rawgithub.com/imakewebthings/deck.js/master/extensions/scale/deck.scale.js"></script> | |
<script src="http://coffeescript.org/extras/coffee-script.js"></script> | |
<script src="http://yandex.st/highlightjs/8.0/highlight.min.js"></script> | |
<script src="https://rawgithub.com/coreyti/showdown/master/src/showdown.js"></script> | |
<script src="https://rawgithub.com/coreyti/showdown/master/src/extensions/github.js"></script> | |
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css' /> | |
<style> | |
pre { | |
border: 0px; | |
} | |
pre code { | |
font-size: .6em; | |
} | |
p { | |
font-size: 1.2em; | |
} | |
blockquote { | |
font-size: 1.2em; | |
} | |
.body { | |
font-family: "Lato", sans-serif; | |
color: #5d5d5d; } | |
.pull-right { | |
float: right; | |
margin: 10px; } | |
.pull-left { | |
float: left; | |
margin: 10px; } | |
</style> | |
</head> | |
<body> | |
<div class="deck-container"> | |
<!-- Begin slides. Just make elements with a class of slide. --> | |
<section class='slide no-md'> | |
<h1> | |
159.707 | |
<br> | |
<span style="font-size: .2em; color: #c00;"> Dynamic typing case study (Ruby), Convention over Configuration (RubyOnRails) </span> | |
</h1> | |
</section> | |
<section class='slide no-md'> | |
<h2> About me </h2> | |
<ul> | |
<li> Graham Jenson </li> | |
<li> B.Sc. Hons 2008 </li> | |
<li> Ph.D. 2013 </li> | |
<li> Contracting Consultant </li> | |
<li> Startup </li> | |
<li> Marketing Enterprise Company</li> | |
</ul> | |
</section> | |
<section class='slide no-md'> | |
<h2>159.707 Advanced Software Design and Construction</h2> | |
<ul> | |
<li><strike>25 Feb: Component Evolution (Graham’s thesis) and recent industry experience </strike></li> | |
<li>4 March: Dynamic typing case study (Ruby), Convention over Configuration (RubyOnRails)</li> | |
<li>11 March: Design Patterns in Modern Web Applications (coffeescript, backbone, ember, angular, node.js)</li> | |
<li>18 March: Architecture, refurbishing/replacing legacy systems </li> | |
<li> 1 April: Agile Methodologies (SCRUM , Kanban) </li> | |
<li> 8 April: Data visualisation with D3 </li> | |
</ul> | |
</section> | |
<section class='slide no-md'> | |
<h2>Today</h2> | |
<ul> | |
<li>Ruby Introduction</li> | |
<li>Rails Practical</li> | |
</ul> | |
</section> | |
<section class='slide no-md'> | |
<h1>Ruby Introduction | |
<br> | |
<span style="font-size: .2em; color: #c00;"> Why it makes me happy </span> | |
</h1> | |
</section> | |
<section class='slide'> | |
##My Experience With Ruby | |
* I am Productive | |
* I write beautiful code | |
> This makes me happy | |
</section> | |
<section class='slide'> | |
##History of Ruby | |
 | |
Yukihiro Matsumoto (**Matz**) in **1993** conceived of the a programming language that is made for developer happiness and productivity. | |
This makes Ruby older than Java, Javascript, and PHP; all created in 1995. | |
</section> | |
<section class='slide'> | |
##History of Ruby | |
Matz took inspiration from Perl and SmallTalk | |
* **Perl** optional parentheses and the close shell integration; | |
* **SmallTalk** he took object orientation and its emphasis on message passing. | |
</section> | |
<section class='slide'> | |
##History of Ruby | |
The first Ruby implementation, known as the "Matz Ruby Implementation" (**MRI**), was initially seen as the reference implementation of Ruby. From MRI many other implementations were created: | |
* **JRuby**: Java Virtual Machine implementation | |
* **Rubinius**: Mostly pure Ruby to LLVM machine code | |
* **IronRuby**: .NET implementation | |
* **MagLev**: SmallTalk implementation | |
</section> | |
<section class='slide'> | |
#Community | |
</section> | |
<section class='slide'> | |
##Community | |
> Matz is nice, so we are nice. | |
</section> | |
<section class='slide'> | |
##Community | |
* Loads of Books | |
* Heaps of online resources | |
</section> | |
<section class='slide'> | |
##Community | |
> Learning how to program, thats the easy part. Learning how to be a programmer, thats the advanced stuff. Thats what gets you to the next level, I think we should work on that. | |
"Soft Talks" | |
* [Disabilities](http://www.youtube.com/watch?v=6cdbx1BmboQ) by James Edward Grey II | |
* [Developers and Depression](http://www.youtube.com/watch?v=yFIa-Mc2KSk) by Greg Baugues | |
* [Loyalty and Layoffs](http://rubyrogues.com/125-rr-loyalty-and-layoffs/) by the Ruby Rogues | |
</section> | |
<section class='slide'> | |
#Productivity | |
</section> | |
<section class='slide'> | |
##Productivity | |
> When cycling, either there is a headwind or you are having a good day. I am always ready to take a wind assisted ride as my accomplishment, as if I really am that strong. But I can't forget that if my doppelgänger was out riding the same road in the same conditions but in the opposite direction, that she would work just as hard but accomplish far less | |
-- *Sandi Metz [Tells your Future](http://www.youtube.com/watch?v=fhpT6Pc4AqM)* | |
</section> | |
<section class='slide'> | |
##Productivity | |
The productivity that you feel when writing Ruby is down to two things: | |
1. Ruby being very malleable to a particular problem and developer | |
2. The ability to quickly re-use Ruby components, called Gems | |
</section> | |
<section class='slide'> | |
##Writing a Gem | |
``` | |
Gem::Specification.new do |s| | |
s.name = 'spellchecker' | |
s.version = '0.1.0' | |
s.summary = "This is a spell checker" | |
... | |
s.files = ["lib/spellchecker.rb"] | |
s.add_development_dependency 'testinggem', '~> 2.1' | |
s.add_runtime_dependency 'wordsgem', '~> 1.1' | |
s.homepage = 'https://rubygems.org/gems/example' | |
end | |
``` | |
</section> | |
<section class='slide'> | |
##Using a Gem | |
`Gemfile` | |
``` | |
source 'https://rubygems.org' | |
gem 'nokogiri' | |
gem 'rack', '~>1.1' | |
gem 'rspec', :require => 'spec' | |
``` | |
``` | |
bundle install | |
``` | |
</section> | |
<section class='slide'> | |
#Performance | |
</section> | |
<section class='slide'> | |
##Performance | |
>Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves. -- *Matz* | |
</section> | |
<section class='slide'> | |
##Performance | |
People sometimes dismiss Ruby because *Ruby is slow*. Well it is, and **I don't care**. | |
1. Hardrware is cheap and developers time is not | |
2. Buy better hardware with the money saved in productivity | |
</section> | |
<section class='slide'> | |
# Example | |
</section> | |
<section class='slide'> | |
##Example | |
What does this Java code do? | |
``` | |
Calendar cal = Calendar.getInstance(); | |
cal.add(Calendar.DATE, -1); | |
System.out.println(cal.getTime() + ""); | |
``` | |
</section> | |
<section class='slide'> | |
##Yesterdays Date | |
Rails gives us a helper where `1.day.ago` returns yesterdays date. | |
Lets implement that! | |
</section> | |
<section class='slide'> | |
##Yesterdays Date | |
``` | |
class Numeric | |
def day | |
self * 60 * 60 * 24 | |
end | |
end | |
``` | |
</section> | |
<section class='slide'> | |
##Yesterdays Date | |
``` | |
class Numeric | |
def ago | |
Time.now - self | |
end | |
end | |
``` | |
</section> | |
<section class='slide'> | |
##Yesterdays Date | |
`2.day.ago` looks silly. So ... | |
``` | |
class Numeric | |
alias :days :day | |
end | |
``` | |
</section> | |
<section class='slide'> | |
#Basics Of Ruby | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
The console `IRB` *Interactive Ruby* | |
> EXAMPLE | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Strings | |
``` | |
a = "Hello World" | |
puts a | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Numbers | |
``` | |
a = 1.2 | |
a.round | |
a.zero? | |
3**2 | |
Math.sqrt(100) | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
``` | |
class Mine | |
def fn(param) | |
param*10 | |
end | |
end | |
``` | |
``` | |
m = Mine.new | |
m.fn(10) | |
m.fn("#") | |
``` | |
``` | |
Mine.instance_methods() | |
Mine.instance_methods(false) | |
Mine.new.respond_to?(:fn) | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
``` | |
class Mine | |
def *(p) | |
p*10 | |
end | |
end | |
``` | |
``` | |
m = Mine.new | |
m * 10 | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Messages | |
``` | |
m = Mine.new | |
m.send(:fn, 10) | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Attributes | |
``` | |
class Mine | |
attr_accessor :name | |
end | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Mixins | |
``` | |
module Blue | |
def blue? | |
true | |
end | |
end | |
class Mine | |
include Blue | |
end | |
Mine.new.blue? | |
class Mine | |
extend Blue | |
end | |
Mine.blue? | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
``` | |
m = Mine.new | |
m.send(:oh_noes, 10) | |
``` | |
``` | |
class Mine | |
def method_missing(m, *args, &block) | |
puts m | |
end | |
end | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
This is powerful, but you can stab yourself with these tools | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Blocks | |
``` | |
def map(list) | |
new_list = [] | |
for l in list | |
new_list << yield(l) | |
end | |
new_list | |
end | |
``` | |
``` | |
map [1,2,3] {|x| x*2} | |
``` | |
</section> | |
<section class='slide'> | |
##Basics Of Ruby | |
Lambdas | |
``` | |
lambda = ->(x){ x*2 } | |
map([1,2,3], &lambda) | |
``` | |
</section> | |
<section class='slide'> | |
##Summary of Ruby | |
* I love Ruby | |
* I think you will love Ruby | |
</section> | |
<section class='slide'> | |
#Ruby on Rails -- The Killer App | |
</section> | |
<section class='slide'> | |
##Rails | |
> You call a libraries code, a framework calls your code | |
It is a framework | |
> **Convention over Configuration** | |
Instead of spending a large amounts of time configuring a project, do it in a standard way and only specify the unconventional. | |
</section> | |
<section class='slide'> | |
##Rails | |
Design Patterns | |
1. MVC Layout | |
2. ActiveRecord ORM | |
</section> | |
<section class='slide'> | |
##Rails | |
Favourite Parts | |
1. **The Asset Pipeline**: The asset pipeline takes a list of assets that need to be pre-compiled like coffeesciprt and sass assets, and then manages their lifecycle in development and deployment lifecycles. | |
2. **Engines**: A Rails Engine is a RubyGem that includes parts of the MVC pattern. It enables a Rails application to be separated into components. | |
</section> | |
<section class='slide'> | |
##Rails | |
Why I like Ruby | |
1. Testing focus | |
2. Deployment focus | |
</section> | |
<section class='slide'> | |
#Rails *Live Demo* | |
</section> | |
<section class="slide"> | |
<h2>Graham Jenson</h2> | |
<ul> | |
<li>Twitter: <strong>@grahamjenson</strong> </li> | |
<li><strong>Blog:</strong> http://maori.geek.nz/blog</li> | |
</ul> | |
</div> | |
</section> | |
<!-- deck.navigation snippet --> | |
<div aria-role="navigation"> | |
<a href="#" class="deck-prev-link" title="Previous">←</a> | |
<a href="#" class="deck-next-link" title="Next">→</a> | |
</div> | |
<!-- deck.status snippet --> | |
<p class="deck-status" aria-role="status"> | |
<span class="deck-status-current"></span> | |
/ | |
<span class="deck-status-total"></span> | |
</p> | |
<!-- deck.goto snippet --> | |
<form action="." method="get" class="goto-form"> | |
<label for="goto-slide">Go to slide:</label> | |
<input type="text" name="slidenum" id="goto-slide" list="goto-datalist"> | |
<datalist id="goto-datalist"></datalist> | |
<input type="submit" value="Go"> | |
</form> | |
<!-- End extension snippets. --> | |
</div> | |
<script> | |
$(function() { | |
hljs.initHighlightingOnLoad(); | |
$.deck('.slide'); | |
}); | |
(function($, deck, undefined) { | |
var $d = $(document); | |
var converter = new Showdown.converter({ extensions: ['github'] }); | |
$d.bind('deck.init', function() { | |
$.each($.deck("getSlides"), function(index, value) { | |
var cssClass = value.attr('class'); | |
// Prevent slides marked with no-md css class to be interpreted as markdown | |
if (!cssClass || cssClass.indexOf('no-md') < 0) { | |
value.html(converter.makeHtml(value.text())); | |
} | |
}); | |
}); | |
})(jQuery, 'deck'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment