6 ms·
Here is where "first write good code" applies, at the design level. This function is begging to be two separate, composable functions that each only do one thi
by squidbidness 11y ago
Here is where "first write good code" applies, at the design level. This function is begging to be two separate, composable functions that each only do one thing.
reverse(addToEach(input_list, 1))
- Kiro 11y agoBut what calls "reverse(addToEach(input_list, 1))" if not another function?
- ajuc 11y agoHopefully a function that can be corectly named.
- Kiro 11y agoWhat do you think is a better name? reverseListAndAddOneToEachElement is describing the function but I agree it feels ugly.
- IanCal 11y agoFor this level of grouping, I'd probably prefer something related to the actual domain. def convertDF4ToMX6(data): # The MX6 format is read as a stack rather # than a queue, and requires data to be 1 # indexed rather than 0 indexed like DF4 # link_to_MX6 format spec 1.3.2 (v5) # link_to_DF6 format spec 1.2.0 (v1) Why are we reversing and adding one? What's the reason we need to do that so much that we're combining those two functions into a single call? This would then mean the calling points might look something like mx6_data = convertDF4ToMX6(loadDF4(file)) return processMX6(mx6_data) rather than mx6_data = reverseAndAddOneToEachElement(loadDF4(file)) return processMX6(mx6_data) Rather contrived, I know.
- deleted 11y ago[deleted]