Wednesday, 11 November 2015

How to try to kill the Playground

Suggested options:

GLMSystemWindow allInstancesDo: [ :w | w label = 'Playground' ifTrue: [ w delete ] ]

[ (World submorphsDo: [:m | (m isKindOf: GLMSystemWindow) ifTrue: [ m delete] )


Tuesday, 10 November 2015

MVC in a few simple words

Model  - the data structures

View - displaying the data structures to the user

Controller - capturing inputs from the user, to update the model, and thence the view

Sunday, 8 November 2015

Implicit and explicit returns from methods

A Smalltalk method will return the receiver, by default.

So, if you want it to return any other value, you must say so explicitly.

e.g.
isSomething
self  booleanStateCheck

returns self

isSomething
^ self booleanStateCheck

returns aBoolean (in this case)

Saturday, 7 November 2015

SUnit considered as a Design-By-Contract tool

SUnit can be used as a tool for doing Design By Contract.  SUnit is really good at testing existing code, but it was originally built (by Kent Beck) as a tool to support TestDrivenDevelopment.

Writing the tests before you write the method bodies is what Design By Contract (DBC) is.  In DBC and its associated Eiffel programming language,  the contracts are part of the language and part of the methods themselves.

In DBC, Items always receive state that is in assured condition - it meets pre-conditions.  Which you can define as contracts.  After the method is finished with the data, it is intended to meet the defined post-conditions,  i.e. the method does consistency checking on its data, based on its own specifically defined rules, once it has completed.  This helps ensure that the data is correct before any future method has to deal with it.  And so the data has a much better chance of meeting the next pre-condition it meets.

All the methods in Eiffel are intended to meet pre-conditions, essentiually by receiving post-conditioned from other methods and objects.  i.e. it would have been checked for consistency with its own rules from what results could be provided, before it was passed to the next object.

So if you think of SUnit as a tool for doing design contracts :

TestCase setup provides preconditioned data (tho' test data)

Tests are run on the output of the methods' work.  These tests act as postconditions.

In Eiffel, pre-and post conditions were dealt with as
    assertions of a positive statement
       or as
    the NOT of a positive case.

In SUnit, we
    assert: the positive cases,
        and
   deny: the negative cases.

Eiffel also had invariants.  I kind of think of the Class-level tests in SUnit as its equivalent of invariants..  (Or maybe the analogy is with TestCase's teardown method, where it tidies everything up after itself, ready for the next run of the tests).

SUnit also has assert:description: and deny:description: keyword messages.  The description parameter provides the Transcript with a message when individual tests pass or fail.


Friday, 6 November 2015

SmallCouchDb - a Small(talk) Couch API DB

SmallCouch - Smalltalk API to Couch DB


Why only interface from Smalltalk *to* Couch?

Why not provide a Smalltalk DB that receives and understands CouchDB API calls?

And provide a Couch API db on the other side of the API, as well?

It would mean native interoperability with PouchDB

Perhaps also with Couchbase Mobile?

It would allow apps to stay with the Smalltalk stack until they swapped it out to something with bigger capacity.  Unless they never wanted to.

Imagine SmallCouchDB on GLASS or Gemstone as a scaling option

And always the ability to interoperate with the high availability NOSQL world.

Why not on even terms?

Is Erlang that much faster than Smalltalk?

Outward looking, and also able to provide the facilities within the stack.

Couch is just a big dictionary, that tells its peers about what's in the Dictionary.

Often it holds object trees as the Value.  Often it just holds documents, with a version number.

We can do that.

Thursday, 5 November 2015

Creating a three-pane Window, using SystemWindow and LayoutFrame

window := SystemWindow labelled: 'Layout'.

redMorph := Morph new.
window 
 addMorph: redMorph
 fullFrame: (LayoutFrame 
  fractions: (0@0 corner: 1@1)   
        "in fractions: the numbers represent a value from 0 to 1  
          i.e. a decimal fraction, of 100% of the parent window's size"
  offsets: (100@0 corner: 0@50 negated)).
        "in offsets: the numerics represent absolute values, in pixels"
redMorph color: Color red.
        "there is a set of named colors.  Color objects can also be specified as RGB values
          r:g:b:  Each parameter is a number between 0 and 1.0 "

Two morphs side-by-side in a proportional layout will automagically have a grabbable, movable pane edge.

greenMorph := Morph new.
window 
 addMorph: greenMorph
 fullFrame: (LayoutFrame 
  fractions: (0@0 corner: 0@1)
  offsets: (0@0 corner: 100@50 negated)).
greenMorph color: Color green.

yellowMorph := Morph new.
window 
 addMorph: yellowMorph
 fullFrame: (LayoutFrame 
  fractions: (0@1 corner: 1@1)
  offsets: (0@50 negated corner: 0@0)).
yellowMorph color: Color yellow.

window openInWorld.  "sent to the superclass"

Wednesday, 4 November 2015

How to get a font file from a github repo downloaded by Pharo - code snippet


How to get a font file from a github repo downloaded by Pharo

wd := FileSystem disk workingDirectory .
master := wd / 'github-cache/kilon/ChronosManager/master'.
fontPath := (master children at: 1)/'fonts/Cubellan.ttf'.
fontPath:= (fontPath asString  substrings:'@ ') at: 2.
Add Comment

by Dimitris Chloupis