CONTEXTVS, STVLTE!

Context, stupid!



Piotr Przybył
piotr[at]przybyl.org
piotrprz
WrocławJUG, 20 III MMXVIII

© 2018 Piotr Przybył. Licensed under Simplified BSD license.

CAVEAT AVDITORES

Context exists.

Go and find it.

Don't guess it.

169

Is this far?

https://en.wikipedia.org/wiki/File:Mars_Climate_Orbiter_-_mishap_diagram.png

the only picture of Mars taken by MCO

https://photojournal.jpl.nasa.gov/catalog/?IDNumber=PIA02330

Skipping the context
can be expensive.

Sometimes very much.

What is the speed of light?

~3 x 108 m/s

in vacuum

90 m/s less in the air

~1.2 x 108 m/s in diamonds

Make sure your mantra
matches the context.

Columbia shuttle
Train tunnel
Train tunnel
Train tunnel

Sometimes you can't alter
your context.

Context can live long.

Very long.

Cubicles in office
PC speaker

https://upload.wikimedia.org/wikipedia/commons/8/8c/PC-Speaker_IMG_9311-9312.JPG

Far east bath
Cyber crime

Hello! :-)

Привет! )))

Salut ! :-)

Cultural context matters.

It is in us.

Your users have one.

You have one too.

Login form
E-mail
Monitor
Fly

Sometimes context is FUBAR!

Factory
Toothpaste
Weight
Scale

Context in not only
input to your system.

Desired effect
makes your context too.

Which sorting algorithm is the best/fastest?

I IV II III

1 4 2 3

bubble: 5 comparisons

quick: 6 comparisons

Check: https://visualgo.net

Factors

  • initial order
  • keeping initial order
  • data set size
  • cost of comparison
  • cost of swap
  • cost of insertion
  • cost of index based access
  • cost of additional memory
  • etc.

There is no
"the best [sorting] algorithm"
if the data is unknown.

The data is your context.

Slow app

Slow DB?

classroom

Indexes to the rescue??

superhero

Indexes

  • used in WHERE clause
  • build and balanced during INSERTS*
  • make sense for fairly distributed values
  • "easy" to index

Indexes are not free lunch.

Gluttony is not healthy.

Ingredients matter.

The way you process data
is your context.

Print sorted list

of children's names

in typical 3 tier web application

ADAM ANNA HVBERT

contacts app

ADAM ANNA HVBERT

three tier app

ORDER BY is not for free.

Neither is any other data processing.

The purpose of data processing is your context.

Optimisation

consumption or resources, first approach
consumption or resources, second approach

Make sure that
what you define your context
is not too narrow.

Interrupt in Java is broken

because it doesn't stop the thread instantly, you need some ceremony, so always `interrupt` your Thread again.

https://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html

An interrupt is an indication to a thread that it should stop what it is doing and do something else. It's up to the programmer to decide exactly how a thread responds to an interrupt, but it is very common for the thread to terminate. This is the usage emphasized in this lesson.

in other words

interrupt means

May I have your attention, please?

Thread.interrupt is not a drop-in replacement for

Thread.stop

Thread.destroy

Because a thread can't be stopped safely in a generic way.

Transactions are a must

for any serious system

to keep data consistency

Bank
Money transfer

Are they really?

Transactionless
Transactions across REST microservices?
What is the most accepted transaction strategy for microservices
How I Avoid Two-Phase Commit

When demanding transactions

make sure you don't do too much

Composition good,
inheritance not good

[...] general principle in type system design: It is safe to assume that a type T is a subtype of a type U if you can substitute a value of type T wherever a value of type U is required. This is called the Liskov Substitution Principle.
The principle holds if T supports the same operations as U,
and all of T's operations require less and provide more than the corresponding operations in U.

Programming in Scala by M. Odersky, L. Spoon, B. Venners

Inheritance isn't bad per se.

Misunderstanding and misusing it is bad.

Composition vs. Inheritance: How to Choose?

DRY vs. DAMP

DRY vs. DAMP

It's a balance, not a contradiction

Simple way of finding and determining context

Why?

Why?

Why?

Why?

Why?

Oil

A bit more advanced

Fishikawa

Ishikawa fishbone diagrams

A.K.A. Cause-and-effect diagram

CONTEXTVS, STVLTE!!


Thanks a lot.

Be aware!

Because it depends!!

Piotr Przybył
piotr[at]przybyl.org
piotrprz
WrocławJUG, 20 III MMXVIII
http://bit.ly/2GDNuBk
qr