Hey folks.
I know it has been sort of mentioned before in this tread
But I think this is a bit of a different perspective on it.
I am still very new to all this and some stuff I am seeing/learning these days is still WAY ABOVE me and my understanding.
I have also seen this link/video which is very interesting too.
And I am about to go against all it says. But why not? ![]()
If you are new to it all, you don't understand the big picture and I know it is easy to fall into habits which can (or not) be bad for you in the future.
BTW, I am NO past experience with GIT backups and the like. All too new for me.
So, you are writing a function node to do something.
WHERE DO YOU START??
Now, before I get to the STRUCTURE of the code, how about a few ideas to help you track the version of the code?
A HUGE thing that I am starting to do when writing code is to add a Header with the date/time when it was written.
eg:
// 2025 11 15 1450
Year, month, date and time.
It isn't Rocket science but gee, it goes a long way to keeping track of the code.
Yes, my flows are littered with backups of function nodes as I am developing them.
So what? It isn't illegal.
You write the code with this Header and copy it to a spare part of the flow - backup.
Test it. It works. Great, improve it.
When you've done the improvements, edit the header with the new time and repeat.
The times don't have to be THAT ACCURATE, but they help you see which is which.
Why so many backups? I hear you ask.
Well - my take on it - you don't always know where you are going with the code.
You are TRYING things. Seeing if they work.
And you may be several layers down and find this path is a dead end.
You need to go back a few steps to get rid of the stuff you added when you went down this path.
Back to a Good working copy then start again.
Of course you need to delete all the dead end path nodes. Helps reduce the clutter.
Then you start a new line of thought.
And it may happen multiple times.
When all is working - FINALLY - you can delete all the old copies.
But WHEN you delete them depends on how confident (and good your testing is) at that point in time.
A lot of things may not have been considered and bite you later.
So keeping some older versions for a few .... days/weeks/...... may be a good idea.
Try to group things.
There's no exact method I'm going to say, but maybe this way:
All functions together at the top
All configurable constants / definitions next
Then the main execution flow
Then outputs / status / return
It has been said that for every line of code there are FIVE lines of comments to accompany it.
I'm not going to quote exact numbers. But I do agree that a well laid out structure is helpful.
Break up the blocks with nice lines like:
==================================================
// New function block description here
As an example.
And maybe even add comments at the top which describe what the block is doing and a brief walk through of how it works.
Although the clip above mentions how DEEP your tests should be (maximum)
Yes, try to keep your conditional testing from being too deep.
Cut things down and have a lot of shallower testing happen before the code so if you want to change things it is at these shallower depths you are changing things.
I know it can be hard to see/understand all this - and believe me, I am still coming to terms with it - it really can/does help.
Hope this is helpful to at least one person.
(Though more would be nicer.)
All the best.
Happy coding.
Disclaimer.
A lot of this is what I've learnt from getting ChatGPT to help me and me getting it to optimise the code and stuff like that.
Compared to the mess/dog's breakfast I had, the new code is so much more compact and clearer to read.
So I think it is only fair I share what I've learnt with others and Pay it forward.