[Pharo-project] Do you know any code that can be better understood with its test?
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior. Do you have any idea? -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
How about this: -- takes a string and does a global replacement on substrings.. gsub: aString "from email correspondence with Nicolas Cellier " | newString | newString:= self parameters associations inject: aString into: [:subst :assoc | assoc key asRegex copy: subst replacingMatchesWith: assoc value]. ^newString testBasicGsub | string result| "aDict at: 'test' put: 'testreplaced'; at: 'hello' put: 'hello'; at: 'hello2' put: 'hello2replaced'." string:='test'. result:= FiconabGsub replace: string using: aDict. self assert: result='testreplaced'. string:='test test'. result:= FiconabGsub replace: string using: aDict. self assert: result='testreplaced testreplaced'. S. On 13 Oct, 2012, at 10:47 PM, Damien Cassou <damien.cassou@gmail.com> wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
bitShift: look at the tests ((1 bitShift: 100) bitShift: -100) = 1 On Oct 13, 2012, at 4:47 PM, Damien Cassou wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
On 13 October 2012 15:47, Damien Cassou <damien.cassou@gmail.com> wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
http://ss3.gemstone.com/ss/Control/ has tests for delimited dynamic variables. The idea's not terribly complicated - close over a variable and use resumable exceptions to refer to it or change it - but if you don't have that in-a-nutshell idea in your head it can look a bit strange. But the tests in ControlTests' DelimitedDynamicVariableTest show quite clearly how dynamic binding works. (The delimited part probably won't make a lot of sense until one's managed to wrap one's head around control operators - shift, in this case - so the nice interaction between the delimited continuations and the delimited dynamic variables might be lost on a newbie.) frank
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
Frank I was asked to do a keynote to master, phd student and other and I would like to show them that with the right tool we can do some powerful abstractions. I'm thinking showing them thisContext use for haltIf on:fork: example do you have idea? Should I look (I will ;)) look at Control and DynamicVariable? Do you have other idea? Stef On Oct 13, 2012, at 5:54 PM, Frank Shearar wrote:
On 13 October 2012 15:47, Damien Cassou <damien.cassou@gmail.com> wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
http://ss3.gemstone.com/ss/Control/ has tests for delimited dynamic variables. The idea's not terribly complicated - close over a variable and use resumable exceptions to refer to it or change it - but if you don't have that in-a-nutshell idea in your head it can look a bit strange. But the tests in ControlTests' DelimitedDynamicVariableTest show quite clearly how dynamic binding works.
(The delimited part probably won't make a lot of sense until one's managed to wrap one's head around control operators - shift, in this case - so the nice interaction between the delimited continuations and the delimited dynamic variables might be lost on a newbie.)
frank
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
On 13 October 2012 17:05, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Frank
I was asked to do a keynote to master, phd student and other and I would like to show them that with the right tool we can do some powerful abstractions.
I'm thinking showing them thisContext use for haltIf on:fork: example
I don't see a #haltIf: in my Pharo 2.0 image (but it's well out of date, and I'm still waiting for the update to finish) but I imagine it would evaluate a block and when that block returns true, uses thisContext sender (sender ...) to drop you into the right context?
do you have idea? Should I look (I will ;)) look at Control and DynamicVariable? Do you have other idea?
I think thisContext is an excellent jumping board into a great many things. http://www.mirandabanda.org/cogblog/2009/01/14/under-cover-contexts-and-the-... has a lovely paragraph: "Contexts are fabulous weapons, even better programming building blocks, and horribly expensive. How do I love contexts? Let me count the ways⦠Contexts mean Smalltalk has had edit-and-continue debugging since the 1970â²s. Contexts allow the implemention of an exception system with no additional support from the virtual machine. Contexts allow the implemention of dynamic binding, co-routines, tail-recursion-elimination and backtracking with no additional support from the virtual machine. Contexts enable process persistence and migration. Contexts allow implementation of continuations (full, delimited/partial or otherwise) without additional VM support (and hence the Seaside web framework). Contexts are consistent (consistent) with the rest of the âobjects all the way downâ system, providing activations as first-class objects. Because theyâre there." frank
Stef
On Oct 13, 2012, at 5:54 PM, Frank Shearar wrote:
On 13 October 2012 15:47, Damien Cassou <damien.cassou@gmail.com> wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
http://ss3.gemstone.com/ss/Control/ has tests for delimited dynamic variables. The idea's not terribly complicated - close over a variable and use resumable exceptions to refer to it or change it - but if you don't have that in-a-nutshell idea in your head it can look a bit strange. But the tests in ControlTests' DelimitedDynamicVariableTest show quite clearly how dynamic binding works.
(The delimited part probably won't make a lot of sense until one's managed to wrap one's head around control operators - shift, in this case - so the nice interaction between the delimited continuations and the delimited dynamic variables might be lost on a newbie.)
frank
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
On Oct 15, 2012, at 7:25 PM, Frank Shearar wrote:
On 13 October 2012 17:05, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Frank
I was asked to do a keynote to master, phd student and other and I would like to show them that with the right tool we can do some powerful abstractions.
I'm thinking showing them thisContext use for haltIf on:fork: example
I don't see a #haltIf: in my Pharo 2.0 image (but it's well out of date, and I'm still waiting for the update to finish) but I imagine it would evaluate a block and when that block returns true, uses thisContext sender (sender ...) to drop you into the right context?
haltIf: condition â¦. haltIfCallChainContains: aSelector | cntxt | cntxt := thisContext. [cntxt sender isNil] whileFalse: [ cntxt := cntxt sender. (cntxt selector = aSelector) ifTrue: [self signal]].
do you have idea? Should I look (I will ;)) look at Control and DynamicVariable? Do you have other idea?
I think thisContext is an excellent jumping board into a great many things. http://www.mirandabanda.org/cogblog/2009/01/14/under-cover-contexts-and-the-... has a lovely paragraph:
"Contexts are fabulous weapons, even better programming building blocks, and horribly expensive. How do I love contexts? Let me count the waysâ¦
Contexts mean Smalltalk has had edit-and-continue debugging since the 1970â²s. Contexts allow the implemention of an exception system with no additional support from the virtual machine. Contexts allow the implemention of dynamic binding, co-routines, tail-recursion-elimination and backtracking with no additional support from the virtual machine. Contexts enable process persistence and migration. Contexts allow implementation of continuations (full, delimited/partial or otherwise) without additional VM support (and hence the Seaside web framework). Contexts are consistent (consistent) with the rest of the âobjects all the way downâ system, providing activations as first-class objects. Because theyâre there."
Yes I read that a while ago.
frank
Stef
On Oct 13, 2012, at 5:54 PM, Frank Shearar wrote:
On 13 October 2012 15:47, Damien Cassou <damien.cassou@gmail.com> wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
http://ss3.gemstone.com/ss/Control/ has tests for delimited dynamic variables. The idea's not terribly complicated - close over a variable and use resumable exceptions to refer to it or change it - but if you don't have that in-a-nutshell idea in your head it can look a bit strange. But the tests in ControlTests' DelimitedDynamicVariableTest show quite clearly how dynamic binding works.
(The delimited part probably won't make a lot of sense until one's managed to wrap one's head around control operators - shift, in this case - so the nice interaction between the delimited continuations and the delimited dynamic variables might be lost on a newbie.)
frank
-- Damien Cassou http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
On Sat, Oct 13, 2012 at 04:47:04PM +0200, Damien Cassou wrote:
I'm looking for a piece of code that is hard to understand by looking at the source code but which has unit tests that help understanding the behavior.
Do you have any idea?
Perhaps CommandShell and OSProcess. The tests show how these work from the point of view of expected behavior, so I think they may be easier to understand by starting with the tests. Dave
participants (5)
-
Damien Cassou -
David T. Lewis -
Frank Shearar -
mail list -
Stéphane Ducasse