SlideShare uma empresa Scribd logo
1 de 23
Writing Computer-ese
Steve Frezza, Ph. D., C.S.D.P.

1
Your Speaker
 Professor

of Software Engineering.

 PhD

in EE (1995); Taught CE, CS and SE courses
 Certified Software Development Professional (2001)
 Teaching:
 Requirements,

project management, testing, design, programming,
quality assurance
 Computer architecture, Digital logic, Embedded Systems
 Leadership, Freshman Seminar, Professional Seminar, Civil War
 Currently:
 Deacon

MA in Pastoral Studies

Formation program in the Diocese of Erie

2
‘Creative’ Writing for
Software Engineers
 Self-Documenting

Code

 Maintainability

and readability
 More than coding standards
 Visual

Languages

 Organizing

writing

 Specification
 Standing

and Socio-Technical Systems

Committee Processes

Writing that creates something
3
Coding as written expression
Specialized,

goal-oriented writing

Goal:

make a computer system do
something of use

Means:

Coding

Formalized

grammar
Sequential Execution
Integrated Development Environment
(IDE)
Extensive Libraries
4
The Code-Writing Problem
 Imagine

writing a book for something

 With

multiple people writing
 People joining/leaving the team
 New pieces to be added to the manual
 Old pieces sometimes removed
 Multiple versions of the book being
published
 Needed:

Ability to:

 Modify

the book organization quickly
 Quickly teach new writers how and where
to integrate their stories
5
Elegant Code
(from Stackoverflow.com blog)
Elegant code is a combination of:
Correctness. IMHO no wrong code can truly be elegant.
Correctness
Succinctness. Less code means less to go wrong, less to
Succinctness
understand. Briefly and clearly expressed.
Readability. The easier it is to understand code, the easier to
Readability
maintain.
Performance. To a point. Prematurely optimized code cannot
Performance
truly be elegant.

6
Elegant Code cont.
(from Stackoverflow.com blog)
Elegant code is a combination of:
Standardized. Following the established standards of the
Standardized
platform or project. When given two equally elegant options,
the one that is closest to the established standard is the best.
Exactly the way I would do it.  It's easy to label code that is
it
NOT how you would do it as "inelegant". Please don't do that keep an open mind to different code.
"To every problem there is a solution that is simple,
elegant, and wrong"
7
Sample Problem
Write some code to
Do something of use…
Enter the the amountconvert ($XX.XX): 11.55 USD
Enter amount to to convert ($XX.XX): 11.55 USD
The a currency-conversion program that takes a
Developamount requested: $11.55 USD is also 11.55 USD.number
The amount requested: places), and a three-letter currency
(rounded to two decimal $11.55 USD is also 7.51 GBP.
The amount requested: $11.55 USD is
(e.g., “USD”) and converts to availablealso 10.97 CHF.
currencies. Manage
The amount requested: $11.55 USD is also 11.55 BSD.
conversions forrequested: $11.55 USDGBP, AUD, AUD. and
at least EUR, USD, is also 12.01 CAD
The amount
CHF. amount requested: $11.55 USD is also 11.90 CAD.
The
The amount requested: $11.55 USD is also 8.89 EUR.
8
Java Sample
Takes an <amount> and print six conversions…
public static void changeCurrency(float amount) {
System.out.println("The amount requested: ” +amount+
+(amount * 1)+ " BSD.");
System.out.println("The amount requested: ” +amount+
+(amount * 1.03)+ " CAD.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.95)+ " CHF.");
System.out.println("The amount requested: ” +amount+
+(amount * 1.04)+ " AUD.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.65)+ " GBP.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.77)+ " EUR.");

}
9

" is ”
" is ”
" is ”
" is ”
" is ”
" is ”
Java Sample – What’s Wrong

Repetitive: verbose;
hard to fix

Takes an <amount> and print six conversions…

public static void changeCurrency(float amount) {
System.out.println("The amount requested: ” +amount+
+(amount * 1)+ " BSD.");
System.out.println("The amount requested: ” +amount+
+(amount * 1.03)+ " CAD.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.95)+ " CHF.");
System.out.println("The amount requested: ” +amount+
+(amount * 1.04)+ " AUD.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.65)+ " GBP.");
System.out.println("The amount requested: ” +amount+
+(amount * 0.77)+ " EUR.");

}

Standards: embedded literals
10

" is ”
" is ”
" is ”
" is ”
" is ”
" is ”
Objects: Containers for behavior
Like subsections

in a manual:

 Manual:

one (sub)section defines/illustrates one ‘thing’ well.
 E.g., in a policy manual, all the rules pertaining to xyz policy should
be in that subsection, not scattered elsewhere in the document.
 Only one place to change that policy
Unlike subsections
 Defined

in a manual

by classes, which are patterns for

objects;
 Defines both changeable information (data) and
behavior (operations) that modify or use that
data.
11
Repetitive: verbose;
hard to fix
Readability: What’s this?

Better Version

public static void changeCurrency(float amount) {
System.out.println(BSD.conversionTranscript(amount));
System.out.println(CAD.conversionTranscript(amount));
System.out.println(CHF.conversionTranscript(amount));
System.out.println(AUD.conversionTranscript(amount));
System.out.println(GBP.conversionTranscript(amount));
System.out.println(EUR.conversionTranscript(amount));
}

Readability: What are these?
//Create a converter object for each of the currencies:
private static Converter EUR = new Converter("EUR",0.77);
private static Converter CAD = new Converter("CAD", 1.03);
private static Converter AUD = new Converter("AUD", 1.04);
private static Converter BSD = new Converter("BSD", 1.0);
private static Converter CHF = new Converter("CHF", 0.95);
private static Converter GBP = new Converter("GBP", 0.65);
12
Confounding Comments
 Commenting

Code – Why, why not?

 Why:

Easier to read, preserve ‘clear text’ message
 Why not: Often wrong or misleading, costly to maintain
 Process
 Use

to guide construction

 Product
 Use

Artifact:

Artifact:

to illustrate the code as written

13
Commented Code
public static void changeCurrency(float currencies;
// Print out the amount in the differentamount) {
System.out.println(BSD.conversionTranscript(amount));
public static void changeCurrency(float amount) {
System.out.println(BSD.conversionTranscript(amount));
System.out.println(CAD.conversionTranscript(amount));
// Code goes here
System.out.println(CHF.conversionTranscript(amount));
System.out.println(CAD.conversionTranscript(amount));
}
System.out.println(AUD.conversionTranscript(amount));
System.out.println(CHF.conversionTranscript(amount));
System.out.println(GBP.conversionTranscript(amount));
System.out.println(AUD.conversionTranscript(amount));
System.out.println(EUR.conversionTranscript(amount));
System.out.println(GBP.conversionTranscript(amount));
}
System.out.println(EUR.conversionTranscript(amount));
}

14
Control Structures
 Functional
 Define

Encapsulation

your own terms…

public String conversionTranscript( double valueInUSD) {
String amountString =
String.format("The amount requested: $%.2f USD is also %.2f ",
valueInUSD, convertFromUSD(valueInUSD));
return amountString + currencyCode + ".";
}
 Correct:

Does one thing well
 Succinct: Short, focused, no extraneous code
 Readable: Named for Use
 Performance: Optimized for reuse
 Standard: Follows conventions
15
Control Structures
 Conditional
 Used

Behavior

to avoid repeating code, ensure correct logic

public static void changeCurrency(float amount,
public static void changeCurrency(float amount) {
Denomination[] denom) {
System.out.println(BSD.conversionTranscript(amount));
for (int index = 0; index < denom.length; index++) {
System.out.println(CAD.conversionTranscript(amount));
System.out.println(denom[index].conversionTranscript(amount));
System.out.println(CHF.conversionTranscript(amount));
}
System.out.println(AUD.conversionTranscript(amount));
}
System.out.println(GBP.conversionTranscript(amount));
System.out.println(EUR.conversionTranscript(amount));
}

16
Self-Documenting Code
 Name
 So

they make sense for their general use

 Name
 So

classes, structures & functions
objects and variables

they make sense for their specific use

 Heuristic:
 Can

it be misunderstood?
 Better name?
 Shorter is better
 Succinct, but no more succinct than necessary

17
Self-Documenting Code (1)
public static void changeCurrency(float amount,
Denomination[] denom) {
for (int i= 0; i< denom.length; i++) {
System.out.println(denom[i].conversionTranscript(amount));
}
}

Variable <i> - Descriptive? Specific? Concise?
NO

NO

18

YES
Self-Documenting Code (2)
public static void changeCurrency(float amount,
Denomination[] denom) {
for (int index = 0; index < denom.length; index++) {
System.out.println(denom[index].conversionTranscript(amount));
}
}

Variable <index> - Descriptive? Specific? Concise?
A little
NO
Sort-of

19
Self-Documenting Code (3)
public static void changeCurrency(float amount,
Denomination[] denom) {
for (int denomIndex = 0; denomIndex < denom.length; denomIndex++)
{
System.out.println(denom[denomIndex].conversionTranscript(amount))
;
}
Variable <index> - Descriptive? Specific? Concise?
}

Yes

Yes

20

NO
Self-Documenting Code (4)
public enum CurrencyType {
USD(0), EUR(1), CAD(2), AUD(3), BSD(4), CHF(5), GBP(6);
private int typeIndex;
CurrencyType (int index) { typeIndex = index; }
public int index() { return typeIndex; }
}

public static void changeCurrency(float amount,
Denomination[] denom) {
for (CurrencyType currency : CurrencyType.values()) {
System.out.println(denom[currency.index()].conversionTranscript(am
ount));
}
}

Variable <currency> - Descriptive? Specific? Concise?
Yes
Yes
Yes
21
Elegant Code
public static void changeCurrency(float amount,
public static void changeCurrency(float amount,
Denomination[] denom) {
Denomination[] denom) {
for (CurrencyType denom.length; i++) {
for (int i= 0; i< currency : CurrencyType.values()) {
System.out.println(denom[currency.index()].conversionTranscript(am
System.out.println(denom[i].conversionTranscript(amount));
ount));
}
}
}
}

 More

code… 
 Succinct… Less to remember… 
 Specific to problem… 
 Changes managed in one place…
 Reuseable pattern…
22
Writing Code: Summary
Like writing a policy manual; e.g., need to…
 Know

your purpose & audience (e.g. what you want it to do) first
 Understand how to express the intent (e.g., programing language)
 Write to achieve quality: correctness, readability, succinctness
 Break into small pieces
 Make easy to edit
Unlike writing a policy manual;
 Writing

to do, not just be
 Re-useable patterns for information &
behavior (classes)
 Re-useable operations (functions)
23

Mais conteúdo relacionado

Semelhante a Programming as a writing genre

Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0Nate Abele
 
01 Database Management (re-uploaded)
01 Database Management (re-uploaded)01 Database Management (re-uploaded)
01 Database Management (re-uploaded)bluejayjunior
 
Ppt on visual basics
Ppt on visual basicsPpt on visual basics
Ppt on visual basicsyounganand
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptxMattMarino13
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Thinkful
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdfhamzadamani7
 
Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Scott Wlaschin
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NETDoommaker
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsSalesforce Developers
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans Fabrizio Giudici
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Thinkful
 

Semelhante a Programming as a writing genre (20)

Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
 
01 Database Management (re-uploaded)
01 Database Management (re-uploaded)01 Database Management (re-uploaded)
01 Database Management (re-uploaded)
 
Ppt on visual basics
Ppt on visual basicsPpt on visual basics
Ppt on visual basics
 
Ad505 dev blast
Ad505 dev blastAd505 dev blast
Ad505 dev blast
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Javascript
JavascriptJavascript
Javascript
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf
 
Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
DSL in scala
DSL in scalaDSL in scala
DSL in scala
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong Foundations
 
Refactoring
RefactoringRefactoring
Refactoring
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Web programming
Web programmingWeb programming
Web programming
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 

Mais de Stephen Frezza

Professionalism & Quality: What accreditation offers engineering
Professionalism & Quality: What accreditation offers engineeringProfessionalism & Quality: What accreditation offers engineering
Professionalism & Quality: What accreditation offers engineeringStephen Frezza
 
Catholic life issues 1-27-14
Catholic life issues 1-27-14Catholic life issues 1-27-14
Catholic life issues 1-27-14Stephen Frezza
 
Knowledge basis for design 2014
Knowledge basis for design 2014Knowledge basis for design 2014
Knowledge basis for design 2014Stephen Frezza
 
Using interactive models to enhance UML education
Using interactive models to enhance UML educationUsing interactive models to enhance UML education
Using interactive models to enhance UML educationStephen Frezza
 
Collection, Maintenance and Validation of Effective Evidence for Program Asse...
Collection, Maintenance and Validation of Effective Evidence for Program Asse...Collection, Maintenance and Validation of Effective Evidence for Program Asse...
Collection, Maintenance and Validation of Effective Evidence for Program Asse...Stephen Frezza
 
Distinguishing Analysis from Design
Distinguishing Analysis from DesignDistinguishing Analysis from Design
Distinguishing Analysis from DesignStephen Frezza
 
Epistemology and the Foundations of Engineering
Epistemology and the Foundations of EngineeringEpistemology and the Foundations of Engineering
Epistemology and the Foundations of EngineeringStephen Frezza
 
Real-World Problem Solving
Real-World Problem SolvingReal-World Problem Solving
Real-World Problem SolvingStephen Frezza
 
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...Deus machinator - The intersection of Catholic/Christian Theology and Enginee...
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...Stephen Frezza
 
Germans in the American Civil War
Germans in the American Civil WarGermans in the American Civil War
Germans in the American Civil WarStephen Frezza
 

Mais de Stephen Frezza (11)

Professionalism & Quality: What accreditation offers engineering
Professionalism & Quality: What accreditation offers engineeringProfessionalism & Quality: What accreditation offers engineering
Professionalism & Quality: What accreditation offers engineering
 
Catholic life issues 1-27-14
Catholic life issues 1-27-14Catholic life issues 1-27-14
Catholic life issues 1-27-14
 
Knowledge basis for design 2014
Knowledge basis for design 2014Knowledge basis for design 2014
Knowledge basis for design 2014
 
Using interactive models to enhance UML education
Using interactive models to enhance UML educationUsing interactive models to enhance UML education
Using interactive models to enhance UML education
 
Collection, Maintenance and Validation of Effective Evidence for Program Asse...
Collection, Maintenance and Validation of Effective Evidence for Program Asse...Collection, Maintenance and Validation of Effective Evidence for Program Asse...
Collection, Maintenance and Validation of Effective Evidence for Program Asse...
 
Distinguishing Analysis from Design
Distinguishing Analysis from DesignDistinguishing Analysis from Design
Distinguishing Analysis from Design
 
Epistemology and the Foundations of Engineering
Epistemology and the Foundations of EngineeringEpistemology and the Foundations of Engineering
Epistemology and the Foundations of Engineering
 
Real-World Problem Solving
Real-World Problem SolvingReal-World Problem Solving
Real-World Problem Solving
 
Germans at Gettysburg
Germans at GettysburgGermans at Gettysburg
Germans at Gettysburg
 
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...Deus machinator - The intersection of Catholic/Christian Theology and Enginee...
Deus machinator - The intersection of Catholic/Christian Theology and Enginee...
 
Germans in the American Civil War
Germans in the American Civil WarGermans in the American Civil War
Germans in the American Civil War
 

Último

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Último (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

Programming as a writing genre

  • 2. Your Speaker  Professor of Software Engineering.  PhD in EE (1995); Taught CE, CS and SE courses  Certified Software Development Professional (2001)  Teaching:  Requirements, project management, testing, design, programming, quality assurance  Computer architecture, Digital logic, Embedded Systems  Leadership, Freshman Seminar, Professional Seminar, Civil War  Currently:  Deacon MA in Pastoral Studies Formation program in the Diocese of Erie 2
  • 3. ‘Creative’ Writing for Software Engineers  Self-Documenting Code  Maintainability and readability  More than coding standards  Visual Languages  Organizing writing  Specification  Standing and Socio-Technical Systems Committee Processes Writing that creates something 3
  • 4. Coding as written expression Specialized, goal-oriented writing Goal: make a computer system do something of use Means: Coding Formalized grammar Sequential Execution Integrated Development Environment (IDE) Extensive Libraries 4
  • 5. The Code-Writing Problem  Imagine writing a book for something  With multiple people writing  People joining/leaving the team  New pieces to be added to the manual  Old pieces sometimes removed  Multiple versions of the book being published  Needed: Ability to:  Modify the book organization quickly  Quickly teach new writers how and where to integrate their stories 5
  • 6. Elegant Code (from Stackoverflow.com blog) Elegant code is a combination of: Correctness. IMHO no wrong code can truly be elegant. Correctness Succinctness. Less code means less to go wrong, less to Succinctness understand. Briefly and clearly expressed. Readability. The easier it is to understand code, the easier to Readability maintain. Performance. To a point. Prematurely optimized code cannot Performance truly be elegant. 6
  • 7. Elegant Code cont. (from Stackoverflow.com blog) Elegant code is a combination of: Standardized. Following the established standards of the Standardized platform or project. When given two equally elegant options, the one that is closest to the established standard is the best. Exactly the way I would do it.  It's easy to label code that is it NOT how you would do it as "inelegant". Please don't do that keep an open mind to different code. "To every problem there is a solution that is simple, elegant, and wrong" 7
  • 8. Sample Problem Write some code to Do something of use… Enter the the amountconvert ($XX.XX): 11.55 USD Enter amount to to convert ($XX.XX): 11.55 USD The a currency-conversion program that takes a Developamount requested: $11.55 USD is also 11.55 USD.number The amount requested: places), and a three-letter currency (rounded to two decimal $11.55 USD is also 7.51 GBP. The amount requested: $11.55 USD is (e.g., “USD”) and converts to availablealso 10.97 CHF. currencies. Manage The amount requested: $11.55 USD is also 11.55 BSD. conversions forrequested: $11.55 USDGBP, AUD, AUD. and at least EUR, USD, is also 12.01 CAD The amount CHF. amount requested: $11.55 USD is also 11.90 CAD. The The amount requested: $11.55 USD is also 8.89 EUR. 8
  • 9. Java Sample Takes an <amount> and print six conversions… public static void changeCurrency(float amount) { System.out.println("The amount requested: ” +amount+ +(amount * 1)+ " BSD."); System.out.println("The amount requested: ” +amount+ +(amount * 1.03)+ " CAD."); System.out.println("The amount requested: ” +amount+ +(amount * 0.95)+ " CHF."); System.out.println("The amount requested: ” +amount+ +(amount * 1.04)+ " AUD."); System.out.println("The amount requested: ” +amount+ +(amount * 0.65)+ " GBP."); System.out.println("The amount requested: ” +amount+ +(amount * 0.77)+ " EUR."); } 9 " is ” " is ” " is ” " is ” " is ” " is ”
  • 10. Java Sample – What’s Wrong Repetitive: verbose; hard to fix Takes an <amount> and print six conversions… public static void changeCurrency(float amount) { System.out.println("The amount requested: ” +amount+ +(amount * 1)+ " BSD."); System.out.println("The amount requested: ” +amount+ +(amount * 1.03)+ " CAD."); System.out.println("The amount requested: ” +amount+ +(amount * 0.95)+ " CHF."); System.out.println("The amount requested: ” +amount+ +(amount * 1.04)+ " AUD."); System.out.println("The amount requested: ” +amount+ +(amount * 0.65)+ " GBP."); System.out.println("The amount requested: ” +amount+ +(amount * 0.77)+ " EUR."); } Standards: embedded literals 10 " is ” " is ” " is ” " is ” " is ” " is ”
  • 11. Objects: Containers for behavior Like subsections in a manual:  Manual: one (sub)section defines/illustrates one ‘thing’ well.  E.g., in a policy manual, all the rules pertaining to xyz policy should be in that subsection, not scattered elsewhere in the document.  Only one place to change that policy Unlike subsections  Defined in a manual by classes, which are patterns for objects;  Defines both changeable information (data) and behavior (operations) that modify or use that data. 11
  • 12. Repetitive: verbose; hard to fix Readability: What’s this? Better Version public static void changeCurrency(float amount) { System.out.println(BSD.conversionTranscript(amount)); System.out.println(CAD.conversionTranscript(amount)); System.out.println(CHF.conversionTranscript(amount)); System.out.println(AUD.conversionTranscript(amount)); System.out.println(GBP.conversionTranscript(amount)); System.out.println(EUR.conversionTranscript(amount)); } Readability: What are these? //Create a converter object for each of the currencies: private static Converter EUR = new Converter("EUR",0.77); private static Converter CAD = new Converter("CAD", 1.03); private static Converter AUD = new Converter("AUD", 1.04); private static Converter BSD = new Converter("BSD", 1.0); private static Converter CHF = new Converter("CHF", 0.95); private static Converter GBP = new Converter("GBP", 0.65); 12
  • 13. Confounding Comments  Commenting Code – Why, why not?  Why: Easier to read, preserve ‘clear text’ message  Why not: Often wrong or misleading, costly to maintain  Process  Use to guide construction  Product  Use Artifact: Artifact: to illustrate the code as written 13
  • 14. Commented Code public static void changeCurrency(float currencies; // Print out the amount in the differentamount) { System.out.println(BSD.conversionTranscript(amount)); public static void changeCurrency(float amount) { System.out.println(BSD.conversionTranscript(amount)); System.out.println(CAD.conversionTranscript(amount)); // Code goes here System.out.println(CHF.conversionTranscript(amount)); System.out.println(CAD.conversionTranscript(amount)); } System.out.println(AUD.conversionTranscript(amount)); System.out.println(CHF.conversionTranscript(amount)); System.out.println(GBP.conversionTranscript(amount)); System.out.println(AUD.conversionTranscript(amount)); System.out.println(EUR.conversionTranscript(amount)); System.out.println(GBP.conversionTranscript(amount)); } System.out.println(EUR.conversionTranscript(amount)); } 14
  • 15. Control Structures  Functional  Define Encapsulation your own terms… public String conversionTranscript( double valueInUSD) { String amountString = String.format("The amount requested: $%.2f USD is also %.2f ", valueInUSD, convertFromUSD(valueInUSD)); return amountString + currencyCode + "."; }  Correct: Does one thing well  Succinct: Short, focused, no extraneous code  Readable: Named for Use  Performance: Optimized for reuse  Standard: Follows conventions 15
  • 16. Control Structures  Conditional  Used Behavior to avoid repeating code, ensure correct logic public static void changeCurrency(float amount, public static void changeCurrency(float amount) { Denomination[] denom) { System.out.println(BSD.conversionTranscript(amount)); for (int index = 0; index < denom.length; index++) { System.out.println(CAD.conversionTranscript(amount)); System.out.println(denom[index].conversionTranscript(amount)); System.out.println(CHF.conversionTranscript(amount)); } System.out.println(AUD.conversionTranscript(amount)); } System.out.println(GBP.conversionTranscript(amount)); System.out.println(EUR.conversionTranscript(amount)); } 16
  • 17. Self-Documenting Code  Name  So they make sense for their general use  Name  So classes, structures & functions objects and variables they make sense for their specific use  Heuristic:  Can it be misunderstood?  Better name?  Shorter is better  Succinct, but no more succinct than necessary 17
  • 18. Self-Documenting Code (1) public static void changeCurrency(float amount, Denomination[] denom) { for (int i= 0; i< denom.length; i++) { System.out.println(denom[i].conversionTranscript(amount)); } } Variable <i> - Descriptive? Specific? Concise? NO NO 18 YES
  • 19. Self-Documenting Code (2) public static void changeCurrency(float amount, Denomination[] denom) { for (int index = 0; index < denom.length; index++) { System.out.println(denom[index].conversionTranscript(amount)); } } Variable <index> - Descriptive? Specific? Concise? A little NO Sort-of 19
  • 20. Self-Documenting Code (3) public static void changeCurrency(float amount, Denomination[] denom) { for (int denomIndex = 0; denomIndex < denom.length; denomIndex++) { System.out.println(denom[denomIndex].conversionTranscript(amount)) ; } Variable <index> - Descriptive? Specific? Concise? } Yes Yes 20 NO
  • 21. Self-Documenting Code (4) public enum CurrencyType { USD(0), EUR(1), CAD(2), AUD(3), BSD(4), CHF(5), GBP(6); private int typeIndex; CurrencyType (int index) { typeIndex = index; } public int index() { return typeIndex; } } public static void changeCurrency(float amount, Denomination[] denom) { for (CurrencyType currency : CurrencyType.values()) { System.out.println(denom[currency.index()].conversionTranscript(am ount)); } } Variable <currency> - Descriptive? Specific? Concise? Yes Yes Yes 21
  • 22. Elegant Code public static void changeCurrency(float amount, public static void changeCurrency(float amount, Denomination[] denom) { Denomination[] denom) { for (CurrencyType denom.length; i++) { for (int i= 0; i< currency : CurrencyType.values()) { System.out.println(denom[currency.index()].conversionTranscript(am System.out.println(denom[i].conversionTranscript(amount)); ount)); } } } }  More code…   Succinct… Less to remember…   Specific to problem…   Changes managed in one place…  Reuseable pattern… 22
  • 23. Writing Code: Summary Like writing a policy manual; e.g., need to…  Know your purpose & audience (e.g. what you want it to do) first  Understand how to express the intent (e.g., programing language)  Write to achieve quality: correctness, readability, succinctness  Break into small pieces  Make easy to edit Unlike writing a policy manual;  Writing to do, not just be  Re-useable patterns for information & behavior (classes)  Re-useable operations (functions) 23