I want to use some C codes from a function, however, the function has 300+ lines of code and 20 variables, which make me really headache to deal with.
I'm just wondering whether there's such a tool that can separate(refactor) small functions from a large function automatically. Then it will save me a lot of time to deal with long functions like that.
(I don't think it's a very hard thing because this tool only need to analysis the position where a Variable was defined first time, and the position where a Variable was used at last, then give me some suggestion about where to split..)
The problem is that it is difficult for a computer to know what the purpose of a function is. If it so happens that all 20 of the variables and 300 lines of code are all needed for a task and it does not make sense to split that task up, then it is a good function. It is a little hard to imagine, but still.
Don't break something up just because it is long. Break it up because it makes sense to do so. Keep functions performing only one thing. As of now computers are not smart enough to figure out the purpose of a function and especially not smart enough to decide what are sub-sections of the function that could reasonably be split out.