06-24-2022
05:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-24-2022
05:27 AM
I'd go with Snippet 3, because I personally prefer a more verbose style than something like Snippet 2. I like to have each "task" have it's own section in code. The main benefit is when I come back to it 6 months later, it's easier for me to tell what the code does.
Snippet 4 is good for beginners but as a general rule code should be understandable without comments, and I think #2 and #3 are fairly easy to understand. If I do put in comments I tend to put them at the end of a line of code, not before a block. That way I can avoid them if I don't need them, but they are there if I do.