Jeff H's Profile
Reputation: 112 Stalwart
- Active Members
- Active Posts:
- 309 (0.17 per day)
- 30-January 11
- Profile Views:
- Last Active:
- Dec 09 2015 03:07 PM
- Dream Kudos:
Posts I've Made
Posted 13 Aug 2014A little late but something not mentioned or to bring more attention to about TakeABreath example is its readability.
Anyone person can only keep about 4 to 7 ideas or thoughts in their mind at one time.
Breaking up methods into smaller parts that are not easily understood probably isn't any better.
When you look at TakeABreath method it is easy to see that there 3 main parts inhale, process, exhale.
There might be complex computations happening but, if all I need to know is call TakeABreath when a breath is needed that's it. If something changes and need to know what it does it is easily understood at a high level and do not require unnecessary information or noise to understand the lower level ideas.
For example if need change the way oxygen is brought in I do not need to know about processing oxygen or exhaling to see to what happens when inhaling, or to put it another way it does not require having to understand, filter out, etc.. to see inhale implementation.
Hopefully it makes sense but can you see how TakeABreath and its functions is close or organized to the way people naturally read or organize an idea? You appreciate code like that when scrolling up constantly because a method has 34 different local variables and it is 5th time you had to look because you can't remember what this one variable type is and that leads to some other class that constructor is just as bad.
It has to happen somewhere but making code readable and broken up in way that makes it easy read is a very helpful skill.
Not sure what your doing but might lend itself to CQS design.
Not CQRS and the terminology has nothing to do with relational database.
Quick overview is every method is a query or command.
A query has NO side effects and returns a value. This could be value in private field etc..
A command returns void and performs an action or changes state.
A command can call a query but a query can not call a command.
Also you can use functional programming concept of a "maybe" or in F# a maybe.
Basically a collection constrained to having either 0 or 1 items instead of settings variables to null and null checks
- Member Title:
- D.I.C Regular
- Age Unknown
- Birthday Unknown