Data Visibility Abstraction @stuartsierra Being abstract is - - PowerPoint PPT Presentation

data visibility abstraction
SMART_READER_LITE
LIVE PREVIEW

Data Visibility Abstraction @stuartsierra Being abstract is - - PowerPoint PPT Presentation

Data Visibility Abstraction @stuartsierra Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.


slide-1
SLIDE 1

Data Visibility Abstraction

@stuartsierra

slide-2
SLIDE 2
  • Edsger W. Dijkstra

“Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.”

slide-3
SLIDE 3

BASIC

slide-4
SLIDE 4
slide-5
SLIDE 5

10 FOR I = 1 TO 5 20 PRINT I 30 NEXT I RUN 1 2 3 4 5

slide-6
SLIDE 6
slide-7
SLIDE 7

SUB FOO (parameters) ' ... do whatever ... END SUB FUNCTION BAR (parameters) ' ... do whatever ... BAR = ' return value END FUNCTION

slide-8
SLIDE 8

C++

slide-9
SLIDE 9

http://abstrusegoose.com/249

slide-10
SLIDE 10

Perl

slide-11
SLIDE 11

PERL(1) Perl Programmers Reference Guide PERL(1) NAME perl - Practical Extraction and Report Language SYNOPSIS Overview perl Perl overview (this section) perlintro Perl introduction for beginners perltoc Perl documentation table of contents Tutorials perlreftut Perl references short introduction perldsc Perl data structures intro perllol Perl data structures: arrays of arrays perlrequick Perl regular expressions quick start perlretut Perl regular expressions tutorial perlboot Perl OO tutorial for beginners perltoot Perl OO tutorial, part 1

slide-12
SLIDE 12

#!/usr/bin/env perl my $user = { name => "Stuart", age => 15, langs => [ "BASIC", "C++", "Perl" ] }; print $user->{'langs'}[2];

slide-13
SLIDE 13

Tie::File(3pm) Perl Programmers Reference Guide Tie::File(3pm) NAME Tie::File - Access the lines of a disk file via a Perl array SYNOPSIS # This file documents Tie::File version 0.97 use Tie::File; tie @array, 'Tie::File', filename or die ...; $array[13] = 'blah'; # line 13 of the file is now 'blah' print $array[42]; # display line 42 of the file $n_recs = @array; # how many records are in the file? $#array -= 2; # chop two records off the end for (@array) { s/PERL/Perl/g; # Replace PERL with Perl everywhere }

slide-14
SLIDE 14

XML

slide-15
SLIDE 15

<user> <name>Stuart</name> <age>15</age> <langs> <lang>BASIC</lang> <lang>C++</lang> <lang>Perl</lang> <lang>XML</lang> </langs> </user>

slide-16
SLIDE 16

use XML::DOM; my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile ("file.xml"); # print all HREF attributes of all CODEBASE elements my $nodes = $doc->getElementsByTagName ("CODEBASE"); my $n = $nodes->getLength; for (my $i = 0; $i < $n; $i++) { my $node = $nodes->item ($i); my $href = $node->getAttributeNode ("HREF"); print $href->getValue . "\n"; }

slide-17
SLIDE 17

<xsl:template match="/doc:article/doc:info"/> <xsl:template match="doc:link"> <xsl:element name="ulink" namespace="http://docbook.org/ns/docbook"> <xsl:attribute name="url" namespace="http://docbook.org/ns/docbook"> <xsl:value-of select="@xlink:href"/> </xsl:attribute> </xsl:element> </xsl:template> <xsl:template match="doc:footnote"> <xsl:element name="footnote" namespace="http://docbook.org/ns/docbook"> <xsl:apply-templates select="*"/> </xsl:element> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>

slide-18
SLIDE 18

#!/usr/bin/env bash saxon one.xslt site.xml t1.xml saxon two.xslt t1.xml t2.xml saxon three.xslt t2.xml t3.xml saxon four.xslt t3.xml index.html

slide-19
SLIDE 19
slide-20
SLIDE 20

Common Lisp

slide-21
SLIDE 21

http://gigamonkeys.com/

slide-22
SLIDE 22

(defun breadth-first-search (start) (let ((open (list start)) ; the list of nodes to be examined (closed (list)) ; the list of nodes already examined (steps 0) ; number of iterations (expanded 0) ; total number of nodes expanded (stored 0)) ; max number of nodes stored at any one time (loop while open do (let ((x (pop open))) (when (finished? x) (return (format nil "Found ~a in ~a steps. Expanded ~a nodes, stored a maximum of ~a nodes." x steps expanded stored))) (incf steps) (pushnew x closed :test #'equal) (let ((successors (successors x))) (incf expanded (length successors)) (setq successors (delete-if (lambda (a) (or (find a open :test #'equal) (find a closed :test #'equal))) successors)) (setq open (append open successors)) (setq stored (max stored (length open))))))))

slide-23
SLIDE 23

access Alexandria arnesi aromyxo bknr-utils ch-util cl-configuration cl-jpl-util cl-utilities CLLIB common-idioms de.setf.utility dso-util fare-utils Formlets fukacl hu.dwim.util incf-cl JARW kmrcl mccme-helpers metatilities metatilities-base monkeylib- utilities mop-utils my-util pergamum qtility rutils s-utils SCLF umpa-lumpa ytools

The Quagmire of Convenience

slide-24
SLIDE 24

;; Association list (setq user '((name . "Stuart") (age . 24) (langs . ("XSLT" "Perl" "Lisp"))) ;; Hash table (setq user (make-hash-table)) (setf (gethash 'name user) "Stuart") (setf (gethash 'age user) 24) (setf (gethash 'langs user) '("XSLT" "Perl" "Lisp"))

slide-25
SLIDE 25
slide-26
SLIDE 26

(defcenum svtype :null ; undef :iv ; Scalar (integer) :nv ; Scalar (double) :rv ; Scalar (reference) :pv ; Scalar (string) :pviv ; pointer to an IV (used in hashes) :pvnv ; pointer to an NV (used in hashes) :pvmg ; blessed or magical scalar :pvbm ; ?? :pvlv ; ?? :pvav ; Array :pvhv ; Hash :pvcv ; Code reference :pvgv ; typeglob (possibly file handle) :pvfm ; ?? :pvio) ; an I/O handle?

slide-27
SLIDE 27

(defun call-perl (function return-type methodp &rest args) (need-perl) (perl-scope (pushmark) (push-mortals-on-stack args) (get-stack-by-type return-type (funcall (if (stringp function) #'perl-call-function ;; either scalar string or code reference #'perl-call-scalar) function (calling-flags return-type methodp)))))

slide-28
SLIDE 28

Ruby

slide-29
SLIDE 29

class Company < ActiveRecord::Base include Auditable belongs_to :group has_many :profiles, :dependent => :destroy has_many :users, :dependent => :destroy has_many :subscriptions, :dependent => :destroy, :order => :service_id has_many :services, :through => :subscriptions has_many :statistics, :dependent => :destroy accepts_nested_attributes_for :subscriptions, :allow_destroy => true, :reject_if => lambda{|attrs| attrs[:_create] == '0'} accepts_nested_attributes_for :users, :allow_destroy => true after_update :ensure_users_match validates_presence_of :name validates_uniqueness_of :name validate :presence_of_subscriptions default_scope :order => :name end

slide-30
SLIDE 30

doc = Hpricot.parse("file.xml") doc / "/html/body//p//img" doc / "html > body > p img" doc / :html / :body / :p / :img

slide-31
SLIDE 31

pidgin

a grammatically simplified form of a language, used for communication between people not sharing a common language.

slide-32
SLIDE 32

Clojure

slide-33
SLIDE 33

(def user {:name "Stuart" :age 25 :langs ["Lisp" "Ruby" "Clojure"]}) (-> user :langs last) ;;=> "Clojure"

slide-34
SLIDE 34

user=> (inspect-tree user)

slide-35
SLIDE 35

(map function set-of-maps) (map function (resultset-seq query)) (map function (line-seq file)) (map function (xml-seq xml-tree)) (map function (file-seq directory)) (map function list-of-vectors) (map function map-of-maps) (map function (range)) ; all integers (map function "characters in string")

slide-36
SLIDE 36

(def primes (letfn [(next-prime [known-primes n] (lazy-seq (if (some #(zero? (rem n %)) known-primes) (next-prime known-primes (inc n)) (cons n (next-prime (conj known-primes n) (inc n))))))] (next-prime [] 2))) (map #(inc (* 2 %)) primes) ;;=> (5 7 11 15 23 27 35 39 47 59 ...)

slide-37
SLIDE 37

user=> (def editor (d/entity db editor-id)) user=> editor ;;=> {:db/id 17592186045425} user=> (:user/firstName editor) ;;=> "Edward" user=> (:comment/_author editor) ;;=> [{:db/id 17592186045429} ...]

slide-38
SLIDE 38

(defn complex-process [] (let [result (computation (get-input)] (if (condition? result) (launch-missile) (erase-hard-drive))))

slide-39
SLIDE 39

user=> (complex-process) ;;=> nil

slide-40
SLIDE 40

(defn gather-information [state] (assoc state :analysis (computation (:input state))) (defn make-decision [state] (assoc state :response (if (condition? (:analysis state)) :launch-missile :erase-hard-drive)))

slide-41
SLIDE 41

user=> (make-decision {:input "trustno1"}) ;;=> {:input "trustno1" ;; :analysis :security-breach ;; :response :erase-hard-drive}

slide-42
SLIDE 42

(defn take-action [state] (case (:response state) :launch-missile (launch-missile) :erase-hard-drive (erase-hard-drive))) (defn complex-process [initial-state] (-> initial-state gather-information make-decision take-action))

slide-43
SLIDE 43

(defn log [state] (logging/info state) state) (defn complex-process [initial-state] (-> initial-state gather-information make-decision log take-action))

slide-44
SLIDE 44

Convert Data Convert Data Data

Effect or Output Input

slide-45
SLIDE 45

Interceptor T wo Interceptor Three Interceptor One

Enter Data

Response Request

Leave

Data Enter Data

Leave

Data Enter Data

Leave

Data

slide-46
SLIDE 46

http://pedestal.io

slide-47
SLIDE 47

“Hexagonal Architecture” Application Adaptor Adaptor Adaptor A d a p t

  • r

A d a p t

  • r

Interactive GUI Database Web Services Automated T ests

slide-48
SLIDE 48

Data Manipulator Adaptor Adaptor Adaptor A d a p t

  • r

A d a p t

  • r

Interactive GUI Database Web Services Automated T ests

slide-49
SLIDE 49

https://github.com/Netflix/Hystrix

slide-50
SLIDE 50

(hystrix/defcommand complex-command {:timeout 3000 :request-volume-threshold 10 :error-threshold-percentage 75 :sleep-window 60000} [input] ... code ... )

slide-51
SLIDE 51

;; Rally the troops (defn init! [] (connect-to-database!) (create-thread-pools!) (start-background-processes!) (start-web-server!) ...)

slide-52
SLIDE 52

;; System lifecycle (defrecord System [storage config web-service] Lifecycle (start [_] (start storage) (start web-service)) (stop [_] (stop web-service) (stop storage)))

slide-53
SLIDE 53

;; System lifecycle (reduce (fn [system key] (update-in system [key] start)) system (dependency-sort (keys system)))

slide-54
SLIDE 54
  • Design programs to manipulate data
  • Separate decisions from side effects
  • Reify processes
slide-55
SLIDE 55
  • Me: stuartsierra.com,

@stuartsierra

  • Us: thinkrelevance.com
  • Clojure: clojure.org