stc 2016 programming language storytime

85
Sarah Kiniry cPanel, Inc. Storytime Programming Language

Upload: sarah-kiniry

Post on 08-Feb-2017

70 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: STC 2016 Programming Language Storytime

Sarah Kiniry cPanel, Inc.

StorytimeProgramming Language

Page 2: STC 2016 Programming Language Storytime

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

Page 3: STC 2016 Programming Language Storytime

If you can learn to read, you can learn to read code.

Page 4: STC 2016 Programming Language Storytime

Just read the story!

1

2

3

What does the application do?

What text will the user see?

Which files or settings?

@SarahKiniry #STC16

Page 5: STC 2016 Programming Language Storytime

How do I find the story?

Page 6: STC 2016 Programming Language Storytime

Code Clues

1

2

3

What does the application do?

What text will the user see?

Which files or settings?

Code CommentsFunction Names

Variable (Setting) Names

File LocationsPrint 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

Page 7: STC 2016 Programming Language Storytime

CommentsText 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.

Page 8: STC 2016 Programming Language Storytime

Comments

// Single-line comments// require a comment// for each line.

do(thing); // comment

/* Multi-linecomments 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

Page 9: STC 2016 Programming Language Storytime

Single Line

// Java, JavaScript, C, C#, PHP

# PHP, Perl, Ruby, Python

@SarahKiniry #STC16

Page 10: STC 2016 Programming Language Storytime

Multi Line

/* Comment */ Java, JavaScript, C, C#, PHP

// Comment \ Comment

C

=pod =cut

Perl

=begin =end

Ruby

""" """ Python

@SarahKiniry #STC16

Page 11: STC 2016 Programming Language Storytime

FunctionsReusable 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.

Page 12: STC 2016 Programming Language Storytime

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

Page 13: STC 2016 Programming Language Storytime

Using Functions

function($value)

function "$value"

@SarahKiniry #STC16

Page 14: STC 2016 Programming Language Storytime

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

Page 15: STC 2016 Programming Language Storytime

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

Page 16: STC 2016 Programming Language Storytime

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();

Page 17: STC 2016 Programming Language Storytime

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!

Page 18: STC 2016 Programming Language Storytime

Creating Functions

// This is the format to define a function.type functionname(parameters) { code }

C

@SarahKiniry #STC16

Page 19: STC 2016 Programming Language Storytime

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

Page 20: STC 2016 Programming Language Storytime

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();

Page 21: STC 2016 Programming Language Storytime

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!

Page 22: STC 2016 Programming Language Storytime

Creating Functions

// This is the format to define a function.function functionname(parameters) { code }

JavaScript, PHP

@SarahKiniry #STC16

Page 23: STC 2016 Programming Language Storytime

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

Page 24: STC 2016 Programming Language Storytime

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);

Page 25: STC 2016 Programming Language Storytime

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

Page 26: STC 2016 Programming Language Storytime

Creating Functions

# This is the format to define a function.sub functionname { code }

Perl

@SarahKiniry #STC16

Page 27: STC 2016 Programming Language Storytime

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

Page 28: STC 2016 Programming Language Storytime

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 }

Page 29: STC 2016 Programming Language Storytime

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

Page 30: STC 2016 Programming Language Storytime

Creating Functions

# This is the format to define a function.def functionname(parameters) code end

Ruby

@SarahKiniry #STC16

Page 31: STC 2016 Programming Language Storytime

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

Page 32: STC 2016 Programming Language Storytime

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

Page 33: STC 2016 Programming Language Storytime

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

Page 34: STC 2016 Programming Language Storytime

Creating Functions

# This is the format to define a function.def functionname(parameters): code return[value]

Python

@SarahKiniry #STC16

Page 35: STC 2016 Programming Language Storytime

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]

Page 36: STC 2016 Programming Language Storytime

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]

Page 37: STC 2016 Programming Language Storytime

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!

Page 38: STC 2016 Programming Language Storytime

VariablesThe 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.

Page 39: STC 2016 Programming Language Storytime

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

Page 40: STC 2016 Programming Language Storytime

Important Value Types

Files example.txt, example.jpg, example.php

DirectoriesLinux: /example/directory or example/directory/

Windows: C:\example\directory or ..\example\directory\

Settings managed, unmanaged; blue, green, red; 0, 1

@SarahKiniry #STC16

Page 41: STC 2016 Programming Language Storytime

Variables

my $file = example.txt;

$color = blue;

$do_something = 1;

@SarahKiniry #STC16

Page 42: STC 2016 Programming Language Storytime

Hello World!

Page 43: STC 2016 Programming Language Storytime

The Hello World Story

1

2

3

What does the application do?

What text will the user see?

Which files or settings?

@SarahKiniry #STC16

Page 44: STC 2016 Programming Language Storytime

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

Page 45: STC 2016 Programming Language Storytime

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

Page 46: STC 2016 Programming Language Storytime

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

Page 47: STC 2016 Programming Language Storytime

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

Page 48: STC 2016 Programming Language Storytime

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

Page 49: STC 2016 Programming Language Storytime

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

Page 50: STC 2016 Programming Language Storytime

Hello, JavaScript!

<script language=“Javascript">

// Write to browser window.document.write("Hello World!");

</script>

@SarahKiniry #STC16

Page 51: STC 2016 Programming Language Storytime

Hello, JavaScript!

<script language=“Javascript">

// Write to browser window.document.write("Hello World!");

</script>

@SarahKiniry #STC16

Page 52: STC 2016 Programming Language Storytime

Hello, JavaScript!

<script language=“Javascript">

// Write to browser window.document.write("Hello World!");

</script>

@SarahKiniry #STC16

Page 53: STC 2016 Programming Language Storytime

Hello, C!

/* Hello World */

void main(){ printf("Hello World!");

}

@SarahKiniry #STC16

Page 54: STC 2016 Programming Language Storytime

Hello, C!

/* Hello World */

void main(){ printf("Hello World!");

}

Page 55: STC 2016 Programming Language Storytime

Hello, C!

/* Hello World */

void main(){ printf("Hello World!");

}

Page 56: STC 2016 Programming Language Storytime

Hello, C#!

/// Let’s say Hello.using System;namespace HelloWorld{ class Hello { static void Main() { Console.WriteLine("Hello World!"); } }}

@SarahKiniry #STC16

Page 57: STC 2016 Programming Language Storytime

Hello, C#!

/// Let’s say Hello.using System;namespace HelloWorld{ class Hello { static void Main() { Console.WriteLine("Hello World!"); } }}

Page 58: STC 2016 Programming Language Storytime

Hello, C#!

/// Let’s say Hello.using System;namespace HelloWorld{ class Hello { static void Main() { Console.WriteLine("Hello World!"); } }}

Page 59: STC 2016 Programming Language Storytime

Hello, PHP!

// Tell them hello in PHP.<?phpecho "Hello World!";?>

@SarahKiniry #STC16

Page 60: STC 2016 Programming Language Storytime

Hello, PHP!

// Tell them hello in PHP.<?phpecho "Hello World!";?>

Page 61: STC 2016 Programming Language Storytime

Hello, PHP!

// Tell them hello in PHP.<?phpecho "Hello World!";?>

Page 62: STC 2016 Programming Language Storytime

Hello, Perl!

#!/usr/bin/perl

# We’ll call this a Perl of wisdom.

print "Hello World!";

@SarahKiniry #STC16

Page 63: STC 2016 Programming Language Storytime

Hello, Perl!

#!/usr/bin/perl

# We’ll call this a Perl of wisdom.

print "Hello World!";

Page 64: STC 2016 Programming Language Storytime

Hello, Perl!

#!/usr/bin/perl

# We’ll call this a Perl of wisdom.

print "Hello World!";

Page 65: STC 2016 Programming Language Storytime

Hello, Ruby!

#!/usr/bin/ruby -w

# First Perl, now Ruby? Shiny.

puts "Hello, world!"

=beginReally though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled?=end

@SarahKiniry #STC16

Page 66: STC 2016 Programming Language Storytime

Hello, Ruby!

#!/usr/bin/ruby -w

# First Perl, now Ruby? Shiny.

puts "Hello, world!"

=beginReally though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled?=end

Page 67: STC 2016 Programming Language Storytime

Hello, Ruby!

#!/usr/bin/ruby -w

# First Perl, now Ruby? Shiny.

puts "Hello, world!"

=beginReally though, who knew there were two programming languages named after gemstones, even if one is kind of misspelled?=end

Page 68: STC 2016 Programming Language Storytime

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

Page 69: STC 2016 Programming Language Storytime

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. """

Page 70: STC 2016 Programming Language Storytime

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. """

Page 71: STC 2016 Programming Language Storytime

The Harder Stuff

Page 72: STC 2016 Programming Language Storytime

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

Page 73: STC 2016 Programming Language Storytime

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

Page 74: STC 2016 Programming Language Storytime

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

Page 75: STC 2016 Programming Language Storytime

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

Page 76: STC 2016 Programming Language Storytime

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

Page 77: STC 2016 Programming Language Storytime

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

Page 78: STC 2016 Programming Language Storytime

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

Page 79: STC 2016 Programming Language Storytime

What’s The Story?

1

2

3

What does the application do?

What text will the user see?

Which files or settings?

@SarahKiniry #STC16

Page 80: STC 2016 Programming Language Storytime

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

Page 81: STC 2016 Programming Language Storytime

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

Page 82: STC 2016 Programming Language Storytime

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

Page 83: STC 2016 Programming Language Storytime

More JavaScript

JavaScript code example from w3schools.com

@SarahKiniry #STC16

Page 84: STC 2016 Programming Language Storytime

More JavaScript

JavaScript code example from w3schools.com

@SarahKiniry #STC16

Page 85: STC 2016 Programming Language Storytime

Questions?

@SarahKiniry #STC16