Complex Values


Published on

Complex Values by C. Haider, ESUG09, Brest, France

Published in: Technology, Spiritual
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • <CH> introduces Thomas explains his role as layouter and text author introduces historic develoment of the idea <T> introduces Christian and his work met CH a year ago at ESUG Values are in all our work Recognizing them makes modeling easier improves readability Helps with maintenance
  • <T> What we also found: Systems are fragile: different data workflows (Data not standardized. Sharing/aliasing between modules. Unexpected changes, Nil, errors, connection lost.) Complicated: variants not modeled, concurrency, understand legacy/foreign code, all-in-one solutions
  • <T> what we also share is a functional style Makes a difference MacLennan said: distinguish Nature of data is often values. To ignore them leads to conceptional errors. Complementary concept handle them properly
  • <T> MacLennan teaches us: Values are abstractions (universals, concepts) Values are never created or destroyed Values wont change Values are referentially transparent 2 Instances are not distinguishable So, you can share them Why not model that in software?
  • <CH> Date Time Rectangle
  • <CH> why is this a value? Output text should not change after creation literal representation really useful Concise and readable at a glance, easily understandable with all details and structure no magic practical, tool support, living code test code easy completer works fine
  • <T>so, what is a ComplexValue? Values in Values create once – never change any content No cyclic structures Concrete, finite, complete
  • <T> Can build class hierarchies same capabilities like a regular object
  • <T> we want tool support ´for modeling specify attributes and generate Model exploration and model changing is easy
  • <T> where we also can find values Configurations: move specifics from code into declarations excellent for the setup of modules and systems all benefits of normal source code
  • <T> we dont know, why xml strings should live In an Image Not referencable
  • <T>Adequate There are Values – why use Objects? Simple/Reliable Dont care No side effects, No cycles, No illegal Values <CH>Pretty Readable at a glance Concise and Understandable Practical Print and transportable Supported by tools (references, refactoring, formatter, highlighter) Trivial
  • Read the Article!
  • Legal ways to create a value
  • Complex Values

    1. 1. specify. simplify. explore. with ComplexValues <ul><li>counseling developer Thomas J. Schrader </li></ul><ul><li>Smalltalked Visuals GmbH Christian Haider </li></ul>
    2. 2. data workflows fragile systems complicated maintenance difficult ? something missing in conventional OO
    3. 3. Values - functional style makes a difference „ values | objects“ ! [MacLennan, 1982]
    4. 4. Value is abstract concept 42 abstraction no lifecycle stateless context-free
    5. 5. there are Standard Values <ul><li>Immediates </li></ul><ul><li>SmallInteger 42 , Character $a </li></ul><ul><li>Literal </li></ul><ul><li>Float 13.5 , Symbol #none </li></ul><ul><li>String 'abc' , Array #(1 'xyz' #one) </li></ul><ul><li>Value like </li></ul><ul><li>Point [email_address] , Association #abc -> 42 </li></ul><ul><li>ColorValue (ColorValue red: 1 green: 0 blue: 0) </li></ul>
    6. 6. a complex Value <ul><li>ChartText </li></ul><ul><li>style: ( Textstyle </li></ul><ul><li>color: ( CmykColor </li></ul><ul><li>cyan: 1 </li></ul><ul><li>magenta: 0.3 </li></ul><ul><li>yellow: 0 </li></ul><ul><li>black: 0.3) </li></ul><ul><li>font: #{Helvetica} </li></ul><ul><li>size: 12 ) </li></ul><ul><li>string: 'This is a text' </li></ul><ul><li>position: 5 @ 10 </li></ul>
    7. 7. a complex Value specified <ul><li>ChartText </li></ul><ul><li>style: ( Textstyle ..) </li></ul><ul><li>string: 'This is a text' </li></ul><ul><li>position: 5 @ 10 </li></ul>ChartText class>>localSpecification <constant: #style class: #{Textstyle} > <constant: #string class: #{String} > <optional: #position class: #{Point} default: '0@0' > <optional: #kerning class: #{Number} default: '0' >
    8. 8. ComplexValue is immutable composite Text string: 'ComplexValue...' style: (Textstyle font: #{Helvetica} size: 60) top down tree
    9. 9. ComplexValues are real objects but without identity Value = behavior + content same class & content = same Value
    10. 10. ComplexValue is generated from a specification just one specification per Value AValue class>>localSpecification
    11. 11. Interface 42.13 200 true 'abc ' 16:30 1.9.2009 16:30 1.9.2009 #(13 ' xyz ' nil false 16:30) Struct{ id: ' djia.ind ' type: ' close ' date: ' 20090101 ' adj: ' yes ' sync: 0} Requestor Trade time: <Time> value: <Number> volume: <Integer> settled: <Boolean> Trade time: 16:30 value: 42.13 volume: 200 settled: true Request id: ' djia.ind ' date: 1.1.2009 type: #close adjusted: true
    12. 12. System Interface Files Graphics Database C calls Internet Inside Media
    13. 13. Module Interfaces
    14. 14. Configuration <ul><li>#(#{UI.FullSpec} </li></ul><ul><li>#window: </li></ul><ul><li>#(#{UI.WindowSpec} </li></ul><ul><li>#label: #(#{Kernel.UserMessage} </li></ul><ul><li> #key: #UnlabeledCanvas …) </li></ul><ul><li>#bounds: #(#{Graphics.Rectangle} …) ) </li></ul><ul><li>#component: </li></ul><ul><li>#(#{UI.SpecCollection} </li></ul><ul><li>#collection: #( </li></ul><ul><li> #(#{UI.TextEditorSpec} </li></ul><ul><li> #layout: #(#{Graphics.LayoutFrame} … ) </li></ul><ul><li> #name: #textEditor </li></ul><ul><li> #model: #textHolder </li></ul><ul><li> #isReadOnly: true </li></ul><ul><li> #tabRequiresControl: true ) ) ) ) </li></ul>FullSpec window: ( WindowSpec label: ( UserMessage key: #UnlabeledCanvas …) bounds: ( Rectangle …)) component: ( SpecCollection collection: ( Array with: ( TextEditorSpec layout: ( LayoutFrame …) name: #textEditor model: #textHolder isReadOnly: true tabRequiresControl: true )))
    15. 15. VW Setting <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><settings domain = &quot;VisualWorksSettings&quot; > </li></ul><ul><li><setting> </li></ul><ul><li><id> </li></ul><ul><li><key> tools </key> </li></ul><ul><li><key> browser </key> </li></ul><ul><li><key> defaultBrowserType </key> </li></ul><ul><li></id> </li></ul><ul><li><state> </li></ul><ul><li><choice-key> Package </choice-key> </li></ul><ul><li></state> </li></ul><ul><li></setting> </li></ul><ul><li></settings> </li></ul>Settings domain: 'VisualWorksSettings' setting: ( Id with: #tools with: #browser with: #defaultBrowserType ) state: ( ChoiceKey value: 'Package' )
    16. 16. Why we like Values <ul><li>adequate </li></ul><ul><li>simple and reliable </li></ul><ul><li>pretty </li></ul><ul><li>practical </li></ul>
    17. 17. Thank you! Questions?
    18. 18. References <ul><li>Store </li></ul><ul><li>{Values Development} </li></ul><ul><li>Cincom Public Store </li></ul><ul><li>Technical Article </li></ul><ul><li>“ Complex Values In Smalltalk”, ESUG 09 </li></ul><ul><li>Contact </li></ul><ul><li>[email_address] </li></ul><ul><li>[email_address] </li></ul>
    19. 19. Defining a Value <ul><li>localSpecification </li></ul><ul><li><constant: #constant class: #{Symbol} > </li></ul><ul><li><optional: #optional class: #{Symbol} default: '#a' > </li></ul><ul><li><sequence: #array > </li></ul><ul><li><map: #dictionary > </li></ul>
    20. 20. Constructor <ul><li>constant: const optional: opt array: arr dictionary: dict </li></ul><ul><li>| inst | </li></ul><ul><li>inst := self new. </li></ul><ul><li>inst </li></ul><ul><li>initializeConstant: const </li></ul><ul><li>optional: opt </li></ul><ul><li>array: arr </li></ul><ul><li>dictionary: dict . </li></ul><ul><li>^ inst </li></ul>
    21. 21. Optional Constructors <ul><li>constant: const </li></ul><ul><li>| inst | </li></ul><ul><li>inst := self new. </li></ul><ul><li>inst initializeConstant: const optional: nil array: nil dictionary: nil . </li></ul><ul><li>^ inst </li></ul><ul><li>constant: const optional: opt (…) </li></ul><ul><li>constant: const optional: opt array: arr (…) </li></ul><ul><li>constant: const optional: opt dictionary: dict (…) </li></ul><ul><li>constant: const array: arr (…) </li></ul><ul><li>constant: const array: arr dictionary: dict (…) </li></ul><ul><li>constant: const dictionary: dict (…) </li></ul>
    22. 22. Initializer <ul><li>initializeConstant: const optional: opt array: arr dictionary: dict </li></ul><ul><li>constant := const . </li></ul><ul><li>( opt notNil and: [self optional ~= opt ]) ifTrue: [ </li></ul><ul><li>optional := opt ]. </li></ul><ul><li>( arr notNil and: [ arr notEmpty]) ifTrue: [ </li></ul><ul><li>array := ( Array withAll: arr ) beImmutable]. </li></ul><ul><li>( dict notNil and: [ dict notEmpty]) ifTrue: [ </li></ul><ul><li>| od | </li></ul><ul><li>od := OrderedDictionary new. </li></ul><ul><li>dict keysAndValuesDo: [: key : value | od at: key put: value ]. </li></ul><ul><li>dictionary := od beImmutable]. </li></ul><ul><li>self beImmutable </li></ul>
    23. 23. Accessors <ul><li>constant </li></ul><ul><li>&quot;<Symbol>&quot; </li></ul><ul><li>^ constant </li></ul><ul><li>optional </li></ul><ul><li>&quot;<Symbol>&quot; </li></ul><ul><li>^ optional ifNil: [ #a ] </li></ul><ul><li>array </li></ul><ul><li>&quot;<Array>&quot; </li></ul><ul><li>^ array ifNil: [ #() ] </li></ul><ul><li>dictionary </li></ul><ul><li>&quot;<Dictionary>&quot; </li></ul><ul><li>^ dictionary ifNil: [ </li></ul><ul><li>Dictionary new beImmutable] </li></ul>
    24. 24. Printer <ul><li>printvalueWith: printer </li></ul><ul><li>| args | </li></ul><ul><li>args := OrderedCollection new. </li></ul><ul><li>args add: ( printer constant: 'constant' value: self constant). </li></ul><ul><li>args add: ( printer optional: 'optional' value: optional ). </li></ul><ul><li>args add: ( printer array: 'array' value: self array). </li></ul><ul><li>args add: ( printer dictionary: 'dictionary' value: self dictionary). </li></ul><ul><li>^ printer printvalue: self arguments: args </li></ul>
    25. 25. Opentalk Service <ul><li>passInstVars </li></ul><ul><li>&quot;for OpenTalk StSt&quot; </li></ul><ul><li>^ #(#default #default #default #value) </li></ul>