
Nick Coghlan wrote:
So is the "inline vs given statement" question really any more scary than the "should I factor this out into a function" question?
Especially since the factored-out functions could be written either before or after the place where they're used, maybe not even on the same page, and maybe not even in the same source file...
I expect the style guidelines will boil down to: ... - as a general rule, given statements should be used for code that could reasonably be factored out into its own function
Also perhaps: - If you're assigning some things to local names and then using them just once in a subsequent expression, consider using a 'given' statement. I would also be inclined to add that if you're using the 'given' style in a particular function, you should use it *consistently*. For instance, consider the earlier example
result = flange(thingie) given: thingie = doohickie(majiger) given: part_a = source / 2 part_b = source ** 2 majiger = blender(part_a, part_b)
Why have we used the 'given' style for 'thingie' and 'majiger', but fallen back on the sequential style for 'part_a' and 'part_b'? It would be more consistent to write it as result = flange(thingie) given: thingie = doohickie(majiger) given: majiger = blender(part_a, part_b) given: part_a = source / 2 part_b = source ** 2 The flow of data from one place to another within the function is now very clear: source -----> part_a -----> blender --> doohickie --> flange | | \--> part_b --/ -- Greg