14
INTRO TO SERVER SIDE PROGRAMMING Week Four Friday, September 20, 13

DIG1108 Lesson 4

Embed Size (px)

Citation preview

Page 1: DIG1108 Lesson 4

INTRO TO SERVER SIDE PROGRAMMINGWeek Four

Friday, September 20, 13

Page 2: DIG1108 Lesson 4

Basic Git Workflow ReviewSave and test your work often.

If it tests ok, add then commit your work (git add & git commit respectively)

Need to work alone? Work on a branch (git branch & git checkout or git checkout -b for short)Done or need to share your work? Send your work to remote (git push)

Back to work? Get the latest code (git fetch), then include it (git merge or git rebase)

Need to make a whole project your own? Copy it (git clone), then add it as remote and (git pull)

Friday, September 20, 13

Page 3: DIG1108 Lesson 4

CONDITIONAL LOGICIf This, Then That

Friday, September 20, 13

Page 4: DIG1108 Lesson 4

Friday, September 20, 13

Page 5: DIG1108 Lesson 4

Conditional Logic - In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.

Computer Science depends heavily on Boolean Algebra for conditional logic.

"If this thing is true, then do this. If not, do that."

Friday, September 20, 13

Page 6: DIG1108 Lesson 4

Guarding ExpressionsGuarding - In computer programming, a guard is a boolean expression that must evaluate to true if the program execution is to continue in the branch in question.Boolean expressions in conditional statements usually also fit this definition of a guard although they are called conditions.

if( ! isset($something) ) $something = 'some value';do_something_with($something);

$something = ( isset($something) ? $something : 'default' );

$something = do_something_important() or die('error message');

use_the_variable($something);

$something = do_something_important();if ( $something == false ) die('error message');

Friday, September 20, 13

Page 7: DIG1108 Lesson 4

Can I go to the Park?Boolean values can be combined with logical operators

The order in which conditionals are evaluated matters

$permission_from_mom = $mom->request('go_to_park');$permission_from_dad = $dad->request('go_to_park');

$permisson_from_both = ( $permission_from_mom and $permission_from_dad);$permisson_from_either = ( $permission_from_mom or $permission_from_dad);$permisson_from_one = ( $permission_from_mom xor $permission_from_dad);

Friday, September 20, 13

Page 8: DIG1108 Lesson 4

Workflow Diagrams & Truth Tables

Friday, September 20, 13

Page 9: DIG1108 Lesson 4

Nested ConditionalsConditionals can also be nested:

if ( empty($handedness) ) { if ( test_lefty() and test_righty() ) $handedness = 'Ambidextrous';

else if ( test_lefty() ) $handedness = 'Left Handed';

else if ( test_righty() ) $handedness = 'Right Handed';

else $handedness = 'You Have No Hands!';}

echo $handedness;

Friday, September 20, 13

Page 10: DIG1108 Lesson 4

Nested More!Nested conditionals can be written multiple ways:

if ( empty($handedness) ) { if ( test_lefty() ) { if( test_righty() ) $handedness = 'Ambidextrous';

else $handedness = ' Left Handed'; } else if ( test_righty() ) $handedness = 'Right Handed';

else $handedness = 'You Have No Hands!';}

echo $handedness;

Friday, September 20, 13

Page 11: DIG1108 Lesson 4

ASSIGNMENT 4.1Diagramming Conditional Logic

Friday, September 20, 13

Page 12: DIG1108 Lesson 4

Diagramming LogicPartner up and find a project with some if-then-else logic to examine, particularly nested logicIndividually, sketch a simple workflow diagram of the logic and assemble a truth table. Discuss any differences that you may have together when doneCollaborate to make one workflow diagram and truth table to show and explain to the class

Friday, September 20, 13

Page 13: DIG1108 Lesson 4

Log in to Cloud9 and pull up homework-5.1.md in your workspace (you should have this already)

Find the WordPress project on Github, fork it to your account, then clone it into a Cloud9 WorkspaceLook for some branching if-then-else logic in the code. Look for good conditionals and guarding statementsCopy and paste some examples that you find into your homework and attempt to identify the conditionals with comments ("If mom says yes", "if right handed")Save your file locally after review, add and commit it, then push your changes to Github

Friday, September 20, 13

Page 14: DIG1108 Lesson 4

ASSIGNMENT 4.2Branching Logic in WordPress

Friday, September 20, 13