SlideShare a Scribd company logo
1 of 24
Talk: Building High Productivity
Applications
September 17, 2016
Hutomo Sugianto
Tech Evangelist
Kudo Teknologi Indonesia
e: hutomo@kudo.co.id
Concept: Software System vs Software
Software/
Application
Software
“System”
Architecture/
Construction
Interface and
Integration
Common problems in Software Development Term
Background
Bad Code:
Hard to understand
Poor
Collaboration
Code
Complexity
One of the solutions
Crystal Clear:
Easy to understand
High Quality
Code
Improve
Collaboration
Minimum
Complexity
Building High Productivity Application
Outline
Control Structure: What
Control Issues
Dealing with Complexity: Why
Control Structure
High Productivity Applications
Control Structure
A control structure is a block of programming that analyzes variables and chooses
a direction in which to go based on given parameters.
● Code Flow - top to bottom
● Hit a point where it needs to make a decision
● Strict set of rules to decide which direction to go
● So, this decision that must be made, that will in turn effect the flow of code, is
known as a control structure!
Control Structure
Big contributor to overall program complexity.
Conditionals/selection:
● if
● if/else
● switch
Loop/repetition:
● while
● do/while
Control Issues
● Boolean Expressions
● Taming Dangerously Deep
Nesting
Boolean Expressions
● Use True or False for Boolean
Tests
Use the identifiers true and false
in boolean expressions rather
than using values like 0 and 1.
Bad Example:
<?php
$printerError = true;
if ($printerError == 0)
{
initializePrinter();
}
if ($printerError == 1)
{
notifyUserOfError();
}
Boolean Expressions
● Compare boolean values to true
and false implicitly
You can write clearer tests by
treating the expressions as
boolean expressions
<?php
// this code
while (!$done ) {
// put code here
}
while ( $a > $b ) {
// put code here
}
// is better than
while ( $done = false ) {
// put code here
}
while ( ($a > $b) = true ) {
// put code here
}
Boolean Expressions
● Making complicated boolean
expression simple
1. Break complicated tests into
partial tests with new boolean
variables
<?php
// this code
function status($value = false){
return $value;
}
$status = status((3+(5^2))*0);
if($status) {
// put code here
}
// is better than
if(status((3+(5^2))*0)){
// put code here
}
Boolean
Expressions
● Making complicated
boolean expression
simple
2. Move complicated
expression into boolean
functions
<?php
// this code
function userStatus($registered, $verified, $spam){
if($registered AND $verified AND !$spam){
return true;
}
else {
return false;
}
}
if(userStatus(true, false, true)){
// put code here
}
// is better than
if($userRegistered AND $userVerified
AND ($spam == false))
{
// put code here
}
Boolean Expressions
● Guidelines for Comparisons to 0
Programming languages use 0 for several purposes. It’s a numeric value. It’s a
null terminator in a string. It’s false in logical expressions. Because it’s used for
so many purposes, you should write code that highlights the specific way 0 is
used.
Boolean Expressions
● Guidelines for Comparisons to 0
1. Compare logical variables
implicitly
2. Compare numbers to 0
you should compare numeric
expressions explicitly.
<?php
// 1. Compare logical variables
// implicitly
while ( !$done ) {
// put code here
}
// Compare numbers to 0
while ( $balance != 0 ) {
// put code here
}
// rather than
while ( $balance ) {
// put code here
}
Taming Dangerously Deep Nesting
Excessive indentation, or “nesting,” has been pilloried in computing literature for
25 years and is still one of the chief culprits in confusing code.
Deep nesting works against Managing Complexity. That is reason enough to avoid
deep nesting.
It’s not hard to avoid deep nesting. If you have deep nesting, you can redesign the
tests performed in the if and else clauses or you can refactor code into simpler
routines.
Taming Dangerously Deep Nesting
1. Simplify a nested if by using a
break block.
This technique is uncommon enough
that it should be used only when your
entire team is familiar with it and
when it has been adopted by the
team as an accepted coding practice.
<?php
function validateInput($input = [])
{
if(empty($input[‘name’])){
return false;
}
if(empty($input[‘email’])){
return false;
}
}
$input = [‘name’ => ‘CodeSaya’];
validateInput($input);
Taming Dangerously Deep Nesting
2. Convert a nested if to a set of if-
then-elses
Suppose you have a bushy decision
tree like this:
This test is poorly organized in several ways,
one of which is that the tests are redundant.
<?php
// bad example
if ( 10 < $quantity ) {
if ( 100 < $quantity ) {
if ( 1000 < $quantity
) {
$discount =
0.10;
}
else {
$discount =
0.05;
}
}
else {
$discount = 0.025;
}
}
Taming Dangerously Deep Nesting
2. Convert a nested if to a set of if-
then-elses
This solution is easier than some
because the numbers increase neatly
(simple but clever way).
<?php
// good example
if ( 1000 < quantity ) {
discount = 0.10;
}
else if ( 100 < quantity ) {
discount = 0.05;
}
else if ( 10 < quantity ) {
discount = 0.025;
}
else {
discount = 0;
}
Taming Dangerously Deep Nesting
3. Convert a nested if to a
case statement
You can recode some kinds
of tests, particularly those
with integers, to use a case
statement rather than chains
of ifs and elses.
<?php
switch(true){
case ($quantity >=0 AND $quantity <= 10):
$discount = 0.0;
break;
case ($quantity >= 11 AND $quantity <= 100):
$discount = 0.025;
break;
case ($quantity >= 101 AND $quantity <= 1000):
$discount = 0.05;
break;
default:
$discount = 0.10
Break;
}
High
Productivity
Applications
● Why Control Structures
● Minimum Complexity =
Improve Collaboration
Why Control Structure
One reason so much attention has been paid to control structures is that they are
a big contributor to overall program complexity. Poor use of control structures
increases complexity; good use decreases it.
Intuitively, the complexity of a program would seem to largely determine the
amount of effort required to understand it.
Build High Productivity Application
Remember this?
Crystal Clear:
Easy to understand
High Quality
Code
Improve
Collaboration
Minimum
Complexity
Further Reading
Kindly visit us on developers.kudo.co.id
http://php.net/manual/en/language.control-structures.php
https://howtoprogramwithjava.com/the-5-basic-concepts-of-any-programming-
language-concept-2/
Make things as simple as possible—but no simpler.
—Albert Einstein

More Related Content

What's hot

What's hot (20)

Algorithms
AlgorithmsAlgorithms
Algorithms
 
Code smells
Code smellsCode smells
Code smells
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
Decision control
Decision controlDecision control
Decision control
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Effective PHP. Part 3
Effective PHP. Part 3Effective PHP. Part 3
Effective PHP. Part 3
 
Effective PHP. Part 6
Effective PHP. Part 6Effective PHP. Part 6
Effective PHP. Part 6
 
Package assert
Package assertPackage assert
Package assert
 
Effective PHP. Part 5
Effective PHP. Part 5Effective PHP. Part 5
Effective PHP. Part 5
 
Refactoring
RefactoringRefactoring
Refactoring
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
Chapter 3.2
Chapter 3.2Chapter 3.2
Chapter 3.2
 
Java script best practices v4
Java script best practices v4Java script best practices v4
Java script best practices v4
 
Effective PHP. Part 2
Effective PHP. Part 2Effective PHP. Part 2
Effective PHP. Part 2
 
Lesson notes text editor 04.03.13
Lesson notes text editor 04.03.13Lesson notes text editor 04.03.13
Lesson notes text editor 04.03.13
 

Similar to Building high productivity applications

In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLeSparkBiz
 
4. programing 101
4. programing 1014. programing 101
4. programing 101IEEE MIU SB
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnitymazenet
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
 
Testing survival Guide
Testing survival GuideTesting survival Guide
Testing survival GuideThilo Utke
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principlesEdorian
 
13 javascript techniques to improve your code
13 javascript techniques to improve your code13 javascript techniques to improve your code
13 javascript techniques to improve your codeSurendra kumar
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtrykapib57390
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Introduction To Programming
Introduction To ProgrammingIntroduction To Programming
Introduction To Programmingcwarren
 

Similar to Building high productivity applications (20)

In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
 
4. programing 101
4. programing 1014. programing 101
4. programing 101
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
SAD10 - Refactoring
SAD10 - RefactoringSAD10 - Refactoring
SAD10 - Refactoring
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Testing survival Guide
Testing survival GuideTesting survival Guide
Testing survival Guide
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
13 javascript techniques to improve your code
13 javascript techniques to improve your code13 javascript techniques to improve your code
13 javascript techniques to improve your code
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
03b loops
03b   loops03b   loops
03b loops
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Introduction To Programming
Introduction To ProgrammingIntroduction To Programming
Introduction To Programming
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 

Building high productivity applications

  • 1. Talk: Building High Productivity Applications September 17, 2016 Hutomo Sugianto Tech Evangelist Kudo Teknologi Indonesia e: hutomo@kudo.co.id
  • 2. Concept: Software System vs Software Software/ Application Software “System” Architecture/ Construction Interface and Integration
  • 3. Common problems in Software Development Term Background Bad Code: Hard to understand Poor Collaboration Code Complexity
  • 4. One of the solutions Crystal Clear: Easy to understand High Quality Code Improve Collaboration Minimum Complexity Building High Productivity Application
  • 5. Outline Control Structure: What Control Issues Dealing with Complexity: Why Control Structure High Productivity Applications
  • 6. Control Structure A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. ● Code Flow - top to bottom ● Hit a point where it needs to make a decision ● Strict set of rules to decide which direction to go ● So, this decision that must be made, that will in turn effect the flow of code, is known as a control structure!
  • 7. Control Structure Big contributor to overall program complexity. Conditionals/selection: ● if ● if/else ● switch Loop/repetition: ● while ● do/while
  • 8. Control Issues ● Boolean Expressions ● Taming Dangerously Deep Nesting
  • 9. Boolean Expressions ● Use True or False for Boolean Tests Use the identifiers true and false in boolean expressions rather than using values like 0 and 1. Bad Example: <?php $printerError = true; if ($printerError == 0) { initializePrinter(); } if ($printerError == 1) { notifyUserOfError(); }
  • 10. Boolean Expressions ● Compare boolean values to true and false implicitly You can write clearer tests by treating the expressions as boolean expressions <?php // this code while (!$done ) { // put code here } while ( $a > $b ) { // put code here } // is better than while ( $done = false ) { // put code here } while ( ($a > $b) = true ) { // put code here }
  • 11. Boolean Expressions ● Making complicated boolean expression simple 1. Break complicated tests into partial tests with new boolean variables <?php // this code function status($value = false){ return $value; } $status = status((3+(5^2))*0); if($status) { // put code here } // is better than if(status((3+(5^2))*0)){ // put code here }
  • 12. Boolean Expressions ● Making complicated boolean expression simple 2. Move complicated expression into boolean functions <?php // this code function userStatus($registered, $verified, $spam){ if($registered AND $verified AND !$spam){ return true; } else { return false; } } if(userStatus(true, false, true)){ // put code here } // is better than if($userRegistered AND $userVerified AND ($spam == false)) { // put code here }
  • 13. Boolean Expressions ● Guidelines for Comparisons to 0 Programming languages use 0 for several purposes. It’s a numeric value. It’s a null terminator in a string. It’s false in logical expressions. Because it’s used for so many purposes, you should write code that highlights the specific way 0 is used.
  • 14. Boolean Expressions ● Guidelines for Comparisons to 0 1. Compare logical variables implicitly 2. Compare numbers to 0 you should compare numeric expressions explicitly. <?php // 1. Compare logical variables // implicitly while ( !$done ) { // put code here } // Compare numbers to 0 while ( $balance != 0 ) { // put code here } // rather than while ( $balance ) { // put code here }
  • 15. Taming Dangerously Deep Nesting Excessive indentation, or “nesting,” has been pilloried in computing literature for 25 years and is still one of the chief culprits in confusing code. Deep nesting works against Managing Complexity. That is reason enough to avoid deep nesting. It’s not hard to avoid deep nesting. If you have deep nesting, you can redesign the tests performed in the if and else clauses or you can refactor code into simpler routines.
  • 16. Taming Dangerously Deep Nesting 1. Simplify a nested if by using a break block. This technique is uncommon enough that it should be used only when your entire team is familiar with it and when it has been adopted by the team as an accepted coding practice. <?php function validateInput($input = []) { if(empty($input[‘name’])){ return false; } if(empty($input[‘email’])){ return false; } } $input = [‘name’ => ‘CodeSaya’]; validateInput($input);
  • 17. Taming Dangerously Deep Nesting 2. Convert a nested if to a set of if- then-elses Suppose you have a bushy decision tree like this: This test is poorly organized in several ways, one of which is that the tests are redundant. <?php // bad example if ( 10 < $quantity ) { if ( 100 < $quantity ) { if ( 1000 < $quantity ) { $discount = 0.10; } else { $discount = 0.05; } } else { $discount = 0.025; } }
  • 18. Taming Dangerously Deep Nesting 2. Convert a nested if to a set of if- then-elses This solution is easier than some because the numbers increase neatly (simple but clever way). <?php // good example if ( 1000 < quantity ) { discount = 0.10; } else if ( 100 < quantity ) { discount = 0.05; } else if ( 10 < quantity ) { discount = 0.025; } else { discount = 0; }
  • 19. Taming Dangerously Deep Nesting 3. Convert a nested if to a case statement You can recode some kinds of tests, particularly those with integers, to use a case statement rather than chains of ifs and elses. <?php switch(true){ case ($quantity >=0 AND $quantity <= 10): $discount = 0.0; break; case ($quantity >= 11 AND $quantity <= 100): $discount = 0.025; break; case ($quantity >= 101 AND $quantity <= 1000): $discount = 0.05; break; default: $discount = 0.10 Break; }
  • 20. High Productivity Applications ● Why Control Structures ● Minimum Complexity = Improve Collaboration
  • 21. Why Control Structure One reason so much attention has been paid to control structures is that they are a big contributor to overall program complexity. Poor use of control structures increases complexity; good use decreases it. Intuitively, the complexity of a program would seem to largely determine the amount of effort required to understand it.
  • 22. Build High Productivity Application Remember this? Crystal Clear: Easy to understand High Quality Code Improve Collaboration Minimum Complexity
  • 23. Further Reading Kindly visit us on developers.kudo.co.id http://php.net/manual/en/language.control-structures.php https://howtoprogramwithjava.com/the-5-basic-concepts-of-any-programming- language-concept-2/
  • 24. Make things as simple as possible—but no simpler. —Albert Einstein