Programming_styles
I have come to some conclusions. One thing that triggered that is ‘Wez Furlong’.. the creator and maintainer of Wezterm.
He talks alot about what something “should be”. By that I understand that he has interaction defined.
You can really mess code up by giving a method or class to wide of a responsibility.
It’s very easy to do if you program as you think. You add.. you get into a problem.. you change something there.. it works.
But if you would think it all through beforehand.. try to isolate the responsibilities and the calls.. your life would become so much easier.
Let’s say I want a String in Ruby to be Enumerable.
It would make sense to make an EnumerableString class.. and not just monkey-patch on some method to String.
What would that class rule over? What would it NOT rule over?
Let’s say I would need some “back_to_string”-method.. should the Object still be EnumerableString? Or should it now be String?
so: def to_s = (String.new self.join)
.. is that a good idea?
Maybe I come up with the idea to use the EnumerableString to partition vowels and consonants.
Would it still be an EnumerableString? Or would I have to create a new box of opportunities?
Is .upcase really the responsibility of EnumerableString?
What I noticed from Wez.. is that he plans his code. When someone wants a feature.. he never gets painted into a corner. I respect him for that.. and I want to code like that myself (looong way to go :))