An Online Source Code Control Flow Filter
Clean code guidelines recommend keeping functions short, because long functions are difficult to understand and maintain. However, there is legacy code out there were functions span across hundreds, or even thousands of lines.
There is now way someone can keep so many lines of code in their mind. By scrolling through such a function, we forget what was at the beginning before reaching the end.
We’ve seen that filtering on control flow, that is hiding the lines of code that don’t contain control flow keywords such as if
, else
, for
, try
, and so on allowed to show the structure of the function, and took much less lines of code to read.
In order for you to analyse your code with this technique, you will find on Fluent C++ an online program that allows to filter your source code on control flow keywords.
To run the filter, paste your code in the Code tab that appears on the webpage and click ‘Run’. The filtered view of your code will appear below.
The default list of keywords is the following:
- if
- else
- for
- while
- do
- switch
- case
- try
- catch
If you’d like to change it you can edit it in the Keywords tab.
I hope this control flow filter will be useful to you. If you have any piece of feedback, please let me know!
The technique of filtering on control flow to understand a piece of code is taken from my book, The Legacy Code Programmer’s Toolbox.
For more details about why such a filter is useful, go here. For how to implement a filter in C++ go here and here.
Don't want to miss out ? Follow:   Share this post!