coding for "real life" safe coding considering software industry expectations in...

85
CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Upload: branden-antony-parker

Post on 21-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

CODING FOR "REAL LIFE"Safe coding considering software industry expectations in programming

Page 2: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Boráros-Bakucz András• Óbuda University, Budapest, Hungary,

Kálmán Kandó Faculty of Electrical Engineering• Ericsson Hungary Research and Development

Software development, Release Program management

> whoami

Page 3: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Basic programing courses usually focus on basic level knowledge without deep understanding of C and C++ compilers

• But some good practices can be learnt early and used forever… resulting less execution or maintenance cost in business processes as well

• Problem of large scale, industrial software development• Quality vs. team development

Introduction

Page 4: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Central User Database failed in Great Britain• 2 month before Olympics in London• Approx. 18 million people could not use his mobile for more than 20

hours• Headline in newspapers

What Bad Coding may Cause

Page 5: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Nobody wants…

Fame

Page 6: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Reasons• Quite new product• Distributed database system: multiplicated data could never be totally the

same (it must be consistent)• Tested under overload situations only in lab environment• Quality issues, for example no stable enough build system

• What happened• Support/maintenance activity was done during peak hours• System went inconsistent• No one really knew how to get it up again• Support persons downed radio access network links to build location

database from scratch

What Bad Coding may Cause

Page 7: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

CODING PRACTICES

Page 8: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

› Limit internal operations, which depends on data content (internal data consistency) • No need to behave “good” in case of data inconsistencies (software

faults in our case), but need to handle them smoothly• No software crash allowed• Good example: string copy functions

› Use timeout for limiting operations waiting for any kind of external answer (see later)

Limit all operations

Page 9: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• You should never use strcpy in real life. Why? • It is an unsafe function rewritten as strncpy which limits the

maximum bytes copied

Copying Strings

Page 10: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Copying Strings

Page 11: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Copying Strings

Page 12: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Copy Strings

Page 13: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Copy Strings

Page 14: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

“If ifs and ands were pots and pans

there'd be no work for tinkers' hands.”

›Exclude everything possible.›Do not skip else.›Most frequently true first.

ConditionalPractices

Page 15: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Exclude everything possible

Page 16: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Use “smaller then” instead of equality check

• Check for value groups instead of individual values if possible

Exclude everything possible

Page 17: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• System managers, software architectures often not handling negative situations• Requirement does not say anything what software should do if a

condition does not happen

• Developers always need to think what should happen if condition does not meet• Write an else branch all the time and remove only if you are sure

that it concludes on right behavior• Positive path is only the smaller part of development (~30%)

Do Not Skip Else

Page 18: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Requirement: if your program receive an “echo-request” message, send back an “echo-reply”

Do Not Skip Else

Page 19: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Do Not Skip Else

Page 20: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Do Not Skip Else

Page 21: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Requirement:• Count ‘a’ and ‘e’ letters separately in a string.

Most frequently true first

Page 22: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Most frequently true first

Page 23: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Most frequently true first

Page 24: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Most frequently true first

Page 25: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Requirement:• Count ‘a’ and ‘e’ letters together in a string.

Most frequently true first

Page 26: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Most frequently true first

Page 27: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

CONCEPTS

Page 28: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• What cases you must check validity in functions’ input parameters?

• Trust your own software• Either it is your code or some of your colleagues’ code• You should trust internal interface descriptions• No need to check each and every input parameters’ validity

• Do not trust any data received on external interfaces• External interfaces can be “noisy” or “evil”• Or disconnected any time (unknown message received)• In multivendor situation different companies may differently understood

standards

Shall I trust input parameters?

Page 29: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

http://xkcd.com/327/

Tales of the Little Bobby Tables

Page 30: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Sanitize your (database) input• Check each and every human input and… • Be protective, just permit what you are prepared for• For example: hard space, soft space (hyphenation)

Tales of the Little Bobby Tables

Page 31: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Use timers to limit operations should be finished by an external module in a certain time

• Timers counting (mili)seconds and when time expired a function is executed

• Do not trust your external input, always protect your code

Do not Wait Forever

Page 32: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• General principle of lean and agile (iterative) methodologies

• Let your software faults shown as early as possible• Do not hide problems (for example

unhandled else branches)

• Continuous integration• Automatized unit testing• Nightly (or more frequent) builds• Regression test run• Visibility of code quality

Fail Fast

Page 33: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

› Always remember the KISS principle.

Keep it simple and stupid.

› WP: “A design principle noted by the U.S. Navy in 1960. Most systems work best if they are kept simple rather than made complicated; therefore simplicity should be a key goal in design and unnecessary complexity should be avoided.”

› Variations: "keep it short and simple" and "keep it simple and straightforward"

KISS

Page 34: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• After two weeks very hard to remember what you did and why some variables in your very detailed algorithm

• There are more and less self documenting languages (Pascal vs. C)

• There are some editorial steps you can use for make your code easy to understand later by you or anyone else

• Proposals:1. Descriptive variable names (long)

2. Descriptive function names

3. Format source code in a coherent way

4. Write comments

Self Documenting Code

Page 35: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

› A set of programming rules must be followed in coding by all developers

› Give a common base for all new development

› For example:• Logging and tracing rules• Software start // order of the components• Priority of new feature’s threads• How your code should handle failover or takeover• GUI rules

Coding Rules,Design Rules

Page 36: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Make your code more readable, easier to understand• All your products’ components’ source code should look the

same• Contains

• Comment conventions• Indent style conventions• Naming conventions• Best programming practices• Programming rules of thumb (Rule of three, Pareto, Ninety-Ninety)• Programming style conventions

• Example: Google C++ Style Guide

Editorial Rules,Coding Conventions

Page 37: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Productified source code goes to maintenance after deployment

• Effective coding increasing complexity, reducing readability probably reducing maintainability

• Maintainability versus effectiveness – needs to find the right balance

Maintainability

Page 38: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

METHODOLOGIES

Page 39: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Waterfall and Iterative Methods• Give me the possibility to handle it as a big chapter…

Page 40: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

SUMMARY

Page 41: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

› “Do not assume anything.”› Check everything, until you are sure how the system,

features or function works• General positive (non-erroneous) return value is 0• but printf() returns the number of written bytes to stdout

› Q: Why scanf( “Give me a number: %d”, &i );

you are not able to type a number there?

Summary: Rule #1

Page 42: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

› “Do not assume anything.”› Check everything, until you are sure how the system, features or

function works• General positive (non-erroneous) return value is 0• but printf() returns the number of written bytes to stdout

› Q: Why scanf( “Give me a number: %d”, &i );

you are not able to type a number there?

(A: Pattern matching.)

› These functions are fossils, but you should not underestimate the power of “historical reasons”

Summary: Rule #1

Page 43: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

SOFTWARE DEVELOPMENT METHODOLOGIES

Page 44: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Methodologies

• Waterfall• Prototype model• Incremental• Iterative• V-Model• Spiral• Scrum• Cleanroom• RAD

• DSDM• RUP• XP• Agile• Lean• Dual Vee Model• TDD• FDD

Page 45: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Waterfall

• Sequential design process

• Progress is seen as flowing steadily downwards (like a waterfall) through SDLC

Page 46: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Waterfall• Do we know all requirements in the beginning?• If we have a problem we need to go back several phases.• Results long project time, usually year or more.

• Slow release cycle.

• Finding problems early is cheaper than later.• Proven to Waterfall only.

Page 47: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Waterfall #1• Jump to next phase only if the prior one is completed

• PROs• Detailed early analysis cause huge advantages at later phases• If a bug found earlier, it is much cheaper (and more effective) to fix

than bugs found in a later phase• Requirement should be set before design starts• Points to importance of documentation (minimized “broken leg”

issue)• Disciplined and well-structured approach• Effective for stable software projects• Easy to plan from project management point of view

Page 48: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Waterfall #2• CONs

• Changes are expensive• Client does not explicitly know what he or she wants• Client does not explicitly know what is possible to have • Need to finish every phase fully• Long projects, difficult to keep the plan• Designers may not know in advance how complex a feature’s

implementation• “Measure twice, cut once”

Page 49: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Incremental Build Model

• A model between waterfall and iterative methods

• The model is designed, implemented and tested incrementally (a little more is added each time).

• Finished when satisfies all the requirements.

• Combines the elements of the waterfall model with the iterative philosophy of prototyping.

• How long test phase needed – it limits the minimum length of a development “increment”

• Non functional requirements may cause problems

• Also hard to place the efforts needed for development environment creation

Page 50: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Iterative Methods

• Iterative methods are different combinations of both iterative design or iterative method and incremental build model for development.

Page 51: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Incremental vs. Iterative

Page 52: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Iterative / Prototyping

Page 53: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Effort in Iterative Development

Page 54: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Case Study• For small impacts

Start ofStudy

End ofStudy

Study Backlog

Product Backlog

EPP Node

Start ofExecution

< 2 weeksOB WSMD

created

MDErequest

MDE QSsent back to CU

MDE POreceived

Execution &Verification

Release & Delivery

PD0 PD3

Page 55: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Prototyping

• Creating prototypes of software applications i.e. incomplete versions of the software program being developed

• A prototype typically simulates only a few aspects of, and may be completely different from, the final product.

Page 56: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Spiral Model

• Combining elements of design and prototyping-in-stages

• Combines the features of the prototyping and the waterfall model

• The spiral model is intended for large, expensive and complicated projects

• Advantages of top-down and bottom-up concepts

Page 57: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Background

• Top-down• deductive reasoning• analysis or

decomposition• Descartes• G => 1

• Bottom-up• inductive reasoning• synthesis• Bacon• 1 => G

Page 58: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

RAD

• Minimal planning and fast prototyping.

• Developing instead of planning

• The lack of pre-planning generally allows software to be written much faster, and makes it easier to change requirements.

Page 59: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Cleanroom• The Cleanroom process embeds software development and testing within a statistical quality control framework.

• Mathematically-based software development processes are employed to create software that is correct by design, and statistical usage testing processes are employed to provide inferences about software reliability.

• This systematic process of assessing and controlling software quality during development permits certification of software fitness for use at delivery.

Page 60: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Agile• Group of software

development methods• Based on iterative and

incremental development• Most important phrases

• self-organizing, cross-functional teams

• adaptive planning, • evolutionary development and

delivery, • a time-boxed iterative

approach,• rapid and flexible response to

change. • A conceptual framework• The Agile Manifesto in 2001.

Page 61: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Scrum

• Scrum is an iterative and incremental agile software development framework

• A flexible, holistic product development strategy

• Development team works as an atomic unit

• Opposing to sequential approach

Page 62: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Scrum

• Cross-functional teams

• Verification inside the teams

• System test is usually out of the team responsibility

• Competence problems• Small projects problem• Component test• Function test• Early system test

Page 63: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Lean (Kanban)

• A translation of lean manufacturing principles and practices

• Toyota Production System,

• Today part of Agile community.

Page 64: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Lean Principles

1. Eliminate waste

2. Amplify learning

3. Decide as late as possible

4. Deliver as fast as possible

5. Empower the team

6. Build integrity in

7. See the whole

Page 65: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Extreme Programming (XP)• Improve software quality and responsiveness to changing customer requirements

• A type of agile software development

• Frequent "releases" in short development cycles

• Introduce checkpoints where new customer requirements can be adopted.

Page 66: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

XP Concepts (examples only)

• Pair programming• Planning game• Test-driven development

• Continuous integration

Page 67: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

DSDM• An agile project delivery framework,

primarily • DSDM fixes cost, quality and time at

the outset and uses the MoSCoW prioritization of scope

• Pareto principle

• M - MUST: Describes a requirement that must be satisfied in the final solution for the solution to be considered a success.

• S - SHOULD: Represents a high-priority item that should be included in the solution if it is possible. This is often a critical requirement but one which can be satisfied in other ways if strictly necessary.

• C - COULD: Describes a requirement which is considered desirable but not necessary. This will be included if time and resources permit.

• W - WOULD: Represents a requirement that stakeholders have agreed will not be implemented in a given release, but may be considered for the future.

Page 68: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Test-driven development (TDD)• Relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.

• Test-first programming concept of extreme programming in the beginning

• Today standalone methodology

Page 69: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Feature-driven development (FDD)

• Iterative and incremental development process.

• An Agile method• Driven from a client-valued functionality (feature) perspective

• Mostly part of other methodologies

• What is needed for the customer most:• GUI?

• Perception of the quality of a SW by customers?

Page 70: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Rational Unified Process (RUP)• An iterative software development process framework created by the Rational Software Corporation (IBM)

• Not a concrete prescriptive process, but an adaptable framework, intended to be tailored by the development organizations

• Expected to select elements of the process that are appropriate

Page 71: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

V-model

• The V-model is an extension of the waterfall model.

• Show the relationships between development phases and test phases

• Time and project completeness vs. level of abstraction

Page 72: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

V-model, complex

Page 73: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Dual V-model• Describes a model of

complex development• For example:

• Hardware• Platform• Application software

• Development of a system's architecture is the “big V”• Components’/entities’

developments are the “small V”-s

• It shows interactions and sequences of developing a complex system and a system of systems.

Page 74: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

Shouldn’t forget

Page 75: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

CONCEPTSNeed to be understood

Page 76: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

List of Concepts

• Practice• CI• Automated testing• LSV concept• Version control• Flow approach -- swedish hospital pres

• UML

• Design Patterns• Testing phases• code coverage• code review• defect backlog• static code analysis• unit test coverage• SQR

Page 77: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

SOFTWARE DEVELOPMENT FLOW

Page 78: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

System Development Lifecycle

Project planning, feasibility study

Systems analysis, requirements

definition

Systems designImplementation,software design

Integrationand testing

Acceptance,installation,deployment

Maintenance

SDLC

Page 79: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

System Development Lifecycle

Project planning, feasibility study

Systems analysis, requirements

definition

Systems designImplementation,software design

Integrationand testing

Acceptance,installation,deployment

Maintenance

SDLC

Page 80: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

SDLC – Close to Reality

Page 81: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Project planning, feasibility study: Establishes a high-level view of the intended project and determines its goals.

• Systems analysis, requirements definition: Refines project goals into defined functions and operation of the intended application. Analyzes end-user information needs.

• Systems design: Describes desired features and operations in detail, including screen layouts, business rules, process diagrams, pseudocode and other documentation.

• Implementation: The real code is written here.

SDLC

Page 82: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Integration and testing: Brings all the pieces together into a special testing environment, then checks for errors, bugs and interoperability.

• Acceptance, installation, deployment: The final stage of initial development, where the software is put into production and runs actual business.

• Maintenance: What happens during the rest of the software's life: changes, correction, additions, moves to a different computing platform and more. This, the least glamorous and perhaps most important step of all, goes on seemingly forever.

SDLC

Page 83: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• http://www.computerworld.com/s/article/71151/System_Development_Life_Cycle

• Waterfall might be useful in case of well determined req.-s and plans, but extreme could be better for less well defined requirements and prject plans

• Requirements• Specification• Architecture• Construction• Design• Testing• Debugging• Deployment• Maintenance

Activities and Steps

Page 84: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• Processes and regular activities (loops) always need additional efforts/people (cost)

• Means expensive…• But quality is a “must”…

• Or “good enough” quality?

• Processes• Good designer, bad designer

• Prepare for average designers

• No need for process if SW developed by one person

• Quality is far less a question indeed if someone knows the whole software alone

Problem of Processes

Page 85: CODING FOR "REAL LIFE" Safe coding considering software industry expectations in programming

• RUP• XP• Agile• Lean• Dual Vee Model• TDD• FDD

• Waterfall• Prototype model• Incremental• Iterative• V-Model• Spiral• Scrum• Cleanroom• RAD• DSDM

Methodologies