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

PDF
Drupaljam xl 2019 presentation multilingualism makes better programmers
PPTX
Arrays &amp; functions in php
PPTX
Ruby from zero to hero
PPT
Php Reusing Code And Writing Functions
PDF
Introduction to web programming with JavaScript
PPTX
Bioinformatics p1-perl-introduction v2013
PDF
Javascript
Drupaljam xl 2019 presentation multilingualism makes better programmers
Arrays &amp; functions in php
Ruby from zero to hero
Php Reusing Code And Writing Functions
Introduction to web programming with JavaScript
Bioinformatics p1-perl-introduction v2013
Javascript

What's hot (20)

PPT
Oops in PHP
ODP
Object Oriented Design Patterns for PHP
PPTX
Subroutines
PPTX
PHP Basics
PPT
Oops in PHP By Nyros Developer
PDF
Creating native apps with WordPress
PPT
CGI With Object Oriented Perl
PDF
ODP
PHP Web Programming
PPTX
Subroutines in perl
ODP
perl usage at database applications
PPT
PHP - Introduction to PHP Functions
PDF
Php Tutorials for Beginners
PPT
Class 3 - PHP Functions
PPT
Class 2 - Introduction to PHP
PPT
Ruby For Java Programmers
PPT
Class 7 - PHP Object Oriented Programming
PDF
Preparing for the next PHP version (5.6)
Oops in PHP
Object Oriented Design Patterns for PHP
Subroutines
PHP Basics
Oops in PHP By Nyros Developer
Creating native apps with WordPress
CGI With Object Oriented Perl
PHP Web Programming
Subroutines in perl
perl usage at database applications
PHP - Introduction to PHP Functions
Php Tutorials for Beginners
Class 3 - PHP Functions
Class 2 - Introduction to PHP
Ruby For Java Programmers
Class 7 - PHP Object Oriented Programming
Preparing for the next PHP version (5.6)
Ad

Viewers also liked (16)

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

Similar to STC 2016 Programming Language Storytime (20)

PPTX
Building maintainable javascript applications
PDF
In-Depth Guide On WordPress Coding Standards For PHP & HTML
PDF
JavaScript and UI Architecture Best Practices
PPT
PHP-03-Functions.ppt
PPT
PHP-03-Functions.ppt
PPT
Javascript sivasoft
PPT
Java findamentals2
PPT
Java findamentals2
PPTX
Licão 13 functions
KEY
A tour on ruby and friends
KEY
Ruby/Rails
PDF
Painless Javascript Unit Testing
ODP
Bring the fun back to java
PPTX
Struts 2
PPT
Intro Java Rev010
PDF
PHP Reviewer
PDF
Lettering js
KEY
Dsl
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Building maintainable javascript applications
In-Depth Guide On WordPress Coding Standards For PHP & HTML
JavaScript and UI Architecture Best Practices
PHP-03-Functions.ppt
PHP-03-Functions.ppt
Javascript sivasoft
Java findamentals2
Java findamentals2
Licão 13 functions
A tour on ruby and friends
Ruby/Rails
Painless Javascript Unit Testing
Bring the fun back to java
Struts 2
Intro Java Rev010
PHP Reviewer
Lettering js
Dsl
WebNet Conference 2012 - Designing complex applications using html5 and knock...

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