Thursday, 14 August 2014

More efficient

I understand a little more about functions and generally about code efficiency.
I have written more efficient code to create a radio selector. Instead of three separate functions to draw the colours of the rectanges, there is just one function into which I pass a variable color. This then draws the box the appropriate color.

Correct use of functions, passing data in and out, is key to writing efficient code.

Lots of learn.

The more efficient code is here:
http://bl.ocks.org/brennanpincardiff/8e56ef6f51564955aeea


I have read the code and realised that it's possible to have it more efficient again.
I divided it into two functions - change and transition. It's possible to do it all in one function.

I can also remove the timeout functions.

Even more simple code here: http://bl.ocks.org/brennanpincardiff/d07d52f10900c14844b5

Still learning!!!!

No comments:

Post a Comment