12-05-2022 09:13 AM
Quite often I come across code written by someone else who is long gone and it is my task to understand what is going on under the hood. Oftentimes no comments, sometimes with, but even then they can sometimes be cryptic.
I suspect most of us know the popular tools:
I want to pick your brains!
What tricks have you learned over the years to better facilitate this task? 🤔
12-05-2022 09:42 AM
Many times, the code is awful. In such cases usually it's better to throw it away and start over. Trying to understand something that's demented twisted mess is a waste of time.
12-05-2022 09:44 AM
Some want to make our lives easier, some don't. In the case of the latter, I have seen some code in an absolute spaghetti mess, without any SubVIs but it works a charm, it took me a month to thoroughly understand the logic behind the code to recreate it in a better-structured way.
A common issue in programming is that some would go to vast lengths with convoluted logic to achieve a simple piece of code which you would not guess until you understand close to everything.
My technique is to start from the simpler part of the code so that I still have some patience and I have some satisfaction that I am making progress.
12-05-2022 09:47 AM
Yep, you got me there. I've not used anything other than the trusty trio. . .
I look forward to seeing other people's ideas & techniques.
Great idea to ask!👌
12-05-2022 09:50 AM
Over time, after seeing a lot of awful codes, you will be able to quickly guess what the programmer had in mind and you would save time but there is always a particular technique (worse) that you've not come across that will still take your time to understand.
12-05-2022 10:22 AM
@paul_cardinale ha scritto:
Many times, the code is awful. In such cases usually it's better to throw it away and start over. Trying to understand something that's demented twisted mess is a waste of time.
In principle I agree. The problem is that it's often very difficult to get good specifications. Many times, all you get is the old software and a verbal description (or equivalently a handful of text lines). So, in any case, you are forced to understand the old software before starting to re-code.
What I did in some cases while analyzing the old code is to try improving the readability with no functional modifications (or with very small, very careful changes), essentially just repositioning the various elements in a more sensible way. This is time consuming, of course, but may render the code more digestible.
12-05-2022 10:35 AM
Deleting (!) comments and labels might be surprisingly useful. In LabVIEW, this even extends to VI Icons. If you need tools to understand the code, it is probably in a state where the written documentation is outdated, misleading or plain wrong.
12-05-2022 11:16 AM
@LLindenbauer wrote:
Deleting (!) comments and labels might be surprisingly useful. In LabVIEW, this even extends to VI Icons. If you need tools to understand the code, it is probably in a state where the written documentation is outdated, misleading or plain wrong.
The only thing worse than no documentation is wrong documentation.
When I inherit "ancient" code, I refactor to understand it. Breaking things into subVIs, improving that portion (subVIs help a lot with regression testing). Of course, make sure this code is locked away in a Source Code Control before doing anything to it.
12-05-2022 11:52 AM
Ah yes, block diagram cleanup can bring huge gains! Thanks for the reminder.
But not auto block diagram cleanup (in my experience).
12-05-2022 12:07 PM
@B_Strange wrote:
Ah yes, block diagram cleanup can bring huge gains! Thanks for the reminder.
But not auto block diagram cleanup (in my experience).
If the cleanup tool improves the look of your block diagram, you need to seriously rethink your block diagram design. 😄