From: Nick Klauer Date: 2011-03-27T10:55:21+09:00 Subject: Re: Scripting style (was: Clearer errors in 1.9's minitest) --00032555f6c674dc5f049f6d1e64 Content-Type: text/plain; charset=UTF-8 > > 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. That's fine, but then what is the point of this post? Are you asking for help with integrating yourself into more of the semantics of the Ruby Style way of coding? I guess I'm missing something. -Nick Klauer On Sat, Mar 26, 2011 at 19:33, spiralofhope wrote: > 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 > > > --00032555f6c674dc5f049f6d1e64--