I have finished reading "Functions" chapter from Uncle Bob's Clear code It was to ensure that the functions are low - actually and they should do the same thing only at the level of intangible here. Here is a function from an app that I am learning from Cocoa ).
- Go to (IBAction): (ID) sender {NSString * output = noil; If ([[NameInputField stringValue] is EqualToString: @ ""]] {output = @ "Please enter your name"; } Other {nssting * date = [[NSDT date] Description with calendar calendar format: @ "% A,% b% d" time zone: zero locale: [[NSUser Defaults standard user defaults] Dictionary Representation]]; Output = [NSString stringWithFormat: @ "Hello,% @! Today is% @.", [NameInputField stringValue], Date]; } [ResponseOutputField setStringValue: Output]; }
Actually, this function reads a name from a text field ( nameInputField
) and another text field ( responseOutputField
) I am thinking that a) if this function does 'one thing' to the abstract level and b) how to shorten it
I disagree that this function is at the right level. Based on the current input, core computation of work for output should work in any other function. This will make that calculation more qualified (since you do not need a text field, you can test the unit in isolation) and can be reusable as it contains less relevant materials as it is, Hard-wired for specific use and it is not reusable.
Likewise, how do you actually test without running the application?
Comments
Post a Comment