Programming, Ruby,
Rails and more
Programming
The ability to instruct the computer what to do
!
Instruct the computer how to behave when certain
events arise
The computer is a pretty dumb machine, it needs to be told what to do to perform any useful tasks. We build rich and powerful instructions for the computer so we can get it to perform a variety of tasks.
!
Why program?
•
Solve a problem
•
Solve other people’s problems
•
Get a computer slave away on a laborious task,
while you focus on the more important things
•
Historically machines have replaced labour
intensive jobs
•
Perth’s next economy
You may want to program, just to solve your own problem. For example I have a listing of shares locked in some crummy website, with some programming I can sync it with Google Docs and build some nice graphs.
!
You may want to work on solving other people’s problems, maybe a product in the consumer or enterprise space?
!
You may have some intensive tasks that you would usually repeat manually on a computer, we can program a computer to repeat those tasks.
!
Machines have historically replaced labour intensive tasks, machines need programming to perform their robotic tasks. Do you want to be the human that’s next in line to be replaced, or be the human in charge of the machines?
!
You can build a business out of programming, whether you are consulting or building your own product solutions. Where will be Perth be at the end of the mining boom?
A programmer
•
Isn’t just focused on one skill.
•
Employers want to hire programmers, not Rails
programmers
•
Should understand the depth of the tools they are
working with
•
Can extend and grow the tools they are working
with
The best kind of programmers are those that can move between skills, Mercedes mechanics know how to service Mercedes-Benz vehicles but also know how to basically service any modern car.
!
A programmer
•
Works with logic/decisions
•
IF is_night_time? DO lights_on ELSE lights_off
!
•Works with repetition/iteration
•
WHILE is_really_dark? DO lights_on ELSE lights_off
!
•Can talk to other computers and services
•
IF bom_perth_sunset? DO lights_on ELSE lights_off
A programmer can task the computer to evaluate a situation and make a decision, these flows can help your program react to certain events and make the best decision.
!
We also might want to keep the computer constantly checking our inputs and react to change in the event. So a while loop will help us continually check if it is dark and react accordingly.
!
Computers have been networked for a number of years, we can take advantage of that and have programs that talk to other computers. I could have a program that asks BoM for the sunset time and reacts accordingly.
Tools
•
Develop code in an editor
•
Lightweight: Sublime Text, Notepad++
•
Heavy/extensive: RubyMine, Aptana RadRails
•A computer. Any will do
•
Cloud9 allows for programming in a browser
Much like a word document or a image project we need to write our programs somewhere. We call this an editor.
!
Editors range from the level of interference you want. If you want minimal interference only when you truly need it you can opt for a editor like Sublime, but if you want something that is able to help you out further you may want an Integrated Development Environment (IDE). IDEs allow you to write your code and also understand how it's running, working through any issues with you.
!
You will want a computer to run your code, but we have services like Cloud9 that allow you to write code in a browser and have a remote computer run your program.
Ruby
•
Ruby is the language powering Rails, we need
appreciate what’s happening underneath and go
beyond Rails.
•
Developed in the mid 90s by Yukihiro Matsumoto
(Matz)
•
Built for productivity and for fun
•Reads as it is written (story like)
•Tryruby!
Rails runs on Ruby, so we write Ruby to interact with Rails.
!
Rails was developed by Matz in the mid 90s, influenced by some important languages Ruby brings a more human aspect to programming. It has been described as fun to write allowing for a programs to be written that read back very well.
!
Rails
•Rails bring Ruby to the web.
•
Developed by David Heinemeier Hansson (DHH) for
37signals. Now 13 core team members.
•
We write programs that output stuff that is sent to a web
browser
•
Our browsers can send stuff back to Rails and we can
react
•
Rails marries Ruby as a language with good web
principles
Rails is known as a framework, comprising of a number of pieces to help write Ruby programs that talk to web browsers.
!
It was developed by David Heinemeier Hansson (DHH) while working at 37signals as a way to develop powerful web applications for the company. Rails was used as a key part of developing Basecamp, a project management tool for the web.
!
In Rails we write Ruby programs that can send stuff to the browser, we can also receive information back from the user’s browser and react to this. This is the powerful of “dynamic” websites, they can constantly change and evolve depending on the context and events around the current user.
!
Websites
• Can’t react to change without
a human rewriting it
• Simple
• A restaurant site with with no
booking, just a fixed menu.
• Always changing
• Computer programs can react
to events and update the website.
• Human input
• Time of day
• The website can be
personalised for each user
• facebook.com, News sites,
Blogs
Static
Dynamic
We can classify websites into two areas. Static websites and Dynamic websites.
!
Static websites are fixed in time, they can’t react to events without a human going in a rewriting the website. They are simple, much like a billboard they are fixed and involve some work to change if needed.
If you’ve visited a basic restaurant site that usually just lists a menu without any booking facilities it is usually a static website.
!
Dynamic websites are interactive, they are always changing. Reacting to events they will change their appearance and information displayed, they can receive human interaction and handle these changes. Or they can react to changes in environment, time of day etc.
!
Because the website is built by a computer program it can personalise itself for each user, meaning we can display different information depending on who, where and when the user is.