SlideShare a Scribd company logo
1 of 68
Study Group Sharing: 
The practice of programming 
Juggernaut Liu
Who is this sharing for? 
• Who wants to read this book 
• Who wants to be a good programmer 
• Who wants to know how to solve problems like the master 
• Who codes in C&C++
Who is the speaker? 
Programming Skills : 
•6 years experience in C# 
• Information Exchange 
• Internal API 
•3 years experience in JAVA 
• Real-time quotes server 
•2 years experience in C&C++ 
• WFBS 8.0 , WFBS 9.0 
• OSCE 10.6 SP3, OSCE 11 
Juggernaut Liu
Chapters 
• Style 
• Design 
• Interfaces 
• Debugging 
• Testing 
• Performance 
• Portability 
• Notation
STYLE
Style 
• Naming 
• Expressions and Statements 
• Define numbers 
• Comments
Style 
• Writing code that works well and is a pleasure to read 
–Programs are read not only by computers but also by programmers! 
• If you work on a program you didn’t write, preserve the style you find there. 
– The Boy Scout Rule : 
– Always leave the campground cleaner than you found it. 
• Once styling the program become automatic, your subconscious will take 
care of many of the details for you, and even the code you produce under 
pressure will be better!
Style – Naming(1) 
● A name should be informative, concise, memorable, 
and pronounceable if possible. 
● Use descriptive names for globals, short names for locals. 
○brief comment with the declaration of each global variable 
● Sample:
Style – Naming(2) 
• Use active names for functions. 
– Function names should be based on active verbs, perhaps 
followed by nouns.
Style – Naming(3) 
• Be accurate. 
– A name not only labels, it conveys information to the reader. A 
misleading name can result in mystifying bugs. 
• Bad Samples: 
– Originally, PhoneString phoneString 
– Now, PhoneNumber phoneString
Style – Expressions and Statements(1) 
• Use the natural form for expressions. 
– Write expressions as you might speak them aloud
Style – Expressions and Statements(2) 
• Parenthesize to resolve ambiguity. 
– Parentheses specify grouping and can be used to make the intent 
clear even when they are not required
Style – Expressions and Statements(3) 
• Be clear.
Style – Expressions and Statements(4) 
• Use else-ifs for multi-way decisions.
Style – Define numbers 
• Define numbers as constants, not macros 
• Effective C++ item 2: Prefer consts, enums, and inlines to 
#defines.
Style – Comments 
• Don’t belabor the obvious 
• Comment functions and global data 
• Don’t contradict the code
DESIGN
Design 
• "In the end, only familiarity with the tools and techniques 
of the field will provide the right solution for a particular 
problem, and only a certain amount of experience will 
provide consistently professional results.“ 
– Raymond Fielding. The Technique of Special Effects 
Cinematography
Design 
• A good algorithm or data structure might make it possible 
to solve a problem in seconds that could otherwise take 
years. 
• Assess potential algorithms and data structures. 
Consider how much data the program is likely to process. 
• It best to start detailed design with data structures, 
guided by knowledge of what algorithms might be used.
Design 
• Use a library or language feature if you can. 
• Write or borrow a short, simple, easy to understand 
implementation. 
• Production code takes much more effort than prototypes 
do.
INTERFACES
Interfaces - The issues to be worked out 
• Interfaces: 
– What services and access are provided? 
• Information hiding: 
– What information is visible and what is private? 
• Resource management: 
– Who is responsible for managing memory and other limited 
resources? 
• Error handling: 
– Who detects errors. who reports them, and how?
Interfaces – Principles(1) 
• Hide implementation details 
– The implementation behind the interface should be hidden from 
the rest of the program so it can be changed without affecting or 
breaking anything 
– Avoid global variables 
– Classes in C++ and Java are better mechanisms for hiding 
information
Interfaces – Principles(2) 
• Choose a small orthogonal set of primitives 
– An interface should provide as much functionality as necessary 
but no more, and the functions should not overlap excessively in 
their capabilities. 
– Narrow interfaces are to be preferred to wide ones 
– Do one thing, and do it well. 
– Don’t add to an interface just because it’s possible to do so
Interfaces – Principles(3) 
• Don't reach behind the user's back 
– A library function should not write secret files and variables or 
change global data, and it should be circumspect about modifying 
data in its caller.
Interfaces – Principles(4) 
• Do the same thing the same way everywhere. 
– Consistency and regularity are important.
Interfaces – Resource Management 
• Free a resource in the same layer that allocated it 
• C++ constructors and destructors help enforce this rule 
• The existence of automatic garbage collection does not 
mean that there are no memory-management issues in a 
design
Interfaces – Error handling 
● Detect errors at a low level, handle them at a high level 
● Use exceptions only for exceptional situations 
○ Exceptions should not be used for handling expected 
return values
DEBUG
Debug 
● Advice on Good Clues, Easy Bugs 
● Advice on No Clues, Hard Bugs 
● Non-reproducible Bugs
Debug - Advice on Good Clues, Easy Bugs 
• Look for familiar patterns 
– Ask yourself whether this is a familiar pattern 
• Examine the most recent change 
– Looking carefully at recent changes helps to localize the problem 
• Get a stack trace 
– Examine the state of a program after death. 
– Check improbable values of arguments 
• Explain your code to someone else 
– Read the code 
– Take a break
Debug - Advice on No Clues, Hard Bugs 
• Make the bug reproducible 
• Divide and conquer 
– Narrow down the possibilities 
– Proceed by binary search 
• Write self-checking code 
– Display messages 
– Logs 
– checking function 
• Keep records
Debug - Non-reproducible Bugs 
• Check whether all variables have been initialized 
• Does something depend on the external environment of 
the program?
TESTING
Testing 
● Test as You Write the Code 
● Tips for Testing
Testing - Test as You Write the Code(1) 
• Boundary condition testing 
– Off-by-one errors.
Testing - Test as You Write the Code(2) 
• Test pre- and post-conditions
Testing - Test as You Write the Code(3) 
• Program defensively
Testing - Tips for Testing 
• Write testing code temporarily 
–In Unit Test : Do not add any code in production code just for testing. 
–Remove testing code before publishing 
• Use 0xDEADBEEF rather than 0 
• Clear Input / Output 
• Vary your test cases 
• Test on multiple machines, compilers, and operating 
systems.
PERFORMANCE
Performance 
● Find the bottleneck 
● Strategies for Speed 
● Space Efficiency 
● Basic cycle for performance optimization
Performance - Strategies for Speed(1) 
• Use a better algorithm or data structure 
• Collect common subexpressions 
– Bad samples: 
?
Performance - Strategies for Speed(2) 
• Replace expensive operations by cheap ones 
• Unroll or eliminate loops
Performance - Strategies for Speed(3) 
• Cache frequently-used values 
– Re-use recently accessed 
• Precompute results 
– Trading space for time
Performance - Strategies for Speed(4) 
• Buffer input and output 
– String += VS String.Append 
• Use approximate values 
– If accuracy isn't an issue, use lower-precision data types 
• Rewrite in a lower-level language 
– Lower-level languages tend to be more efficient.
Performance - Space Efficiency 
• Save space by using the smallest possible data type 
• Don't store what you can easily recompute 
• However : 
– Major improvements are more likely to come from better data 
structures or algorithm 
– Space efficiency often comes with a cost in run-time
Basic cycle for performance optimization 
● Measure 
● Focus on the few places where a change will make the 
most difference 
● Verify the correctness of your changes 
● Measure again
PORTABILITY
Portability 
● Why do we worry about portability? 
● Language 
● Headers and Libraries 
● Program Organization 
● Data Exchange 
● Internationalization 
● Summary
Portability – Why? 
Why do we worry about portability? 
•Less maintenance and more utility 
•Environments change 
•A portable program is a better designed program
Portability – Language 
●Follow the standard and mainstream 
●Hide system dependencies behind interfaces 
○Good samples : The I/O libraries 
●Sizes of data types 
○sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long) 
○sizeof (float) <= sizeof (double) 
●Alignment of structure and class members 
○sizeof (struct X) bytes, 
○Not sizeof (char) + sizeof(int)
Portability – Headers and Libraries 
• Use standard libraries 
• Problems 
– Headers tend to be cluttered 
– Header files also can "pollute" the namespace by declaring a 
function with the same name 
• Solutions 
– Use a different header for each compiler or environment 
– Redefining the name
Portability – Program Organization 
• Union 
– Conditional compilation 
– Include a header which defines all 
• Intersection (Suggestion) 
– Use only features available everywhere 
– Avoid conditional compilation
Portability – Avoid conditional compilation(1) 
VS
Portability – Avoid conditional compilation(2) 
VS 
Log4XXX can do it too. !!!
Portability – Data Exchange 
• TEXT 
• Binary Data 
– little-endian vs big-endian 
– Sender and receiver agree on the byte order in transmission
Portability – Internationalization 
• Do not assume ASCII 
– Unicode 
– UTF-8 
– Wide Characters (C/C++) 
• Do not assume English 
– L10N 
– UI
Portability - Summary 
• Portable code is an ideal that is well worth striving for, 
since so much time is wasted making changes to move a 
program from one system to another or to keep it running 
as it evolves and the systems it runs on changes. 
• The intersection approach is better than the union one. 
– Loss of efficiency and features 
– Z>B
NOTATION
Notation 
• Perhaps of all the creations of man language is the most 
astonishing. 
– Giles Lytton Strachey, Words and Poetry
Notation 
• If you find yourself writing too much code to do a mundane 
job, or if you have trouble expressing the process 
comfortably, maybe you're using the wrong language. 
• If the right language doesn't yet exist, that might be an 
opportunity to create it yourself.
Notation - Formatting Data(1) 
• Sample : Transit different format data. 
Type 1 
Type 2
Notation - Formatting Data(2) 
• Pack one of the format data 
Each pack_type needs to implement its own logic !!
Notation - Formatting Data(3) 
• Define format string
Notation 
With the right notation, many problems become easier. 
Cool Sample : Cucumber
Reference 
• Reviews from Amazon 
– http://www.amazon.com/Practice-Programming-Addison-Wesley- 
Professional-Computing/dp/020161586X 
• All members’ power point in iShare 
• MSDN GC Class 
• My Blog 
– http://juggernaut-liu.blogspot.tw/2014/04/practice-of-programming-portability. 
html 
– http://juggernaut-liu.blogspot.tw/2014/05/practice-of-programming-notation. 
html
MSDN GC Class
Q & A

More Related Content

What's hot

Natural language processing: feature extraction
Natural language processing: feature extractionNatural language processing: feature extraction
Natural language processing: feature extractionGabriel Hamilton
 
[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysisWeverton Timoteo
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesShivam Mitra
 
Summer Training Project On Python Programming
Summer Training Project On Python ProgrammingSummer Training Project On Python Programming
Summer Training Project On Python ProgrammingKAUSHAL KUMAR JHA
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsShivam Mitra
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandonMaslowB
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caringsporst
 
Syntax directed-translation
Syntax directed-translationSyntax directed-translation
Syntax directed-translationJunaid Lodhi
 
CH # 1 preliminaries
CH # 1 preliminariesCH # 1 preliminaries
CH # 1 preliminariesMunawar Ahmed
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2deathful
 
Building NLP solutions using Python
Building NLP solutions using PythonBuilding NLP solutions using Python
Building NLP solutions using Pythonbotsplash.com
 

What's hot (16)

Natural language processing: feature extraction
Natural language processing: feature extractionNatural language processing: feature extraction
Natural language processing: feature extraction
 
[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
 
Code Inspection
Code InspectionCode Inspection
Code Inspection
 
Summer Training Project On Python Programming
Summer Training Project On Python ProgrammingSummer Training Project On Python Programming
Summer Training Project On Python Programming
 
2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon
 
5. bleu
5. bleu5. bleu
5. bleu
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to Lists
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caring
 
Syntax directed-translation
Syntax directed-translationSyntax directed-translation
Syntax directed-translation
 
CH # 1 preliminaries
CH # 1 preliminariesCH # 1 preliminaries
CH # 1 preliminaries
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
 
Building NLP solutions using Python
Building NLP solutions using PythonBuilding NLP solutions using Python
Building NLP solutions using Python
 
Prolog
PrologProlog
Prolog
 

Similar to Programming Study Group: Code Style, Design, Debugging and More

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesInductive Automation
 
2.4 Optimizing your Visual COBOL Applications
2.4   Optimizing your Visual COBOL Applications2.4   Optimizing your Visual COBOL Applications
2.4 Optimizing your Visual COBOL ApplicationsMicro Focus
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesDr. Syed Hassan Amin
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012cobyst
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Shirish Bari
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptVinayakHospet1
 
FPL - Part 1 (Sem - I 2013 )
FPL - Part 1  (Sem - I  2013 ) FPL - Part 1  (Sem - I  2013 )
FPL - Part 1 (Sem - I 2013 ) Yogesh Deshpande
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...panagenda
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 

Similar to Programming Study Group: Code Style, Design, Debugging and More (20)

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 
Clean code
Clean codeClean code
Clean code
 
2.4 Optimizing your Visual COBOL Applications
2.4   Optimizing your Visual COBOL Applications2.4   Optimizing your Visual COBOL Applications
2.4 Optimizing your Visual COBOL Applications
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Clean code, Feb 2012
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)Writing Clean Code (Recommendations by Robert Martin)
Writing Clean Code (Recommendations by Robert Martin)
 
Java basics
Java basicsJava basics
Java basics
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
FPL - Part 1 (Sem - I 2013 )
FPL - Part 1  (Sem - I  2013 ) FPL - Part 1  (Sem - I  2013 )
FPL - Part 1 (Sem - I 2013 )
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 

More from Juggernaut Liu

2020 MOPCON - How to be Agile
2020 MOPCON - How to be Agile2020 MOPCON - How to be Agile
2020 MOPCON - How to be AgileJuggernaut Liu
 
Design Sprint Case in Trend Micro
Design Sprint Case in Trend MicroDesign Sprint Case in Trend Micro
Design Sprint Case in Trend MicroJuggernaut Liu
 
趨勢科技案例分享 - 與專家一起共舞 Design Sprint
趨勢科技案例分享 - 與專家一起共舞 Design Sprint趨勢科技案例分享 - 與專家一起共舞 Design Sprint
趨勢科技案例分享 - 與專家一起共舞 Design SprintJuggernaut Liu
 
RPG Retrospective Workshop in AgileTour Hsinchu 2018
RPG Retrospective Workshop in AgileTour Hsinchu 2018RPG Retrospective Workshop in AgileTour Hsinchu 2018
RPG Retrospective Workshop in AgileTour Hsinchu 2018Juggernaut Liu
 
Scrum drawing game in agile summit 2018
Scrum drawing game in agile summit 2018Scrum drawing game in agile summit 2018
Scrum drawing game in agile summit 2018Juggernaut Liu
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018Juggernaut Liu
 
Scrum Drawing Game 2.0 for Agile Tour 2017
Scrum Drawing Game 2.0 for Agile Tour 2017Scrum Drawing Game 2.0 for Agile Tour 2017
Scrum Drawing Game 2.0 for Agile Tour 2017Juggernaut Liu
 
Scrum Drawing Game for Scrum Gathering Tokyo
Scrum Drawing Game for Scrum Gathering TokyoScrum Drawing Game for Scrum Gathering Tokyo
Scrum Drawing Game for Scrum Gathering TokyoJuggernaut Liu
 
Adapt or Die_devopsdaystaipei_2017
Adapt or Die_devopsdaystaipei_2017Adapt or Die_devopsdaystaipei_2017
Adapt or Die_devopsdaystaipei_2017Juggernaut Liu
 
在瀑布底下玩Scrum
在瀑布底下玩Scrum在瀑布底下玩Scrum
在瀑布底下玩ScrumJuggernaut Liu
 
Jug EIE Menu presentation
Jug EIE Menu presentationJug EIE Menu presentation
Jug EIE Menu presentationJuggernaut Liu
 
需求怎麼估 20150424新竹scrum社群分享
需求怎麼估 20150424新竹scrum社群分享需求怎麼估 20150424新竹scrum社群分享
需求怎麼估 20150424新竹scrum社群分享Juggernaut Liu
 
Photos in SLC by Juggernaut Liu
Photos in SLC by Juggernaut LiuPhotos in SLC by Juggernaut Liu
Photos in SLC by Juggernaut LiuJuggernaut Liu
 
The Practice of Programming - Notation
The Practice of Programming - NotationThe Practice of Programming - Notation
The Practice of Programming - NotationJuggernaut Liu
 
Unit test demo for calculatechinesenamenumber
Unit test demo for calculatechinesenamenumberUnit test demo for calculatechinesenamenumber
Unit test demo for calculatechinesenamenumberJuggernaut Liu
 

More from Juggernaut Liu (18)

2020 MOPCON - How to be Agile
2020 MOPCON - How to be Agile2020 MOPCON - How to be Agile
2020 MOPCON - How to be Agile
 
Design Sprint Case in Trend Micro
Design Sprint Case in Trend MicroDesign Sprint Case in Trend Micro
Design Sprint Case in Trend Micro
 
趨勢科技案例分享 - 與專家一起共舞 Design Sprint
趨勢科技案例分享 - 與專家一起共舞 Design Sprint趨勢科技案例分享 - 與專家一起共舞 Design Sprint
趨勢科技案例分享 - 與專家一起共舞 Design Sprint
 
RPG Retrospective Workshop in AgileTour Hsinchu 2018
RPG Retrospective Workshop in AgileTour Hsinchu 2018RPG Retrospective Workshop in AgileTour Hsinchu 2018
RPG Retrospective Workshop in AgileTour Hsinchu 2018
 
Scrum drawing game in agile summit 2018
Scrum drawing game in agile summit 2018Scrum drawing game in agile summit 2018
Scrum drawing game in agile summit 2018
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018
 
Scrum Drawing Game 2.0 for Agile Tour 2017
Scrum Drawing Game 2.0 for Agile Tour 2017Scrum Drawing Game 2.0 for Agile Tour 2017
Scrum Drawing Game 2.0 for Agile Tour 2017
 
Scrum Drawing Game for Scrum Gathering Tokyo
Scrum Drawing Game for Scrum Gathering TokyoScrum Drawing Game for Scrum Gathering Tokyo
Scrum Drawing Game for Scrum Gathering Tokyo
 
Adapt or Die_devopsdaystaipei_2017
Adapt or Die_devopsdaystaipei_2017Adapt or Die_devopsdaystaipei_2017
Adapt or Die_devopsdaystaipei_2017
 
Null object pattern
Null object patternNull object pattern
Null object pattern
 
在瀑布底下玩Scrum
在瀑布底下玩Scrum在瀑布底下玩Scrum
在瀑布底下玩Scrum
 
Jug EIE Menu presentation
Jug EIE Menu presentationJug EIE Menu presentation
Jug EIE Menu presentation
 
需求怎麼估 20150424新竹scrum社群分享
需求怎麼估 20150424新竹scrum社群分享需求怎麼估 20150424新竹scrum社群分享
需求怎麼估 20150424新竹scrum社群分享
 
Think on your feet
Think on your feetThink on your feet
Think on your feet
 
Photos in SLC by Juggernaut Liu
Photos in SLC by Juggernaut LiuPhotos in SLC by Juggernaut Liu
Photos in SLC by Juggernaut Liu
 
The Practice of Programming - Notation
The Practice of Programming - NotationThe Practice of Programming - Notation
The Practice of Programming - Notation
 
Portability
PortabilityPortability
Portability
 
Unit test demo for calculatechinesenamenumber
Unit test demo for calculatechinesenamenumberUnit test demo for calculatechinesenamenumber
Unit test demo for calculatechinesenamenumber
 

Recently uploaded

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 

Recently uploaded (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 

Programming Study Group: Code Style, Design, Debugging and More

  • 1. Study Group Sharing: The practice of programming Juggernaut Liu
  • 2. Who is this sharing for? • Who wants to read this book • Who wants to be a good programmer • Who wants to know how to solve problems like the master • Who codes in C&C++
  • 3. Who is the speaker? Programming Skills : •6 years experience in C# • Information Exchange • Internal API •3 years experience in JAVA • Real-time quotes server •2 years experience in C&C++ • WFBS 8.0 , WFBS 9.0 • OSCE 10.6 SP3, OSCE 11 Juggernaut Liu
  • 4. Chapters • Style • Design • Interfaces • Debugging • Testing • Performance • Portability • Notation
  • 6. Style • Naming • Expressions and Statements • Define numbers • Comments
  • 7. Style • Writing code that works well and is a pleasure to read –Programs are read not only by computers but also by programmers! • If you work on a program you didn’t write, preserve the style you find there. – The Boy Scout Rule : – Always leave the campground cleaner than you found it. • Once styling the program become automatic, your subconscious will take care of many of the details for you, and even the code you produce under pressure will be better!
  • 8. Style – Naming(1) ● A name should be informative, concise, memorable, and pronounceable if possible. ● Use descriptive names for globals, short names for locals. ○brief comment with the declaration of each global variable ● Sample:
  • 9. Style – Naming(2) • Use active names for functions. – Function names should be based on active verbs, perhaps followed by nouns.
  • 10. Style – Naming(3) • Be accurate. – A name not only labels, it conveys information to the reader. A misleading name can result in mystifying bugs. • Bad Samples: – Originally, PhoneString phoneString – Now, PhoneNumber phoneString
  • 11. Style – Expressions and Statements(1) • Use the natural form for expressions. – Write expressions as you might speak them aloud
  • 12. Style – Expressions and Statements(2) • Parenthesize to resolve ambiguity. – Parentheses specify grouping and can be used to make the intent clear even when they are not required
  • 13. Style – Expressions and Statements(3) • Be clear.
  • 14. Style – Expressions and Statements(4) • Use else-ifs for multi-way decisions.
  • 15. Style – Define numbers • Define numbers as constants, not macros • Effective C++ item 2: Prefer consts, enums, and inlines to #defines.
  • 16. Style – Comments • Don’t belabor the obvious • Comment functions and global data • Don’t contradict the code
  • 18. Design • "In the end, only familiarity with the tools and techniques of the field will provide the right solution for a particular problem, and only a certain amount of experience will provide consistently professional results.“ – Raymond Fielding. The Technique of Special Effects Cinematography
  • 19. Design • A good algorithm or data structure might make it possible to solve a problem in seconds that could otherwise take years. • Assess potential algorithms and data structures. Consider how much data the program is likely to process. • It best to start detailed design with data structures, guided by knowledge of what algorithms might be used.
  • 20. Design • Use a library or language feature if you can. • Write or borrow a short, simple, easy to understand implementation. • Production code takes much more effort than prototypes do.
  • 22. Interfaces - The issues to be worked out • Interfaces: – What services and access are provided? • Information hiding: – What information is visible and what is private? • Resource management: – Who is responsible for managing memory and other limited resources? • Error handling: – Who detects errors. who reports them, and how?
  • 23. Interfaces – Principles(1) • Hide implementation details – The implementation behind the interface should be hidden from the rest of the program so it can be changed without affecting or breaking anything – Avoid global variables – Classes in C++ and Java are better mechanisms for hiding information
  • 24. Interfaces – Principles(2) • Choose a small orthogonal set of primitives – An interface should provide as much functionality as necessary but no more, and the functions should not overlap excessively in their capabilities. – Narrow interfaces are to be preferred to wide ones – Do one thing, and do it well. – Don’t add to an interface just because it’s possible to do so
  • 25. Interfaces – Principles(3) • Don't reach behind the user's back – A library function should not write secret files and variables or change global data, and it should be circumspect about modifying data in its caller.
  • 26. Interfaces – Principles(4) • Do the same thing the same way everywhere. – Consistency and regularity are important.
  • 27. Interfaces – Resource Management • Free a resource in the same layer that allocated it • C++ constructors and destructors help enforce this rule • The existence of automatic garbage collection does not mean that there are no memory-management issues in a design
  • 28. Interfaces – Error handling ● Detect errors at a low level, handle them at a high level ● Use exceptions only for exceptional situations ○ Exceptions should not be used for handling expected return values
  • 29. DEBUG
  • 30. Debug ● Advice on Good Clues, Easy Bugs ● Advice on No Clues, Hard Bugs ● Non-reproducible Bugs
  • 31. Debug - Advice on Good Clues, Easy Bugs • Look for familiar patterns – Ask yourself whether this is a familiar pattern • Examine the most recent change – Looking carefully at recent changes helps to localize the problem • Get a stack trace – Examine the state of a program after death. – Check improbable values of arguments • Explain your code to someone else – Read the code – Take a break
  • 32. Debug - Advice on No Clues, Hard Bugs • Make the bug reproducible • Divide and conquer – Narrow down the possibilities – Proceed by binary search • Write self-checking code – Display messages – Logs – checking function • Keep records
  • 33. Debug - Non-reproducible Bugs • Check whether all variables have been initialized • Does something depend on the external environment of the program?
  • 35. Testing ● Test as You Write the Code ● Tips for Testing
  • 36. Testing - Test as You Write the Code(1) • Boundary condition testing – Off-by-one errors.
  • 37. Testing - Test as You Write the Code(2) • Test pre- and post-conditions
  • 38. Testing - Test as You Write the Code(3) • Program defensively
  • 39. Testing - Tips for Testing • Write testing code temporarily –In Unit Test : Do not add any code in production code just for testing. –Remove testing code before publishing • Use 0xDEADBEEF rather than 0 • Clear Input / Output • Vary your test cases • Test on multiple machines, compilers, and operating systems.
  • 41. Performance ● Find the bottleneck ● Strategies for Speed ● Space Efficiency ● Basic cycle for performance optimization
  • 42. Performance - Strategies for Speed(1) • Use a better algorithm or data structure • Collect common subexpressions – Bad samples: ?
  • 43. Performance - Strategies for Speed(2) • Replace expensive operations by cheap ones • Unroll or eliminate loops
  • 44. Performance - Strategies for Speed(3) • Cache frequently-used values – Re-use recently accessed • Precompute results – Trading space for time
  • 45. Performance - Strategies for Speed(4) • Buffer input and output – String += VS String.Append • Use approximate values – If accuracy isn't an issue, use lower-precision data types • Rewrite in a lower-level language – Lower-level languages tend to be more efficient.
  • 46. Performance - Space Efficiency • Save space by using the smallest possible data type • Don't store what you can easily recompute • However : – Major improvements are more likely to come from better data structures or algorithm – Space efficiency often comes with a cost in run-time
  • 47. Basic cycle for performance optimization ● Measure ● Focus on the few places where a change will make the most difference ● Verify the correctness of your changes ● Measure again
  • 49. Portability ● Why do we worry about portability? ● Language ● Headers and Libraries ● Program Organization ● Data Exchange ● Internationalization ● Summary
  • 50. Portability – Why? Why do we worry about portability? •Less maintenance and more utility •Environments change •A portable program is a better designed program
  • 51. Portability – Language ●Follow the standard and mainstream ●Hide system dependencies behind interfaces ○Good samples : The I/O libraries ●Sizes of data types ○sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long) ○sizeof (float) <= sizeof (double) ●Alignment of structure and class members ○sizeof (struct X) bytes, ○Not sizeof (char) + sizeof(int)
  • 52. Portability – Headers and Libraries • Use standard libraries • Problems – Headers tend to be cluttered – Header files also can "pollute" the namespace by declaring a function with the same name • Solutions – Use a different header for each compiler or environment – Redefining the name
  • 53. Portability – Program Organization • Union – Conditional compilation – Include a header which defines all • Intersection (Suggestion) – Use only features available everywhere – Avoid conditional compilation
  • 54. Portability – Avoid conditional compilation(1) VS
  • 55. Portability – Avoid conditional compilation(2) VS Log4XXX can do it too. !!!
  • 56. Portability – Data Exchange • TEXT • Binary Data – little-endian vs big-endian – Sender and receiver agree on the byte order in transmission
  • 57. Portability – Internationalization • Do not assume ASCII – Unicode – UTF-8 – Wide Characters (C/C++) • Do not assume English – L10N – UI
  • 58. Portability - Summary • Portable code is an ideal that is well worth striving for, since so much time is wasted making changes to move a program from one system to another or to keep it running as it evolves and the systems it runs on changes. • The intersection approach is better than the union one. – Loss of efficiency and features – Z>B
  • 60. Notation • Perhaps of all the creations of man language is the most astonishing. – Giles Lytton Strachey, Words and Poetry
  • 61. Notation • If you find yourself writing too much code to do a mundane job, or if you have trouble expressing the process comfortably, maybe you're using the wrong language. • If the right language doesn't yet exist, that might be an opportunity to create it yourself.
  • 62. Notation - Formatting Data(1) • Sample : Transit different format data. Type 1 Type 2
  • 63. Notation - Formatting Data(2) • Pack one of the format data Each pack_type needs to implement its own logic !!
  • 64. Notation - Formatting Data(3) • Define format string
  • 65. Notation With the right notation, many problems become easier. Cool Sample : Cucumber
  • 66. Reference • Reviews from Amazon – http://www.amazon.com/Practice-Programming-Addison-Wesley- Professional-Computing/dp/020161586X • All members’ power point in iShare • MSDN GC Class • My Blog – http://juggernaut-liu.blogspot.tw/2014/04/practice-of-programming-portability. html – http://juggernaut-liu.blogspot.tw/2014/05/practice-of-programming-notation. html
  • 68. Q & A