dig1108 lesson 3

13
INTRO TO SERVER SIDE PROGRAMMING Lesson Three Friday, September 13, 13

Upload: vc-dig1108-fall-2013

Post on 19-Jun-2015

69 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Dig1108 Lesson 3

INTRO TO SERVER SIDE PROGRAMMINGLesson Three

Friday, September 13, 13

Page 2: Dig1108 Lesson 3

Recap - What Have We Found?

Literalsboolean - True/False

integer

float - decimal numbers

string - text

array - ordered key/value pairs

object - literal within class

Null - no value

Friday, September 13, 13

Page 3: Dig1108 Lesson 3

Recap Continued

OperatorsArithmetic - $newvalue = $oldvalue + 1;

Assignment - $newervalue = 10;

Comparison - $newvalue != $oldvalue;

String Operatorsvar_dump('foo' . 'bar');$a = 'foo'; a .= 'bar';var_dump($a);

Friday, September 13, 13

Page 4: Dig1108 Lesson 3

Order of Operations

PHP (and most languages) follows Operator Precedence rulesThese allow for unambiguous statementsParentheses can be used to override default Operator Precedence or to add visual clarity

$taxable_income = $wages + $earnings - $deductions;

$taxable_income = $wages + ( $earnings - $deductions );

Friday, September 13, 13

Page 5: Dig1108 Lesson 3

Programming Blocks

Blocks are sections of code grouped togetherBlocks consist of declarations and statementsPHP organizes statements into blocks with { }

Conventions dictate indentation for readability

{$foo=$bar+$bat;echo $foo;}

{ $foo = $bar + $bat; echo $foo;}

Friday, September 13, 13

Page 6: Dig1108 Lesson 3

Coding ConventionsA set of guidelines for a specific programming language of recommended styles, practices & methods for each aspect of a programCovers things like file organization, indentation, comments, declarations, statements, white space, naming conventions, practices & principlesThis improves the readability of code and makes software maintenance easier.Conventions enforced by humans, not compilers

Friday, September 13, 13

Page 7: Dig1108 Lesson 3

Ease of Reading/Ease of Use$UP=6;DN=19;$x=0;while(++$x<=24){echo "hour $x: "; if($x>+$UP&&$X<+$DN);echo "sun is up"; else echo "sun is down": echo "\n"; }

define( 'SUNRISE', 6 );define( 'SUNSET', 19 );

$hours = range( 1, 24);

foreach ( $hours as $hour ) { // ternary operation $up_or_down = ( ( $hour >= SUNRISE and $hour <= SUNSET ) ? 'up' : 'down' );

echo "hour {$hour}: ", "sun is {$up_or_down}", "\n";}

Friday, September 13, 13

Page 8: Dig1108 Lesson 3

ASSIGNMENT 3.1Good Code, Bad Code

Friday, September 13, 13

Page 9: Dig1108 Lesson 3

Good Code, Bad CodeLog in to Github, then into Cloud9 Using GithubLook through your forked projects for a block (~100) lines of code that are either very hard or very easy to read based on the coding styleCopy & paste into a file named assignment-4.1.mdMake a list with your partner of ways that the code style could be improved in each of your examplesSave files to share with the class. Push to Github? (https://help.github.com/articles/create-a-repo)

Friday, September 13, 13

Page 10: Dig1108 Lesson 3

Git and Github - Here to HelpGit is your robot friend that remembers what you tell it to remember, and only thatThis robot recognizes when things have changedIt knows how to remember, just not whenGit can tell you what changed and when, you use comments to tell it (and yourself) whyIf you ask nicely (-h or --help) the robot will helpThis robot is well organized and can track branches of changed code

Friday, September 13, 13

Page 11: Dig1108 Lesson 3

Basic git Commandsgit branch - what branches are there & which am I on?

git status - what files have I changed or created?

git add (files) - consider this stuff for remembering

git commit (files) - I really want you to remember what I've considered via git add

git push [remote [branch] ] - tell the robot named "remote" (default is "origin") about my changes in "branch" (default is "master")

git fetch [remote] - ask the robot named "remote" for changes or branches that you don't know about yet

git merge [branch] - attempt to combine changes in "branch"

Friday, September 13, 13

Page 12: Dig1108 Lesson 3

ASSIGNMENT 3.2fetch and merge

Friday, September 13, 13

Page 13: Dig1108 Lesson 3

Let's Merge AgainIn Cloud 9:

git remote add upstream \https://github.com/vc-dig1108-fall-2013/assignments.gitgit fetch upstreamgit merge upstream/master

Open the file named "homework-4.1.md"

Add your name to bottom of the file and save

Commit the file & push to your Github acct. (hint: "origin")

https://help.github.com/articles/create-a-repohttps://help.github.com/articles/fork-a-repo

Friday, September 13, 13