SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
ACM init() 
Day 1: October 23, 2014
Kelly
Akshay
Daniel
Welcome! 
Welcome to ACM init(), a Computer Science class for 
beginners. 
Over the course of the next few weeks, you will be 
learning Ruby, a flexible, widely used programming 
language.
About the Course 
• This course assumes no prior programming 
experience 
• Hosted by the Association for Computing 
Machinery (ACM) 
• This course will be teaching you how to code in 
a language called Ruby 
• NO EXAMS!!!!
Resources for You 
Our website: acm.cs.ucla.edu 
Slides: slideshare.net/uclaacm 
Facebook: https://www.facebook.com/groups/717821374976381/ 
Want to contact us? 
Kelly: omalleyk@ucla.edu 
Daniel: dduan@yahoo.com 
Akshay: akshaybakshi@ucla.edu
Remember: If you 
have any questions, 
ask! Chances are 
someone else has the 
same question and is 
hesitant to ask.
If you don’t 
understand 
something, it is more 
important that you 
learn it than we finish 
everything today.
Why Computer Science? 
• Computer Science is a fast 
growing field with a surplus of 
high-paying jobs 
• Learning a programming 
language will enhance your 
resume and make you more 
desirable to companies 
• Furthermore, learning how to 
code will better your problem-solving 
skills and help you in 
all of your classes 
Source: http://www.ovrdrv.com/blog/making-computer-science-cool/
The numbers speak for 
themselves... 
Source: http://code.org/promote
Who knows what a 
programming 
language is?
Why Learn Ruby? 
• Ruby is easy to read and use, 
and is considered to be one of 
the best first languages to 
learn 
• Ruby developers are in high 
demand 
• Ruby is useful -- Ruby on Rails 
is one of the most popular 
web programming platforms in 
the startup community
Let's Get Started!
Computing the Factorial of a 
Number 
• Factorial: written as #! 
• For example, 5! is 5*4*3*2*1 = 120 
• I wrote a simple program called fact.rb that will 
compute the factorial for us 
• Let's try it out! Compute the factorial of 6. 
• ruby fact.rb 6
A Bit About Computers 
Computers think in 0s and 1s. Everything that you input into a 
computer gets stored in this manner. For example: 
You don't need to know how this conversion works. However, the concept is 
important because it is the reason why we need programming languages. 
Human-readable programming languages go through a process that 
converts them to binary, which can be understood by the compter.
How do we make our code 
work? 
Ruby is what is called an interpreted language. That means 
that the computer runs one line of code at a time. 
We can't just type code into a word document and hope it will 
magically do something. We need an interpreter that will help 
the computer understand our code.
koding.com 
koding.com is an easy way to run code that requires no 
downloading or storage space.
Enter your email and choose a username
This is what you should see once you log in.
Let's learn how to run a program. Type 
puts "I love computers!" 
into the top window in Koding.
Now, save the file. Select the option Save As.
Select a directory to save the file in. I choose a directory I 
created called ACMclass. Now, name the file myfirstfile.rb
Press Save
The file has been saved! Now, let's run it.
First, we need to make sure we are in the right directory. Type 
in cd 'theDirectoryYouSavedIn' then press Enter. 
It changed!
Now we can access our file! Time to run it. Type in 
ruby myfirstfile.rb 
This tells Koding that we are about to run a Ruby file.
Press Enter, and it runs! The screen printed out "I love 
computers!"
Time to start learning 
Ruby.
Data Types 
• Why? Say "five". Did you say 5 or five? 
• There are three main data types in Ruby: numbers, 
booleans, and strings. 
• Numbers: Exactly what it sounds like. (example: 1, 
400, 45.7) 
• Booleans: Something that is either true or false. 
• String: A word or phrase. (example: "Hello World!")
Variables 
We can store these data types in variables so we can 
come back and use them again later. 
Take a look: 
Now if we want to use any of these stored values 
again all we have to do is type the variable name!
Math 
There are six main math operations we are going to go over 
today.
+ - * / 
• + is addition 
• - is subtraction 
• * is multiplication 
• / is division 
• These work the same way 
your calculator does -- no 
surprises here
** and % 
• ** (exponent) raises one 
number to the power of 
another. For example, 2**3 
would be 8 because 2*2*2=8 
• % (modulus) returns the 
remainder of division. For 
example, 25%7 would be 4 
because 25/7 is 3r4.
Printing to the Screen 
There are two main commands that will allow you to 
print text out to the screen. 
These commands are 'puts' and 'print'.
'puts' vs 'print' 
The 'print' command just takes whatever you give it and prints 
it to the screen. 
'puts' (for "put string") is slightly different: it adds a new (blank) 
line after the thing you want it to print.
'puts' vs. 'print' example
String Methods 
• Remember, a string is is word or a phrase. Ruby 
provides several methods for us to make it easier to 
use strings 
• '.length' : finds the length of the string 
• '.reverse' : reverses the string 
• '.upcase' : changes all letters to uppercase 
• '.downcase' : changes all letters to lowercase
String Methods Example
We've covered all the Ruby syntax 
we're going over for today. Now, 
let's learn a bit about writing good 
code.
Comments 
What if you write a really long program then not look at it for a 
year? What if you're working on a project with other people 
and you have to share your code? 
We need a way to explain what is going on in the programs we 
write. 
The solution? Comments.
How to add comments 
Comments are a tool we have to communicate what our code 
is intended to do. 
To put a comment in your code all you have to do is type 
# your comment here 
Anything that comes after '#' and is on the same line will be 
ignored when the code is being run.
Comment Example
Naming Conventions 
• Remember that we can give values to variables so we can use the same 
value again later 
• We can name these variables whatever we want 
• Doesn't it make sense to give variables descriptive names? 
• Some naming rules: 
• Separate words with underscores '_' 
• Do not start a variable name with a number, symbol, or uppercase 
letter 
• The variable name should describe what the variable contains or will 
be used for
Naming Examples
What we covered 
• A little bit about Ruby 
• How to use Koding 
• Data types: numbers, string, and booleans 
• Variables 
• Math 
• How to print to the screen 
• String methods 
• How to write good code
Any questions? 
Office Hours will be right after the 
class every time.

Weitere ähnliche Inhalte

Ähnlich wie ACM Init() lesson 1

Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
Iván Montes
 
Nllug 2010 - Web-services bootcamp
Nllug 2010 - Web-services bootcampNllug 2010 - Web-services bootcamp
Nllug 2010 - Web-services bootcamp
Bill Buchan
 
Nllug 2010-web-services
Nllug 2010-web-servicesNllug 2010-web-services
Nllug 2010-web-services
Bill Buchan
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
knoppix
 

Ähnlich wie ACM Init() lesson 1 (20)

ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
 
Ruby
RubyRuby
Ruby
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a Program
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
ruby pentest
ruby pentestruby pentest
ruby pentest
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 
Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptx
 
Rubykin
Rubykin Rubykin
Rubykin
 
Nllug 2010 - Web-services bootcamp
Nllug 2010 - Web-services bootcampNllug 2010 - Web-services bootcamp
Nllug 2010 - Web-services bootcamp
 
Nllug 2010-web-services
Nllug 2010-web-servicesNllug 2010-web-services
Nllug 2010-web-services
 
What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?What Is Coding And Why Should You Learn It?
What Is Coding And Why Should You Learn It?
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
INTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c languageINTRODUCTION TO C PROGRAMMING in basic c language
INTRODUCTION TO C PROGRAMMING in basic c language
 
Java basics
Java basicsJava basics
Java basics
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 

Mehr von UCLA Association of Computing Machinery

Mehr von UCLA Association of Computing Machinery (16)

ACM init()- Day 4
ACM init()- Day 4ACM init()- Day 4
ACM init()- Day 4
 
ACM init() Day 3
ACM init() Day 3ACM init() Day 3
ACM init() Day 3
 
ACM init() Day 2
ACM init() Day 2ACM init() Day 2
ACM init() Day 2
 
UCLA ACM Spring 2015 general meeting
UCLA ACM Spring 2015 general meetingUCLA ACM Spring 2015 general meeting
UCLA ACM Spring 2015 general meeting
 
UCLA Geek Week - Claim Your Domain
UCLA Geek Week - Claim Your DomainUCLA Geek Week - Claim Your Domain
UCLA Geek Week - Claim Your Domain
 
Intro to Hackathons (Winter 2015)
Intro to Hackathons (Winter 2015)Intro to Hackathons (Winter 2015)
Intro to Hackathons (Winter 2015)
 
An Introduction to Sensible Typography
An Introduction to Sensible TypographyAn Introduction to Sensible Typography
An Introduction to Sensible Typography
 
Building a Reddit Clone from the Ground Up
Building a Reddit Clone from the Ground UpBuilding a Reddit Clone from the Ground Up
Building a Reddit Clone from the Ground Up
 
ACM init() Day 6
ACM init() Day 6ACM init() Day 6
ACM init() Day 6
 
ACM init() Day 5
ACM init() Day 5ACM init() Day 5
ACM init() Day 5
 
Init() Day 4
Init() Day 4Init() Day 4
Init() Day 4
 
Init() Lesson 3
Init() Lesson 3Init() Lesson 3
Init() Lesson 3
 
Init() Lesson 2
Init() Lesson 2Init() Lesson 2
Init() Lesson 2
 
ACM Fall General Meeting
ACM Fall General Meeting ACM Fall General Meeting
ACM Fall General Meeting
 
ACM Teach - Hackathon Tips and Tricks - Spring 2014
ACM Teach - Hackathon Tips and Tricks - Spring 2014ACM Teach - Hackathon Tips and Tricks - Spring 2014
ACM Teach - Hackathon Tips and Tricks - Spring 2014
 
ACM General Meeting - Spring 2014
ACM General Meeting - Spring 2014ACM General Meeting - Spring 2014
ACM General Meeting - Spring 2014
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
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
 

Kürzlich hochgeladen (20)

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 ...
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

ACM Init() lesson 1

  • 1. ACM init() Day 1: October 23, 2014
  • 5. Welcome! Welcome to ACM init(), a Computer Science class for beginners. Over the course of the next few weeks, you will be learning Ruby, a flexible, widely used programming language.
  • 6. About the Course • This course assumes no prior programming experience • Hosted by the Association for Computing Machinery (ACM) • This course will be teaching you how to code in a language called Ruby • NO EXAMS!!!!
  • 7.
  • 8. Resources for You Our website: acm.cs.ucla.edu Slides: slideshare.net/uclaacm Facebook: https://www.facebook.com/groups/717821374976381/ Want to contact us? Kelly: omalleyk@ucla.edu Daniel: dduan@yahoo.com Akshay: akshaybakshi@ucla.edu
  • 9. Remember: If you have any questions, ask! Chances are someone else has the same question and is hesitant to ask.
  • 10. If you don’t understand something, it is more important that you learn it than we finish everything today.
  • 11. Why Computer Science? • Computer Science is a fast growing field with a surplus of high-paying jobs • Learning a programming language will enhance your resume and make you more desirable to companies • Furthermore, learning how to code will better your problem-solving skills and help you in all of your classes Source: http://www.ovrdrv.com/blog/making-computer-science-cool/
  • 12. The numbers speak for themselves... Source: http://code.org/promote
  • 13. Who knows what a programming language is?
  • 14. Why Learn Ruby? • Ruby is easy to read and use, and is considered to be one of the best first languages to learn • Ruby developers are in high demand • Ruby is useful -- Ruby on Rails is one of the most popular web programming platforms in the startup community
  • 16. Computing the Factorial of a Number • Factorial: written as #! • For example, 5! is 5*4*3*2*1 = 120 • I wrote a simple program called fact.rb that will compute the factorial for us • Let's try it out! Compute the factorial of 6. • ruby fact.rb 6
  • 17.
  • 18. A Bit About Computers Computers think in 0s and 1s. Everything that you input into a computer gets stored in this manner. For example: You don't need to know how this conversion works. However, the concept is important because it is the reason why we need programming languages. Human-readable programming languages go through a process that converts them to binary, which can be understood by the compter.
  • 19. How do we make our code work? Ruby is what is called an interpreted language. That means that the computer runs one line of code at a time. We can't just type code into a word document and hope it will magically do something. We need an interpreter that will help the computer understand our code.
  • 20. koding.com koding.com is an easy way to run code that requires no downloading or storage space.
  • 21. Enter your email and choose a username
  • 22. This is what you should see once you log in.
  • 23. Let's learn how to run a program. Type puts "I love computers!" into the top window in Koding.
  • 24. Now, save the file. Select the option Save As.
  • 25. Select a directory to save the file in. I choose a directory I created called ACMclass. Now, name the file myfirstfile.rb
  • 27. The file has been saved! Now, let's run it.
  • 28. First, we need to make sure we are in the right directory. Type in cd 'theDirectoryYouSavedIn' then press Enter. It changed!
  • 29. Now we can access our file! Time to run it. Type in ruby myfirstfile.rb This tells Koding that we are about to run a Ruby file.
  • 30. Press Enter, and it runs! The screen printed out "I love computers!"
  • 31. Time to start learning Ruby.
  • 32. Data Types • Why? Say "five". Did you say 5 or five? • There are three main data types in Ruby: numbers, booleans, and strings. • Numbers: Exactly what it sounds like. (example: 1, 400, 45.7) • Booleans: Something that is either true or false. • String: A word or phrase. (example: "Hello World!")
  • 33. Variables We can store these data types in variables so we can come back and use them again later. Take a look: Now if we want to use any of these stored values again all we have to do is type the variable name!
  • 34. Math There are six main math operations we are going to go over today.
  • 35. + - * / • + is addition • - is subtraction • * is multiplication • / is division • These work the same way your calculator does -- no surprises here
  • 36. ** and % • ** (exponent) raises one number to the power of another. For example, 2**3 would be 8 because 2*2*2=8 • % (modulus) returns the remainder of division. For example, 25%7 would be 4 because 25/7 is 3r4.
  • 37. Printing to the Screen There are two main commands that will allow you to print text out to the screen. These commands are 'puts' and 'print'.
  • 38. 'puts' vs 'print' The 'print' command just takes whatever you give it and prints it to the screen. 'puts' (for "put string") is slightly different: it adds a new (blank) line after the thing you want it to print.
  • 40. String Methods • Remember, a string is is word or a phrase. Ruby provides several methods for us to make it easier to use strings • '.length' : finds the length of the string • '.reverse' : reverses the string • '.upcase' : changes all letters to uppercase • '.downcase' : changes all letters to lowercase
  • 42. We've covered all the Ruby syntax we're going over for today. Now, let's learn a bit about writing good code.
  • 43. Comments What if you write a really long program then not look at it for a year? What if you're working on a project with other people and you have to share your code? We need a way to explain what is going on in the programs we write. The solution? Comments.
  • 44. How to add comments Comments are a tool we have to communicate what our code is intended to do. To put a comment in your code all you have to do is type # your comment here Anything that comes after '#' and is on the same line will be ignored when the code is being run.
  • 46. Naming Conventions • Remember that we can give values to variables so we can use the same value again later • We can name these variables whatever we want • Doesn't it make sense to give variables descriptive names? • Some naming rules: • Separate words with underscores '_' • Do not start a variable name with a number, symbol, or uppercase letter • The variable name should describe what the variable contains or will be used for
  • 48. What we covered • A little bit about Ruby • How to use Koding • Data types: numbers, string, and booleans • Variables • Math • How to print to the screen • String methods • How to write good code
  • 49. Any questions? Office Hours will be right after the class every time.