A Beginner's Joy with Ruby

Jason Charnes

Phase 1

Deciding how to learn programming




Mobile App Development?

Desktop/Business Development?

Web Development?

Games?

App Development






iOS: Objective-C, Cocoa Framework
Android: Java

Desktop/Business Development






Java
C++
C#.NET

Web Development

PostgreSQL
MySQL
Cross Browser Compatibility
Web Servers
HTTP Status Codes
Git
Ajax
JSON
SASS
CoffeeScript
PHP
Laravel
CodeIgniter
FuelPHP
HTML
CSS
Responsive Design
Javascript
jQuery
Ruby
Rails
Sinatra
Python
Django
Flask

Where to begin


School, it kind of helped...


Visual Basic 1

Intro to Computer Programming with Java

Problem Solving with Computers using Python

Intro to Computer Science with Java

Where to begin




"PHP is the server side language that everyone uses."

So I started trying to learn it.

Phase Two

Creating arrogant garbage



<?php
$knowledge = "little";
for($i = 0; $i < 100; $i++) { echo "I'm an amazing genius and I know everything.";}
echo "I don't realize I only have very " . $knowledge . " knowledge";
?>

Creating Arrogant Garbage


<?php$name = "Jason";$time = new DateTime();?>
<html><head> <title>Server side programming is so easy.</title></head><body> <h1>What time is it <?= $name ?>?</h1> <p>It's <?= $time->format('H:i:s') ?></p></body></html>

Creating Arrogant Garbage







I just need to learn a some SQL and I will be unstoppable.

Creating Arrogant Garbage


Except...

Things are starting to get messy

Phase Three

It's time for a Change



So I started looking for a framework

CodeIgniter
CakePHP
FuelPHP
Laravel

Countless Others

Time for a Change


Trying to pick one was not easy.


"X framework is the best."

"Y framework is the most advanced."

"Z framework is so behind."


"Ruby on Rails"

Time for a Change





"The Ruby community is condescending and snobbish"

"Ruby and Rails are too opinionated"

"Ruby doesn't scale well"

I fell in Love



Our First Date


I started learning Ruby.
www.tryruby.org

Our First Date


15 Minutes Later:


Wait, so it's really that simple?
Yes.

Wait, so it's really that expressive? 
Yes.

Jason, are you impressed? 
Yes.

Digging In

I want to create and manipulate an object in Ruby:
 p = Person.new p.name = "Al Gore" p.known_for = ["Being Vice President", "\"Inventing\" the Internet"] p.feelings_toward_language = "Simple Enough"
Java (School)
 Person p = Person.new(); p.name = "Al Gore";
p.known_for[0] = "Being Vice President";
p.known_for[1] = "\"Inventing the Internet\""; p.feelings_toward_lanugage = "Not too bad at this stage";
PHP
 $p = Person.new(); $p->name = "Al Gore"; $p->known_for = ["Being Vice President", "\"Inventing the Internet\""]; $p->feelings_toward_lanugage = "Not a big fan of '->', but not too bad";

Digging In


I want to reverse a string in Ruby:
 "The United States of America".reverse => "aciremA fo setatS detinU ehT"
Java (School)
 String postConstitution = "The United States of America"; String preConstitution  = ""; for(int i = 0; i < postConstitution.length(); i++) {     preConstitution += postConstitution.charAt(i); } return preConstitution;
PHP
 return strrev("The United States of America");

Digging In


I need to loop through an array or a hash in ruby:
 colors = %w{red green blue} colors.each {|c| puts c}
Java (School)
 String[] colors = {"Red", "Green", "Blue"}; for(int i = 0; i < colors.length; i++) {    System.out.println(colors[i]); }
PHP
 colors = ["Red", "Green", "Blue"]; foreach($color in $colors) {     echo $color; }

Digging In


The fun only continued:

There is an unless operator.

Creating a method is nice.

I don't have to use parenthesis.

I don't have to use semi-colons.

No curly braces!

I can transform long lines of code into one line.

Ruby + Rails




The double edge sword: Scaffolding.

"Don't use scaffolding"
"Don't use scaffolding"
"Don't use scaffolding"


Well. I used it.

Ruby + Rails


It Helped.

I learned controllers.

I learned routes.

I learned views.

I painfully learned models.


Rails Guides and StackOverflow

Ruby + Rails


Models

Are just a Ruby Class

Can get complex code out of the controller

Certain actions can trigger methods

Can handle validation

Have a corresponding db table

Ruby + Rails


ActiveRecord, you beautiful SOB.


Person.all
SELECT * FROM people

Person.find(144)
SELECT * FROM people WHERE id = 144

Person.where(name: "Jason Charnes")
SELECT * FROM people WHERE name = "Jason Charnes"

Ruby + Rails


Views

They link to controller actions well.

Partials allow extraction of reusable code.

ERB, eh... It got old pretty quick. But it was easy to pickup!

<div class="people>
<% @people.each do |p| %> <li><%= link_to p.name, person_path(p) %></li> <% end %> </div>

Ruby + Rails


REST Controllers

def index  @people = Person.allend
def show @person = Person.find(params[:id])end
def new @person = Person.newend
...

Ruby + Rails


Other things it taught me:


Introduced me to gems. Thank God.

Helped me learn JSON and AJAX.

Helped me better understand OOP with Ruby.

Helps me create web applications quickly.

Ruby


Other things I learned:

Makes programming feel like writing a sentence.

Has an amazing community of users.

Makes learning complicated concepts easier.

Is my second wife.

Resources







Google

Stack Overflow





Thanks.

A Beginner's Joy with Ruby

By Jason Charnes

A Beginner's Joy with Ruby

  • 1,486
Loading comments...

More from Jason Charnes