technology for reduce of mistakes - うっかりをなくす技術

103
Technology for reduce of mistakes id:karupaneura YAPC::Asia 2015 #yapcasiaD

Upload: karupanerura

Post on 21-Jan-2018

8.664 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Technology for reduce of mistakes - うっかりをなくす技術

Technology for reduce of mistakesid:karupaneura YAPC::Asia 2015 #yapcasiaD

Page 2: Technology for reduce of mistakes - うっかりをなくす技術

Oops.. I forgot AC adaptor..

Page 3: Technology for reduce of mistakes - うっかりをなくす技術

Thank you very very much!!!!

Page 4: Technology for reduce of mistakes - うっかりをなくす技術

Hello, YAPC::Asia!!

Page 5: Technology for reduce of mistakes - うっかりをなくす技術

About me

• Kenta SATO (id:karupanerura)

• Perl/XS/Swift/Kotlin/Java/Crystal/C99/etc..

• Gotanda.pm Author

• Senior Engineer at Mobile Factory, Inc.

• WebApp/iOS/Android/Operation/etc..

Page 6: Technology for reduce of mistakes - うっかりをなくす技術

CPAN (PAUSE: KARUPA)

• Time::Strptime

• Geo::Hex::V3::XS

• Test::SharedObject

• Plack::App::Vhost

• etc..

Page 7: Technology for reduce of mistakes - うっかりをなくす技術

Gotanda.pm #6

• at 9/17(Tue) GaiaX Inc.

• Join us!

• http://gotanda.pm.org/

Page 8: Technology for reduce of mistakes - うっかりをなくす技術

YAPC::Asia with me

• 2011: LT (My first attend to YAPC::Asia)

• 2012: LT + Individual Sponsor

• 2013: 20min Talk + individual sponsor

• 2014: 40min Talk + individual sponsor + volunteer staff

• 2015: 60min Talk + individual sponsor + core staff

• 2016: ???

Page 9: Technology for reduce of mistakes - うっかりをなくす技術

Summary of this talk

Page 10: Technology for reduce of mistakes - うっかりをなくす技術

Summary of the talk

• About of human error. (human factors)

• How to reduce human error?

• The hint for reducing of human error factors

• by technology/technic

Page 11: Technology for reduce of mistakes - うっかりをなくす技術

Agenda

1. Human Error

2. How to notice human error factors?

3. How to reduce factors by engineering?

4. Approaches by engineering

5. Conclusion

Page 12: Technology for reduce of mistakes - うっかりをなくす技術

Human Error

Page 13: Technology for reduce of mistakes - うっかりをなくす技術

We need safe code

• Don’t want to crash application

• Don’t want to mistake the code operation

• Don’t want to destroy data

• Don’t want to break code when modified

Page 14: Technology for reduce of mistakes - うっかりをなくす技術

What is human error?

Page 15: Technology for reduce of mistakes - うっかりをなくす技術

Human error ≒ mistake

Page 16: Technology for reduce of mistakes - うっかりをなくす技術

Human error is …

• The word of human factors field

• David Meister defined:

• “a deviations from the requested performance by system.”

• source: “Human factors: theory and practice”

Page 17: Technology for reduce of mistakes - うっかりをなくす技術

POINT: Human error is …

• In our context: operator = another developer

• It’s defined in a operator’s context

• Engineers create a system and operate it ourself.

• So we should think that a developer and a operator are different person.

Page 18: Technology for reduce of mistakes - うっかりをなくす技術

POINT: Human error is …

• “System” means …

• a infrastructure

• a application

• a source code

• etc…

Page 19: Technology for reduce of mistakes - うっかりをなくす技術

Why happen a human error?

Page 20: Technology for reduce of mistakes - うっかりをなくす技術

Factor of human error

• grouping by factor:

• Human factor

• Management factor

• Environment factor

Page 21: Technology for reduce of mistakes - うっかりをなくす技術

Human factors

• Direct factor:

• A carelessness

• A mistake

Page 22: Technology for reduce of mistakes - うっかりをなくす技術

Approach for human factors• Control arousal level

• Pointing confirmation

• Accident prediction training

• NKY Training

Page 23: Technology for reduce of mistakes - うっかりをなくす技術

Management factors

• Indirect factor:

• Not enough direction

• Not enough review

Page 24: Technology for reduce of mistakes - うっかりをなくす技術

Approach for management factors• Work flow improvements

• Simplification of proces

• Code review

• Documentation

• Automation

Page 25: Technology for reduce of mistakes - うっかりをなくす技術

Environment factors

• Indirect factor:

• Difficult to understand

• Complex ways

• Tend to overlook a mistake

• Tend to make mistakes

Page 26: Technology for reduce of mistakes - うっかりをなくす技術

Approach for environment factors• Make it easy to understand

• Simple ways

• Tend to notice a mistake

• Prevent/Safe a mistake

Page 27: Technology for reduce of mistakes - うっかりをなくす技術

CONCLUSION of this section

• Human error ≒ mistake

• Think in another developer's point of view

• Is it difficult to understand?

• Are there complex ways?

• Is it be tend to overlook a mistake?

Page 28: Technology for reduce of mistakes - うっかりをなくす技術

Agenda

1. Human Error

2. How to notice human error factors?

3. How to reduce factors by engineering?

4. Approaches by engineering

5. Conclusion

Page 29: Technology for reduce of mistakes - うっかりをなくす技術

How to notice mistake factors?

Page 30: Technology for reduce of mistakes - うっかりをなくす技術

near-miss

• In Japanese “ヒヤリ・ハット”

• Accidents that cause no loss/injuries/damage

Page 31: Technology for reduce of mistakes - うっかりをなくす技術

Heinrich's law

“that in a workplace, for every one major injury accident there are 29 accidents that cause minor injuries and 300 accidents that cause no injuries (what are often termed “incidents”), roughly a 1-30-300 proportioning.”

Page 32: Technology for reduce of mistakes - うっかりをなくす技術

Heinrich's lawserious accident

slight accident

near-miss

frequency

Page 33: Technology for reduce of mistakes - うっかりをなくす技術

POINT: Heinrich's law

A mistake factor makes many near-misses

Page 34: Technology for reduce of mistakes - うっかりをなくす技術

Be careful near-miss!

• Tend to overlook

• because not loss/injuries/damages

• Resolving near-misses prevents incidents

Page 35: Technology for reduce of mistakes - うっかりをなくす技術

How to find near-misses factors?

Page 36: Technology for reduce of mistakes - うっかりをなくす技術

Collect the case of near-misses

Page 37: Technology for reduce of mistakes - うっかりをなくす技術

How to collect the case of near-misses?

Page 38: Technology for reduce of mistakes - うっかりをなくす技術
Page 39: Technology for reduce of mistakes - うっかりをなくす技術

Github issue is awesome

• Tag is awesome

• CRITICAL/LITE/ARCH/CODE/etc..

• Engineer friendly

• Easy to link with code

Page 40: Technology for reduce of mistakes - うっかりをなくす技術

Code review

• Get a operator points of view

• Find a factor of near-miss

• Create issue soon

• Analyze and fix it

Page 41: Technology for reduce of mistakes - うっかりをなくす技術

CONCLUSION of this section

• Resolving near-misses prevents incidents

• Should collect the case of near-misses

• GitHub issue is good

• Code review is good approach

• for finding a factor of near-misses

Page 42: Technology for reduce of mistakes - うっかりをなくす技術

Agenda

1. Human Error

2. How to notice human error factors?

3. How to reduce factors by engineering?

4. Approaches by engineering

5. Conclusion

Page 43: Technology for reduce of mistakes - うっかりをなくす技術

How to reduce mistake factors

by engineering?

Page 44: Technology for reduce of mistakes - うっかりをなくす技術

Environment factors can be reduced by engineering

Page 45: Technology for reduce of mistakes - うっかりをなくす技術

How to reduce environment factors?

Page 46: Technology for reduce of mistakes - うっかりをなくす技術

Approaches

• Easy to understand

• Simple ways

• Tend to notice a mistake

• Prevent/Safe a mistake

Page 47: Technology for reduce of mistakes - うっかりをなくす技術

break..

Page 48: Technology for reduce of mistakes - うっかりをなくす技術

Agenda

1. Human Error

2. How to notice human error factors?

3. How to reduce factors by engineering?

4. Approaches by engineering

5. Conclusion

Page 49: Technology for reduce of mistakes - うっかりをなくす技術

Approachs by engineering

Page 50: Technology for reduce of mistakes - うっかりをなくす技術

Easy to understand

Page 51: Technology for reduce of mistakes - うっかりをなくす技術

Easy to understand

• Readable code

• Descriptive naming

• Code document/comment

• Less side effects

Page 52: Technology for reduce of mistakes - うっかりをなくす技術

Readable code

• Read it!!!!!!!!!!!!!

Page 53: Technology for reduce of mistakes - うっかりをなくす技術

Readable code

READ IT

SOON

Page 54: Technology for reduce of mistakes - うっかりをなくす技術

Descriptive naming

帰れま10

Page 55: Technology for reduce of mistakes - うっかりをなくす技術

Descriptive naming

Page 56: Technology for reduce of mistakes - うっかりをなくす技術

Descriptive naming

Page 57: Technology for reduce of mistakes - うっかりをなくす技術

Descriptive naming

Page 58: Technology for reduce of mistakes - うっかりをなくす技術

Code document/comment

• This does know you(developer) only!

• ”Why this approach is used?"

• "Why this workaround is needed?"

• etc..

• But, Operator needs this information.

Page 59: Technology for reduce of mistakes - うっかりをなくす技術

Less side effects

• No any side effects is best.

• But, we uses ...

• database

• view

• and ...

Page 60: Technology for reduce of mistakes - うっかりをなくす技術

Less side effects

• Approach:

• (Don't use global variable)

• Shorten object lifecycle

• Immutable(Readonly) object/value

• Functional programming

Page 61: Technology for reduce of mistakes - うっかりをなくす技術

Shorten object lifecycle

• Less status changes reduces side effects

• Object has statuses

• Make object in a minimum of scope

Page 62: Technology for reduce of mistakes - うっかりをなくす技術

e.g. Sledge::Plugin::Stash

Page 63: Technology for reduce of mistakes - うっかりをなくす技術

Immutable object/value

• Immutable object don't have any statuses

• It reduces side effects

• No logic depend on mutable status

• It makes many side effects in many cases

• Immutable object makes immutable status

Page 64: Technology for reduce of mistakes - うっかりをなくす技術

Immutable object/value

• Immutable variable:

• Swift:let / Java:final / Kotlin:val / Scala:val

• Perl: (Library makes readonly value)

• Readonly.pm/Const.pm

• Internals::SvREADONLY

Page 65: Technology for reduce of mistakes - うっかりをなくす技術

Immutable object/value

• Immutable object:

• Value object pattern

Page 66: Technology for reduce of mistakes - うっかりをなくす技術

Functional programming

• This is one approach for that the status is closed in minimal scope

• The status is closed in function

• The side effect is close in monad

• (But, I don’t know too much this field.)

Page 67: Technology for reduce of mistakes - うっかりをなくす技術

Simple ways

Page 68: Technology for reduce of mistakes - うっかりをなくす技術

Simple ways

• Immutable object/value

• Shallow nested code

• Modularization

Page 69: Technology for reduce of mistakes - うっかりをなくす技術

Shallow nested code

• Don't write deeply nested code

• Deeply nested code has many statuses

• It’s not simple

• Solution: structured programming

• Split code to other function

Page 70: Technology for reduce of mistakes - うっかりをなくす技術

Modularization

• Operation of the procedure should be a simple.

• Operator need High-Level API

• Practice structured programming

Page 71: Technology for reduce of mistakes - うっかりをなくす技術

Tend to notice a mistake

Page 72: Technology for reduce of mistakes - うっかりをなくす技術

Tend to notice a mistake

• Type restriction/checking

• strict.pm / warnings.pm (Perl)

• Static code analysis (Perl::Critic/Perl::Lint)

• Optional

• Assertion

• Automated test

Page 73: Technology for reduce of mistakes - うっかりをなくす技術

Type restriction

// Java

package org.yapcasia.app;

public class DB { public Prepare select (Query query) { // … }}

Page 74: Technology for reduce of mistakes - うっかりをなくす技術

Type checking

## Perl

use Smart::Args;

sub select { args my $class => ‘ClassName’, my $sql => ‘FooDBI::Query’;

…}

Page 75: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of type restrict/checking?• Checks type at compile-time or run-time

• Notices that type is incorrect

• When type is incorrect

• Operator probably made a mistake

Page 76: Technology for reduce of mistakes - うっかりをなくす技術

strict.pm

## Perl (no strict.pm)

$foo = 1; # it pass

## Perl (enabled strict.pm)

use strict;$foo = 1; # compile time error

# my $foo = 1; # *MUST* declare `my` variable# $foo = 2; # can use declared variable *ONLY*

Page 77: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of strict.pm?• Notices the typo at compile-time

• Difficult to use is a bad way in strict mode

• e.g.) soft reference

• SEE ALSO: perldoc strict

Page 78: Technology for reduce of mistakes - うっかりをなくす技術

warnings.pm

## Perl (no warnings.pm)

my $answer = ‘3:’ + 2; # => 5 (!?)

## Perl (enabled warnings.pm)

use warnings;

my $answer = ‘3:’ + 2; # => 5 (!?)# WARN: Argument "3:" isn't numeric in addition (+) at …

Page 79: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of warnings.pm?• Notices the incompatible implicit type

conversion at run-time

• and some warnings are available

• SEE ALSO: perldoc warnings

Page 80: Technology for reduce of mistakes - うっかりをなくす技術

Static code analysis

• Finds popular mistakes.

• in Perl: Perl::Critic/Perl::Lint

• in JavaScript: ESLint/JSLint/JSHint/etc..

• in Java: FindBugs/etc..

• in Swift: (I’m needing it, but not found yet..)

Page 81: Technology for reduce of mistakes - うっかりをなくす技術

Optional

// Swift

var foo : Int? = someNilableLogic()if let notNilFoo : Int = foo { // notNilFoo is not null}

println(“\(foo + 1)”) // it makes compile-time error

Page 82: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of Optional• Ensures the safety of access to nullable value

• in compile-time

• not need to check null manually

• Maybe monad can also be used as well

• .. maybe :p

Page 83: Technology for reduce of mistakes - うっかりをなくす技術

Assertion

/*** C ***/

int i = 1;i = add(i, 2);assert(i == 3); /* abort when `add` is broken */

Page 84: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of Assertion• Prerequisites becomes clear

• Notices when the precondition is lost

• in run-time

• C++11: static_assert

• checks assertion at compile-time

Page 85: Technology for reduce of mistakes - うっかりをなくす技術

Automated test

• No explanation needed :)

Page 86: Technology for reduce of mistakes - うっかりをなくす技術

Prevent/Safe a mistake

Page 87: Technology for reduce of mistakes - うっかりをなくす技術

Prevent/Safe a mistake

• defer, guard object, try-with-resources

• Max reqs per child

• Poka-yoke

Page 88: Technology for reduce of mistakes - うっかりをなくす技術

defer

// Swift 2.0 (XXX: not checked yet)let fd = open(filename, O_RDONLY)defer { close(fd) }…

// Gofh, err := os.Open(filename)if err != nil { panic(err)}defer f.Close()

Page 89: Technology for reduce of mistakes - うっかりをなくす技術

guard object

## Perl

use Guard;

my $sock = IO::Socket::INET->new(…);my $guard = guard { close($sock) };…

Page 90: Technology for reduce of mistakes - うっかりをなくす技術

try-with-resources

## Java7

try (FileReader r = new FileReader(filename)) { // …}

Page 91: Technology for reduce of mistakes - うっかりをなくす技術

What's the good point of defer, guard object?• Auto release the resources

• at appropriate timing

• in appropriate scope

• not need to release the resources manually

Page 92: Technology for reduce of mistakes - うっかりをなくす技術

Max reqs par child

• “Limit on the number of requests that an individual child server will handle during its life” (Apache)

• When the memory leak occurs

• The problem is reduced

Page 93: Technology for reduce of mistakes - うっかりをなくす技術

Poka-yoke

• In Japanese “ポカヨケ”

• The gimmick prevents mistake physically

• Example: Operator need shutdown a server

• When that the target server is used:

• Cannot shutdown

Page 94: Technology for reduce of mistakes - うっかりをなくす技術

CONCLUSION of this section

• There is engineering approaches for

• notice/reduce/prevent near-misses

• run-time check is good

• compile-time check is very good

• Static typing language is awesome

Page 95: Technology for reduce of mistakes - うっかりをなくす技術

Agenda

1. Human Error

2. How to notice human error factors?

3. How to reduce factors by engineering?

4. Approaches by engineering

5. Conclusion

Page 96: Technology for reduce of mistakes - うっかりをなくす技術

CONCLUSION

Page 97: Technology for reduce of mistakes - うっかりをなくす技術

Conclusion

• Think in another developer's point of view

• “Is it easy to understand?”, “Is it simple?”

• Resolving near-misses prevents incidents

• Should store the case of near-misses

• GitHub issue is good

Page 98: Technology for reduce of mistakes - うっかりをなくす技術

Conclusion

• Good approach:

• Easy to understand

• Simple ways

• Tend to notice a mistake

• Prevent/Safe a mistake

Page 99: Technology for reduce of mistakes - うっかりをなくす技術

TMTOWTDI :)

Page 100: Technology for reduce of mistakes - うっかりをなくす技術

Let’s find the new safety approach!

Page 101: Technology for reduce of mistakes - うっかりをなくす技術

Please vote me!

Page 102: Technology for reduce of mistakes - うっかりをなくす技術

Thank you for listening

Page 103: Technology for reduce of mistakes - うっかりをなくす技術

Any questions?