From: spiralofhope Date: 2011-03-27T09:33:43+09:00 Subject: Scripting style (was: Clearer errors in 1.9's minitest) On Sun, 27 Mar 2011 05:12:51 +0900 Ryan Davis wrote: > You don't actually write your code that way, do you? More or less. I'm assuming you're commenting on my general style. Below would be a full working bit of code. It's rather pointlessly simple but it demonstrates my "way". --- require 'minitest/autorun' class Whatever def foo( string ) return string + '!' end end class Test_Whatever < MiniTest::Unit::TestCase def setup() @o = Whatever.new end def test_foo() assert_equal( ( 'yay!' ), ( @o.foo( 'yay' ) ), ) end end --- I've taken extreme measures to make my code more readable. While I have exceptionally lucid times, I often have a _very_ hard time "fitting a program into my head". The real problem arises when I create magical code on one day and then on some other day I am completely unable to comprehend it. To help, I've been - Breaking my problems down into sometimes embarrassingly-small pieces - .. Each with its own test - .. Usually with somewhat redundant comments. - I've also thrown away regular alignment conventions. - Ignoring performance improvements, preferring clearer and even redundant code. (lots of brackets, stuff on separate lines, trailing commas, etc) - Using a very small subset of Ruby's functionality. Doing things with brute force and which are far less pretty than possible. In some cases I might even coerce code into something monstrous like this: def test_foo() assert_equal( ( 'yay!' ), ( @o.foo( 'yay' ) ), ) end The difference to me is that a bunch of programming that initially took me a very long time has now taken me a very short time to rewrite from scratch. Think years to weeks. The end result is vastly superior in every way to me. Faster, clearer, fully tested. Most importantly I'm enjoying myself! I know that this means that if I ever manage to function with regular style conventions I will be forced to re-rewrite everything to follow them. If it came to that, I would be pleased to do it.. I love that kind of grunt work. =) I know I'm learning bad habits, my code will be "unreadable" to others, I may not be able to read the source of others very well, and there are probably lots of other issues.. but I needed a new way to approach programming. It's either that or I just give up. -- http://spiralofhope.com