SlideShare a Scribd company logo
Sarah Kiniry
cPanel, Inc.
Storytime
Programming Language
About Me
Jason (hubby!)
Backend Perl developer,
extremely patient about being
my in-home tutor, taught me a
whole lot of The Things.
Sarah Kiniry (me!)
Technical Writer, former Stage
Manager and Box Office Manager,
needs-an-intervention level
Trekkie.
technicolorwriter.com

@SarahKiniry
@SarahKiniry
#STC16
If you can learn to read,
you can learn to read code.
Just read the story!
1
2
3
What does the application do?
What text will the user see?
Which files or settings?
@SarahKiniry
#STC16
How do I find the story?
Code Clues
1
2
3
What does the application do?
What text will the user see?
Which files or settings?
Code Comments
Function Names
Variable (Setting) Names
File Locations
Print Functions
Files
Directories
Variables
Code comments, function names,
setting names, and file locations.
Display methods, like print, and
other output functions.
File names, file paths, and other
variables.
@SarahKiniry
#STC16
Comments
Text in code that the computer doesn’t try to run.
Instead, it’s there for the developer’s reference.
Sometimes, it’s also used to temporarily “turn off”
code without deleting it.
Comments
// Single-line comments
// require a comment
// for each line.
do(thing); // comment
/* Multi-line
comments use beginning
and end characters for
multiple lines. */
Single-line comments…
• Can be used on the same line as code (a
trailing comment).
• Comment character at the beginning of the
comment only.
• A line break ends the comment.
Multi-line comments…
• Comment character at the beginning and
end of the comment.
• Generally, these exist on separate lines
from the code.
@SarahKiniry
#STC16
Single Line
// Java, JavaScript, C, C#, PHP
# PHP, Perl, Ruby, Python
@SarahKiniry
#STC16
Multi Line
/* Comment */ Java, JavaScript, C, C#, PHP
// Comment 
Comment
C
=pod
=cut
Perl
=begin
=end
Ruby
""" """ Python
@SarahKiniry
#STC16
Functions
Reusable code that performs one or more actions.
Sometimes, the code that you’re looking at is a
function, while sometimes it uses existing functions.
* This is a lazy use of the term. These actions can be
subroutines, methods, procedures, etc.
Functions
sub do_something {
my $value = @_;
if $value {
return "Yay!";
}
…
do_something($value);
Function definition…
• Includes all of the code that will run
anytime the function is used.
• Creating a function that’s used elsewhere.
• Sets the function name.
Function use…
• Could be a custom-written function, or one
that’s built into the programming language.
• Often, custom functions are defined in
other code, not in the same file.
@SarahKiniry
#STC16
Using Functions
function($value)
function "$value"
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
class type functionname(parameters) {
code
}
*Java uses a “class” structure, so when you see this in code it’s going to be nested in a class.
Java*, C#
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
class type functionname(parameters) {
code
}
// This example defines a function.
public static void printyay() {
System.out.println ("Yay!");
}
*Java uses a “class” structure, so when you see this in code it’s going to be nested in a class.
Java*, C#
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
class type functionname(parameters) {
code
}
// This example defines a function.
public static void printyay() {
System.out.println ("Yay!");
}
*Java uses a “class” structure, so when you see this in code it’s going to be nested in a class.
Java*, C#
@SarahKiniry
#STC16
// This uses the defined function.
printyay();
Creating Functions
// This is the format to define a function.
class type functionname(parameters) {
code
}
// This example defines a function.
public static void printyay() {
System.out.println ("Yay!");
}
*Java uses a “class” structure, so when you see this in code it’s going to be nested in a class.
Java*, C#
@SarahKiniry
#STC16
// This uses the defined function.
printyay();
Yay!
Creating Functions
// This is the format to define a function.
type functionname(parameters) {
code
}
C
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
type functionname(parameters) {
code
}
// This example defines a function.
int printyay() {
printf("Yay!");
}
C
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
type functionname(parameters) {
code
}
// This example defines a function.
int printyay() {
printf("Yay!");
}
C
@SarahKiniry
#STC16
// This uses the defined function.
printyay();
Creating Functions
// This is the format to define a function.
type functionname(parameters) {
code
}
// This example defines a function.
int printyay() {
printf("Yay!");
}
C
@SarahKiniry
#STC16
// This uses the defined function.
printyay();
Yay!
Creating Functions
// This is the format to define a function.
function functionname(parameters) {
code
}
JavaScript, PHP
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
function functionname(parameters) {
code
}
// This example defines a function.
function multiply(a,b) {
return a * b;
}
JavaScript, PHP
@SarahKiniry
#STC16
Creating Functions
// This is the format to define a function.
function functionname(parameters) {
code
}
// This example defines a function.
function multiply(a,b) {
return a * b;
}
JavaScript, PHP
@SarahKiniry
#STC16
// This uses the defined function.
multiply(3,2);
Creating Functions
// This is the format to define a function.
function functionname(parameters) {
code
}
// This example defines a function.
function multiply(a,b) {
return a * b;
}
JavaScript, PHP
@SarahKiniry
#STC16
// This uses the defined function.
multiply(3,2);
6
Creating Functions
# This is the format to define a function.
sub functionname {
code
}
Perl
@SarahKiniry
#STC16
Creating Functions
# This is the format to define a function.
sub functionname {
code
}
# This example defines a function.
sub dothingstovars {
$variables = @_;
do_something($variables);
return $variables;
}
Perl
@SarahKiniry
#STC16
Creating Functions
Perl
@SarahKiniry
#STC16
# This uses the defined function.
dothingstovars(“red”);
# This example defines a function.
sub dothingstovars {
$variables = @_;
do_something($variables);
return $variables;
}
# This is the format to define a function.
sub functionname {
code
}
Creating Functions
Perl
@SarahKiniry
#STC16
# This uses the defined function.
dothingstovars(“red”);
# This example defines a function.
sub dothingstovars {
$variables = @_;
do_something($variables);
return $variables;
}
# This is the format to define a function.
sub functionname {
code
}
blue
Creating Functions
# This is the format to define a function.
def functionname(parameters)
code
end
Ruby
@SarahKiniry
#STC16
Creating Functions
# This is the format to define a function.
def functionname(parameters)
code
end
# This example defines a function.
def Texas(name)
var = "Howdy, " + name
return var
end
Ruby
@SarahKiniry
#STC16
Creating Functions
Ruby
@SarahKiniry
#STC16
# This uses the defined function.
Texas(Bob)
# This is the format to define a function.
def functionname(parameters)
code
end
# This example defines a function.
def Texas(name)
var = "Howdy, " + name
return var
end
Creating Functions
Ruby
@SarahKiniry
#STC16
# This uses the defined function.
Texas(Bob)
# This is the format to define a function.
def functionname(parameters)
code
end
# This example defines a function.
def Texas(name)
var = "Howdy, " + name
return var
end
Howdy,
Bob
Creating Functions
# This is the format to define a function.
def functionname(parameters):
code
return[value]
Python
@SarahKiniry
#STC16
Creating Functions
# This example defines a function.
def print_return(my_words)
print my_words
return[]
Python
@SarahKiniry
#STC16
# This is the format to define a function.
def functionname(parameters):
code
return[value]
Creating Functions
Python
@SarahKiniry
#STC16
# This uses the defined function.
print_return(“Hey everybody!")
# This example defines a function.
def print_return(my_words)
print my_words
return[]
# This is the format to define a function.
def functionname(parameters):
code
return[value]
Creating Functions
Python
@SarahKiniry
#STC16
# This uses the defined function.
print_return(“Hey everybody!")
# This example defines a function.
def print_return(my_words)
print my_words
return[]
# This is the format to define a function.
def functionname(parameters):
code
return[value]
Hey
everybody!
Variables
The names of stored values that code uses to
perform actions. This can mean strings (text),
numbers, or boolean values (true/false).
There are also methods of storing groups of values,
such as arrays or hashes.
Variables
variable_name Java, JavaScript, C, C#, Python
$variable_name PHP, Perl, Ruby
@variable_name Perl, Ruby
%variable_name Perl
(and arrays
and hashes)
@SarahKiniry
#STC16
Important Value Types
Files example.txt, example.jpg, example.php
Directories
Linux: /example/directory or example/directory/
Windows: C:exampledirectory or
..exampledirectory
Settings managed, unmanaged; blue, green, red; 0, 1
@SarahKiniry
#STC16
Variables
my $file = example.txt;
$color = blue;
$do_something = 1;
@SarahKiniry
#STC16
Hello World!
The Hello World Story
1
2
3
What does the application do?
What text will the user see?
Which files or settings?
@SarahKiniry
#STC16
The Hello World Story
1
2
3
What does the application do?

This application displays a message to the user.
What text will the user see?
Which files or settings?
@SarahKiniry
#STC16
The Hello World Story
1
2
3
What does the application do?

This application displays a message to the user.
What text will the user see?

The user will see the text “Hello World.”
Which files or settings?
@SarahKiniry
#STC16
The Hello World Story
1
2
3
What does the application do?

This application displays a message to the user.
What text will the user see?

The user will see the text “Hello World.”
Which files or settings?

No other files or settings are involved.
@SarahKiniry
#STC16
Hello, Java!
/* This is a Hello World script. */
class HelloWorldApp {
public static void main(String[] args)
{
// Display the string.
System.out.println("Hello World!");
}
}
@SarahKiniry
#STC16
Hello, Java!
/* This is a Hello World script. */
class HelloWorldApp {
public static void main(String[] args)
{
// Display the string.
System.out.println("Hello World!");
}
}
@SarahKiniry
#STC16
Hello, Java!
/* This is a Hello World script. */
class HelloWorldApp {
public static void main(String[] args)
{
// Display the string.
System.out.println("Hello World!");
}
}
@SarahKiniry
#STC16
Hello, JavaScript!
<script language=“Javascript">
// Write to browser window.
document.write("Hello World!");
</script>
@SarahKiniry
#STC16
Hello, JavaScript!
<script language=“Javascript">
// Write to browser window.
document.write("Hello World!");
</script>
@SarahKiniry
#STC16
Hello, JavaScript!
<script language=“Javascript">
// Write to browser window.
document.write("Hello World!");
</script>
@SarahKiniry
#STC16
Hello, C!
/* Hello World */
void main()
{
printf("Hello World!");
}
@SarahKiniry
#STC16
Hello, C!
/* Hello World */
void main()
{
printf("Hello World!");
}
Hello, C!
/* Hello World */
void main()
{
printf("Hello World!");
}
Hello, C#!
/// Let’s say Hello.
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
}
}
}
@SarahKiniry
#STC16
Hello, C#!
/// Let’s say Hello.
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
}
}
}
Hello, C#!
/// Let’s say Hello.
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
}
}
}
Hello, PHP!
// Tell them hello in PHP.
<?php
echo "Hello World!";
?>
@SarahKiniry
#STC16
Hello, PHP!
// Tell them hello in PHP.
<?php
echo "Hello World!";
?>
Hello, PHP!
// Tell them hello in PHP.
<?php
echo "Hello World!";
?>
Hello, Perl!
#!/usr/bin/perl
# We’ll call this a Perl of wisdom.
print "Hello World!";
@SarahKiniry
#STC16
Hello, Perl!
#!/usr/bin/perl
# We’ll call this a Perl of wisdom.
print "Hello World!";
Hello, Perl!
#!/usr/bin/perl
# We’ll call this a Perl of wisdom.
print "Hello World!";
Hello, Ruby!
#!/usr/bin/ruby -w
# First Perl, now Ruby? Shiny.
puts "Hello, world!"
=begin
Really though, who knew there were two
programming languages named after
gemstones, even if one is kind of
misspelled?
=end
@SarahKiniry
#STC16
Hello, Ruby!
#!/usr/bin/ruby -w
# First Perl, now Ruby? Shiny.
puts "Hello, world!"
=begin
Really though, who knew there were two
programming languages named after
gemstones, even if one is kind of
misspelled?
=end
Hello, Ruby!
#!/usr/bin/ruby -w
# First Perl, now Ruby? Shiny.
puts "Hello, world!"
=begin
Really though, who knew there were two
programming languages named after
gemstones, even if one is kind of
misspelled?
=end
Hello, Python!
# A lot of programming languages use
# hashes for their comment character.
print("Hello, World!")
""" But they tend to diverge when it comes
to multiline comments. """
@SarahKiniry
#STC16
Hello, Python!
# A lot of programming languages use
# hashes for their comment character.
print("Hello, World!")
""" But they tend to diverge when it comes
to multiline comments. """
Hello, Python!
# A lot of programming languages use
# hashes for their comment character.
print("Hello, World!")
""" But they tend to diverge when it comes
to multiline comments. """
The Harder Stuff
More JavaScript
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
JavaScript code example from w3schools.com
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()"
src="pic_bulboff.gif" width="100" height="180">
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}
</script>
@SarahKiniry
#STC16
What’s The Story?
1
2
3
What does the application do?
What text will the user see?
Which files or settings?
@SarahKiniry
#STC16
What’s The Story?
1
2
3
What does the application do?

This application switches between two images.
What text will the user see?
Which files or settings?
@SarahKiniry
#STC16
What’s The Story?
1
2
3
What does the application do?

This application switches between two images.
What text will the user see?

“Javascript Can Change Images”
Which files or settings?
@SarahKiniry
#STC16
What’s The Story?
1
2
3
What does the application do?

This application switches between two images.
What text will the user see?

“Javascript Can Change Images”
Which files or settings?

pic_bulbon.gif and pic_bulboff.gif, width=100,
height=180
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
@SarahKiniry
#STC16
More JavaScript
JavaScript code example from w3schools.com
@SarahKiniry
#STC16
Questions?
@SarahKiniry
#STC16

More Related Content

What's hot (20)

PPT
Oops in PHP
Mindfire Solutions
 
ODP
Object Oriented Design Patterns for PHP
RobertGonzalez
 
PPTX
Subroutines
primeteacher32
 
PPTX
PHP Basics
Henry Osborne
 
PPT
Oops in PHP By Nyros Developer
Nyros Technologies
 
PDF
Creating native apps with WordPress
Marko Heijnen
 
PPT
CGI With Object Oriented Perl
Bunty Ray
 
PDF
Iq rails
Chatrapathi Yerra
 
ODP
PHP Web Programming
Muthuselvam RS
 
PPTX
Subroutines in perl
sana mateen
 
ODP
perl usage at database applications
Joe Jiang
 
PPT
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
PPT
Ruby For Java Programmers
Mike Bowler
 
PPT
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
PDF
Preparing for the next PHP version (5.6)
Damien Seguy
 
Oops in PHP
Mindfire Solutions
 
Object Oriented Design Patterns for PHP
RobertGonzalez
 
Subroutines
primeteacher32
 
PHP Basics
Henry Osborne
 
Oops in PHP By Nyros Developer
Nyros Technologies
 
Creating native apps with WordPress
Marko Heijnen
 
CGI With Object Oriented Perl
Bunty Ray
 
PHP Web Programming
Muthuselvam RS
 
Subroutines in perl
sana mateen
 
perl usage at database applications
Joe Jiang
 
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Class 3 - PHP Functions
Ahmed Swilam
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Ruby For Java Programmers
Mike Bowler
 
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Preparing for the next PHP version (5.6)
Damien Seguy
 

Viewers also liked (16)

PDF
LavaCon 2015 New Manager Boot Camp
crygula2
 
PDF
Fundamentos.de.matematica.elementar.vol.11.financeira.estatistica
Jose Cicero
 
PPTX
Energias alternativas
Mario Avalos Villarreal
 
PDF
【大阪】大阪へのUIJターンで府内企業の活性化につなげていきたい
さぶみっと!ヨクスル
 
PDF
伝統産業で地域活性!京都の伝統「着物」で、地域に雇用を創出する!【寺谷 卓也さん(京都着物レンタルさくら)】
さぶみっと!ヨクスル
 
PPTX
IPA KELAS 9 REPRODUKSI WANITA
ajengkartika123
 
PPTX
Los valores
Pablo Grandez Alvarado
 
PPTX
第六章 ユマニチュードの哲学~介護者とは何か~
Atsushi OMATA
 
DOC
RESUME OF AHSANUL KABIR
AHSANUL KABIR
 
ODP
10 popular software programs written in python
ATEES Industrial Training Pvt Ltd
 
ODP
Top 10 graphic and web design tools in 2015
ATEES Industrial Training Pvt Ltd
 
PPS
Trece Consejos para la Vida
erickeduproducciones
 
PDF
Information about WRAP
marianskeffington
 
PPTX
Давайте знакомые книжки откроем
Library43
 
PPTX
Самая, самое, самый
Library43
 
PDF
【concrete5】CMS夏祭り2015@mttokyo
Shinji Sakai
 
LavaCon 2015 New Manager Boot Camp
crygula2
 
Fundamentos.de.matematica.elementar.vol.11.financeira.estatistica
Jose Cicero
 
Energias alternativas
Mario Avalos Villarreal
 
【大阪】大阪へのUIJターンで府内企業の活性化につなげていきたい
さぶみっと!ヨクスル
 
伝統産業で地域活性!京都の伝統「着物」で、地域に雇用を創出する!【寺谷 卓也さん(京都着物レンタルさくら)】
さぶみっと!ヨクスル
 
IPA KELAS 9 REPRODUKSI WANITA
ajengkartika123
 
第六章 ユマニチュードの哲学~介護者とは何か~
Atsushi OMATA
 
RESUME OF AHSANUL KABIR
AHSANUL KABIR
 
10 popular software programs written in python
ATEES Industrial Training Pvt Ltd
 
Top 10 graphic and web design tools in 2015
ATEES Industrial Training Pvt Ltd
 
Trece Consejos para la Vida
erickeduproducciones
 
Information about WRAP
marianskeffington
 
Давайте знакомые книжки откроем
Library43
 
Самая, самое, самый
Library43
 
【concrete5】CMS夏祭り2015@mttokyo
Shinji Sakai
 
Ad

Similar to STC 2016 Programming Language Storytime (20)

PDF
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
lailoesakhan
 
PPT
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
PPT
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
PDF
ceng2404314334535365_hgf66353week_07-08_v0.8.pdf
eagac2004
 
PDF
Basics of Programming - A Review Guide
Benjamin Kissinger
 
PPTX
FUNCTIONINPYTHON.pptx
SheetalMavi2
 
PPTX
Ruby introduction part1
Brady Cheng
 
PPTX
FUNCTION CPU
Krushal Kakadia
 
PPTX
cbse class 12 Python Functions2 for class 12 .pptx
tcsonline1222
 
PPTX
functions
Makwana Bhavesh
 
PPTX
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
PDF
Function
GauravGautam224100
 
PDF
Functions
Learn By Watch
 
PDF
PerlIntro
tutorialsruby
 
PDF
PerlIntro
tutorialsruby
 
PDF
Ruby_Coding_Convention
Jesse Cai
 
PDF
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
prasadmutkule1
 
PPTX
User defined functions
Rokonuzzaman Rony
 
PDF
Functions2.pdf
prasnt1
 
PPT
2.overview of c++ ________lecture2
Warui Maina
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
lailoesakhan
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
ceng2404314334535365_hgf66353week_07-08_v0.8.pdf
eagac2004
 
Basics of Programming - A Review Guide
Benjamin Kissinger
 
FUNCTIONINPYTHON.pptx
SheetalMavi2
 
Ruby introduction part1
Brady Cheng
 
FUNCTION CPU
Krushal Kakadia
 
cbse class 12 Python Functions2 for class 12 .pptx
tcsonline1222
 
functions
Makwana Bhavesh
 
Intro To C++ - Class #19: Functions
Blue Elephant Consulting
 
Functions
Learn By Watch
 
PerlIntro
tutorialsruby
 
PerlIntro
tutorialsruby
 
Ruby_Coding_Convention
Jesse Cai
 
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
prasadmutkule1
 
User defined functions
Rokonuzzaman Rony
 
Functions2.pdf
prasnt1
 
2.overview of c++ ________lecture2
Warui Maina
 
Ad

STC 2016 Programming Language Storytime

  • 2. About Me Jason (hubby!) Backend Perl developer, extremely patient about being my in-home tutor, taught me a whole lot of The Things. Sarah Kiniry (me!) Technical Writer, former Stage Manager and Box Office Manager, needs-an-intervention level Trekkie. technicolorwriter.com
 @SarahKiniry @SarahKiniry #STC16
  • 3. If you can learn to read, you can learn to read code.
  • 4. Just read the story! 1 2 3 What does the application do? What text will the user see? Which files or settings? @SarahKiniry #STC16
  • 5. How do I find the story?
  • 6. Code Clues 1 2 3 What does the application do? What text will the user see? Which files or settings? Code Comments Function Names Variable (Setting) Names File Locations Print Functions Files Directories Variables Code comments, function names, setting names, and file locations. Display methods, like print, and other output functions. File names, file paths, and other variables. @SarahKiniry #STC16
  • 7. Comments Text in code that the computer doesn’t try to run. Instead, it’s there for the developer’s reference. Sometimes, it’s also used to temporarily “turn off” code without deleting it.
  • 8. Comments // Single-line comments // require a comment // for each line. do(thing); // comment /* Multi-line comments use beginning and end characters for multiple lines. */ Single-line comments… • Can be used on the same line as code (a trailing comment). • Comment character at the beginning of the comment only. • A line break ends the comment. Multi-line comments… • Comment character at the beginning and end of the comment. • Generally, these exist on separate lines from the code. @SarahKiniry #STC16
  • 9. Single Line // Java, JavaScript, C, C#, PHP # PHP, Perl, Ruby, Python @SarahKiniry #STC16
  • 10. Multi Line /* Comment */ Java, JavaScript, C, C#, PHP // Comment Comment C =pod =cut Perl =begin =end Ruby """ """ Python @SarahKiniry #STC16
  • 11. Functions Reusable code that performs one or more actions. Sometimes, the code that you’re looking at is a function, while sometimes it uses existing functions. * This is a lazy use of the term. These actions can be subroutines, methods, procedures, etc.
  • 12. Functions sub do_something { my $value = @_; if $value { return "Yay!"; } … do_something($value); Function definition… • Includes all of the code that will run anytime the function is used. • Creating a function that’s used elsewhere. • Sets the function name. Function use… • Could be a custom-written function, or one that’s built into the programming language. • Often, custom functions are defined in other code, not in the same file. @SarahKiniry #STC16
  • 14. Creating Functions // This is the format to define a function. class type functionname(parameters) { code } *Java uses a “class” structure, so when you see this in code it’s going to be nested in a class. Java*, C# @SarahKiniry #STC16
  • 15. Creating Functions // This is the format to define a function. class type functionname(parameters) { code } // This example defines a function. public static void printyay() { System.out.println ("Yay!"); } *Java uses a “class” structure, so when you see this in code it’s going to be nested in a class. Java*, C# @SarahKiniry #STC16
  • 16. Creating Functions // This is the format to define a function. class type functionname(parameters) { code } // This example defines a function. public static void printyay() { System.out.println ("Yay!"); } *Java uses a “class” structure, so when you see this in code it’s going to be nested in a class. Java*, C# @SarahKiniry #STC16 // This uses the defined function. printyay();
  • 17. Creating Functions // This is the format to define a function. class type functionname(parameters) { code } // This example defines a function. public static void printyay() { System.out.println ("Yay!"); } *Java uses a “class” structure, so when you see this in code it’s going to be nested in a class. Java*, C# @SarahKiniry #STC16 // This uses the defined function. printyay(); Yay!
  • 18. Creating Functions // This is the format to define a function. type functionname(parameters) { code } C @SarahKiniry #STC16
  • 19. Creating Functions // This is the format to define a function. type functionname(parameters) { code } // This example defines a function. int printyay() { printf("Yay!"); } C @SarahKiniry #STC16
  • 20. Creating Functions // This is the format to define a function. type functionname(parameters) { code } // This example defines a function. int printyay() { printf("Yay!"); } C @SarahKiniry #STC16 // This uses the defined function. printyay();
  • 21. Creating Functions // This is the format to define a function. type functionname(parameters) { code } // This example defines a function. int printyay() { printf("Yay!"); } C @SarahKiniry #STC16 // This uses the defined function. printyay(); Yay!
  • 22. Creating Functions // This is the format to define a function. function functionname(parameters) { code } JavaScript, PHP @SarahKiniry #STC16
  • 23. Creating Functions // This is the format to define a function. function functionname(parameters) { code } // This example defines a function. function multiply(a,b) { return a * b; } JavaScript, PHP @SarahKiniry #STC16
  • 24. Creating Functions // This is the format to define a function. function functionname(parameters) { code } // This example defines a function. function multiply(a,b) { return a * b; } JavaScript, PHP @SarahKiniry #STC16 // This uses the defined function. multiply(3,2);
  • 25. Creating Functions // This is the format to define a function. function functionname(parameters) { code } // This example defines a function. function multiply(a,b) { return a * b; } JavaScript, PHP @SarahKiniry #STC16 // This uses the defined function. multiply(3,2); 6
  • 26. Creating Functions # This is the format to define a function. sub functionname { code } Perl @SarahKiniry #STC16
  • 27. Creating Functions # This is the format to define a function. sub functionname { code } # This example defines a function. sub dothingstovars { $variables = @_; do_something($variables); return $variables; } Perl @SarahKiniry #STC16
  • 28. Creating Functions Perl @SarahKiniry #STC16 # This uses the defined function. dothingstovars(“red”); # This example defines a function. sub dothingstovars { $variables = @_; do_something($variables); return $variables; } # This is the format to define a function. sub functionname { code }
  • 29. Creating Functions Perl @SarahKiniry #STC16 # This uses the defined function. dothingstovars(“red”); # This example defines a function. sub dothingstovars { $variables = @_; do_something($variables); return $variables; } # This is the format to define a function. sub functionname { code } blue
  • 30. Creating Functions # This is the format to define a function. def functionname(parameters) code end Ruby @SarahKiniry #STC16
  • 31. Creating Functions # This is the format to define a function. def functionname(parameters) code end # This example defines a function. def Texas(name) var = "Howdy, " + name return var end Ruby @SarahKiniry #STC16
  • 32. Creating Functions Ruby @SarahKiniry #STC16 # This uses the defined function. Texas(Bob) # This is the format to define a function. def functionname(parameters) code end # This example defines a function. def Texas(name) var = "Howdy, " + name return var end
  • 33. Creating Functions Ruby @SarahKiniry #STC16 # This uses the defined function. Texas(Bob) # This is the format to define a function. def functionname(parameters) code end # This example defines a function. def Texas(name) var = "Howdy, " + name return var end Howdy, Bob
  • 34. Creating Functions # This is the format to define a function. def functionname(parameters): code return[value] Python @SarahKiniry #STC16
  • 35. Creating Functions # This example defines a function. def print_return(my_words) print my_words return[] Python @SarahKiniry #STC16 # This is the format to define a function. def functionname(parameters): code return[value]
  • 36. Creating Functions Python @SarahKiniry #STC16 # This uses the defined function. print_return(“Hey everybody!") # This example defines a function. def print_return(my_words) print my_words return[] # This is the format to define a function. def functionname(parameters): code return[value]
  • 37. Creating Functions Python @SarahKiniry #STC16 # This uses the defined function. print_return(“Hey everybody!") # This example defines a function. def print_return(my_words) print my_words return[] # This is the format to define a function. def functionname(parameters): code return[value] Hey everybody!
  • 38. Variables The names of stored values that code uses to perform actions. This can mean strings (text), numbers, or boolean values (true/false). There are also methods of storing groups of values, such as arrays or hashes.
  • 39. Variables variable_name Java, JavaScript, C, C#, Python $variable_name PHP, Perl, Ruby @variable_name Perl, Ruby %variable_name Perl (and arrays and hashes) @SarahKiniry #STC16
  • 40. Important Value Types Files example.txt, example.jpg, example.php Directories Linux: /example/directory or example/directory/ Windows: C:exampledirectory or ..exampledirectory Settings managed, unmanaged; blue, green, red; 0, 1 @SarahKiniry #STC16
  • 41. Variables my $file = example.txt; $color = blue; $do_something = 1; @SarahKiniry #STC16
  • 43. The Hello World Story 1 2 3 What does the application do? What text will the user see? Which files or settings? @SarahKiniry #STC16
  • 44. The Hello World Story 1 2 3 What does the application do?
 This application displays a message to the user. What text will the user see? Which files or settings? @SarahKiniry #STC16
  • 45. The Hello World Story 1 2 3 What does the application do?
 This application displays a message to the user. What text will the user see?
 The user will see the text “Hello World.” Which files or settings? @SarahKiniry #STC16
  • 46. The Hello World Story 1 2 3 What does the application do?
 This application displays a message to the user. What text will the user see?
 The user will see the text “Hello World.” Which files or settings?
 No other files or settings are involved. @SarahKiniry #STC16
  • 47. Hello, Java! /* This is a Hello World script. */ class HelloWorldApp { public static void main(String[] args) { // Display the string. System.out.println("Hello World!"); } } @SarahKiniry #STC16
  • 48. Hello, Java! /* This is a Hello World script. */ class HelloWorldApp { public static void main(String[] args) { // Display the string. System.out.println("Hello World!"); } } @SarahKiniry #STC16
  • 49. Hello, Java! /* This is a Hello World script. */ class HelloWorldApp { public static void main(String[] args) { // Display the string. System.out.println("Hello World!"); } } @SarahKiniry #STC16
  • 50. Hello, JavaScript! <script language=“Javascript"> // Write to browser window. document.write("Hello World!"); </script> @SarahKiniry #STC16
  • 51. Hello, JavaScript! <script language=“Javascript"> // Write to browser window. document.write("Hello World!"); </script> @SarahKiniry #STC16
  • 52. Hello, JavaScript! <script language=“Javascript"> // Write to browser window. document.write("Hello World!"); </script> @SarahKiniry #STC16
  • 53. Hello, C! /* Hello World */ void main() { printf("Hello World!"); } @SarahKiniry #STC16
  • 54. Hello, C! /* Hello World */ void main() { printf("Hello World!"); }
  • 55. Hello, C! /* Hello World */ void main() { printf("Hello World!"); }
  • 56. Hello, C#! /// Let’s say Hello. using System; namespace HelloWorld { class Hello { static void Main() { Console.WriteLine("Hello World!"); } } } @SarahKiniry #STC16
  • 57. Hello, C#! /// Let’s say Hello. using System; namespace HelloWorld { class Hello { static void Main() { Console.WriteLine("Hello World!"); } } }
  • 58. Hello, C#! /// Let’s say Hello. using System; namespace HelloWorld { class Hello { static void Main() { Console.WriteLine("Hello World!"); } } }
  • 59. Hello, PHP! // Tell them hello in PHP. <?php echo "Hello World!"; ?> @SarahKiniry #STC16
  • 60. Hello, PHP! // Tell them hello in PHP. <?php echo "Hello World!"; ?>
  • 61. Hello, PHP! // Tell them hello in PHP. <?php echo "Hello World!"; ?>
  • 62. Hello, Perl! #!/usr/bin/perl # We’ll call this a Perl of wisdom. print "Hello World!"; @SarahKiniry #STC16
  • 63. Hello, Perl! #!/usr/bin/perl # We’ll call this a Perl of wisdom. print "Hello World!";
  • 64. Hello, Perl! #!/usr/bin/perl # We’ll call this a Perl of wisdom. print "Hello World!";
  • 65. Hello, Ruby! #!/usr/bin/ruby -w # First Perl, now Ruby? Shiny. puts "Hello, world!" =begin Really though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled? =end @SarahKiniry #STC16
  • 66. Hello, Ruby! #!/usr/bin/ruby -w # First Perl, now Ruby? Shiny. puts "Hello, world!" =begin Really though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled? =end
  • 67. Hello, Ruby! #!/usr/bin/ruby -w # First Perl, now Ruby? Shiny. puts "Hello, world!" =begin Really though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled? =end
  • 68. Hello, Python! # A lot of programming languages use # hashes for their comment character. print("Hello, World!") """ But they tend to diverge when it comes to multiline comments. """ @SarahKiniry #STC16
  • 69. Hello, Python! # A lot of programming languages use # hashes for their comment character. print("Hello, World!") """ But they tend to diverge when it comes to multiline comments. """
  • 70. Hello, Python! # A lot of programming languages use # hashes for their comment character. print("Hello, World!") """ But they tend to diverge when it comes to multiline comments. """
  • 72. More JavaScript <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> JavaScript code example from w3schools.com @SarahKiniry #STC16
  • 73. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 74. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 75. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 76. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 77. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 78. More JavaScript JavaScript code example from w3schools.com <h1>JavaScript Can Change Images</h1> <img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> @SarahKiniry #STC16
  • 79. What’s The Story? 1 2 3 What does the application do? What text will the user see? Which files or settings? @SarahKiniry #STC16
  • 80. What’s The Story? 1 2 3 What does the application do?
 This application switches between two images. What text will the user see? Which files or settings? @SarahKiniry #STC16
  • 81. What’s The Story? 1 2 3 What does the application do?
 This application switches between two images. What text will the user see?
 “Javascript Can Change Images” Which files or settings? @SarahKiniry #STC16
  • 82. What’s The Story? 1 2 3 What does the application do?
 This application switches between two images. What text will the user see?
 “Javascript Can Change Images” Which files or settings?
 pic_bulbon.gif and pic_bulboff.gif, width=100, height=180 @SarahKiniry #STC16
  • 83. More JavaScript JavaScript code example from w3schools.com @SarahKiniry #STC16
  • 84. More JavaScript JavaScript code example from w3schools.com @SarahKiniry #STC16