Great job.

The executable examples makes me think of TDD, Test Driven Design. Anyone writes his tests before the code?

Tests can also be a kind of documentation. When you use TDD and BDD, the tests basically replaces the specifications and the requirements.

With the open source package managers it is sometimes possible to deliver test suites with the code. When you build a package you can automatically run the test suite. Failing tests can trigger an automatic bug report to the developers.

So, with the code you could also deliver tests. Tests you probably had to write anyway. They can act as a thorough functional specification of the code.

/Erling


On 2014-07-15 19:15, Joe Bogner wrote:
I neglected to paste into a clean session and sent the wrong version. This
version works as I expected.

Upon running it, you'll be able to access the functions and run the
examples like:

    'abc 123' -: deb ' abc     123 '
1

The helper function evaluates the last line in the block to create the
function

NB. creates and documents a function
NB. could be improved to split out example
NB. or automatically assert on the example
func=: 3 : 0
0!:0 > {: LF cut ][(y,'_doc')=: 0 : 0
)

func 'ltrim'
Removes left most space, if it exists
ex: 'abc' -: ltrim ' abc'
ltrim=: }.^:(' ' = {.)
)

func 'rtrim'
Removes right most space, if it exists
ex: 'abc' -: rtrim 'abc '
rtrim=: }:^:(' ' = {:)
)

func 'itrim'
Removes consecutive inner spaces
ex:  'abc 123' -: itrim 'abc     123'
itrim=: (#~ (0='  'E.]))
)

func 'deb'
Removes leading,trailing and consecutive spaces
ex:  'abc 123' -: deb ' abc     123 '
deb=: rtrim @: ltrim @: itrim
)



On Tue, Jul 15, 2014 at 11:46 AM, Joe Bogner <[email protected]> wrote:

Here's my version of a alternative, possibly more readable example. It's
likely excessive and unconventional:

First, I need a helper:


NB. creates and documents a function
NB. could be improved to split out example
NB. or automatically assert on the example
func=: 3 : 0
(0!:0 > {: LF cut (y,'_doc'))[(y,'_doc')=: 0 : 0
)

func 'ltrim'
Removes left most space, if it exists
ex: 'abc' -: ltrim ' abc'
ltrim=: }.^:(' ' = {.)
)

func 'rtrim'
Removes right most space, if it exists
ex: 'abc' -: rtrim 'abc '
rtrim=: }:^:(' ' = {:)
)

func 'itrim'
Removes consecutive inner spaces
ex:  'abc 123' -: itrim 'abc     123'
itrim=: (#~ (0='  'E.]))
)

func 'deb'
Removes leading,trailing and consecutive spaces
ex:  'abc 123' -: deb ' abc     123 '
deb=: rtrim @: ltrim @: itrim
)


You can then do things like:

    deb_doc

Removes leading,trailing and consecutive spaces

ex: 'abc 123' -: deb ' abc 123 '

deb=: rtrim @: ltrim @: itrim



It would be neat to also be able to have all the examples automatically
assert, but I'm not sure how to do that without sinking another few hours
(probably) into it



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to