Replies: 2 comments 3 replies
-
Hey @LRossman, Looks like a worthwhile refactoring effort. @cbuahin and I are both interested in seeing what you have done. I think it definitely has a place in the project. Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have attached the refactored dwflow.c file so people can view it and comment. It's been written to comply with the draft SWMM 5 Style Guide posted in Discussion #130. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A hallmark of readable and maintainable code are functions that are small and do one thing (see Chapter 3 in the classic "Clean Code" book by Robert C. Martin). I think SWMM mostly adheres to these concepts with some exceptions. One of these is the
dwflow_findConduitFlow
function in dwflow.c. It evaluates the combined continuity/momentum equation to find a new conduit flow estimate under dynamic wave flow routing and consists of 236 lines of code. I recently refactored this function to look as follows:This revised code calls a number of new subordinate functions, containing code off-loaded from the original function, that make it easier to follow what
dwflow_findConduitFlow
is actually doing.Testing shows that the refactored file produces the same results as the original. One concern is if the additional function calls and use of the TData struct to share intermediate results between them would add significant execution time. I ran timing tests on two rather large data sets. The results are shown in the table below:
It appears that the refactored function doesn't result in any significant additional execution time. I'd be interested to know if people think this code revision (made only for readability and maintainability) is worth inserting into the project.
Beta Was this translation helpful? Give feedback.
All reactions