javascript

repeatable and concious method of coding

I have recently been thinking a lot about the mechanism of tdd whilst pairing and have found that having a definite, repeatable method can really help the process both in terms of making progress with the code and in introducing an efficient method to others . It can be frustrating for both people in the pair if they have different ways of doing things. Aggreeing on a standard sequence of actions may help to reduce the time it takes to get to know someones style and thus reduce the times when as a navigator you are sitting there giving keystroke instructions .
So far my method is based on behavior driven design ideas where you have three parts to the test : given (that the system is in a defined state ) , when (something happens, ie the method under test is executed ) , then (what are we expecting to happen?)

I have found that (in true bdd fashion ) starting at the then can be a very efficient way of working because the ide works well with you by providing context smart assists .
Also it makes you concentrate on what the hell you are testing right from the start rather than getting lost in lots of setup .
It also works well with the name of the test method – the then should be a natural counter part to whatever statement the name of the method makes .
Finally It helps to make sure that the method is not too complex to set up and find this out sooner rather than later – after setting up lots of stuff . In conjunction with this you may discover that you already have many of the required setup available . I like to make most of my objects member variables as it cuts down on code int the test method (especially with long class names) this also works well with mockito as you declare all mocks with an annotation as members .
Which brings me to an associated pint – mockito is s great tool when doing this as it lends itself to writing the then part first with the verify paradigm . Infact it Was because we were using mockito that I came up with this methodology !
I will try to write this up as a more detailed article in the future with some examples .

  • Share/Bookmark

browsers
javascript

Comments (0)

Permalink

Javascript Javascript JavaScript JavaSCRIPT!!

Just been shown how to do the old hiding and showing trick with javascript so that when javascript is turned off the thing shows by default.

simple trick – have a stylesheet that is itself loaded by javascript in the on load method of the dom.

Then you can override a class which has say “display:block” in a base css file with “display:none” in the JS loaded one.

After that you simply do the normal toggling.

A nice adaptation is to change a class name you use :

    if (className.indexOf('js-hider') > -1) {
        document.getElementById('element-to-hide').className = className.replace('js-hider', 'js-shower');
        console.log(document.getElementById('element-to-hide').className);
        theLink.innerHTML="Hide thing";
    } else {
        document.getElementById('element-to-hide').className = className.replace('js-shower', 'js-hider');
        theLink.innerHTML = 'Show thing';
    }
  • Share/Bookmark

code
javascript
web

Comments (0)

Permalink