by cookie.monster at 2012-09-28 10:53:28
Looking to tidy up my code. What do you use to tidy up?
For example, could you enclose sections of code in $() to allow quick collapsing without creating any scoping issues?
Your insight would be greatly appreciated!
by poshoholic at 2012-09-28 12:12:45
I use #region statements, with short descriptions of the business logic they contain. e.g.
#region Get a list of computers.
#region For each computer, check to see if it is responding to ping requests.
#region If a computer is responding to ping requests, get the OS version and serial number from that computer.
Regions are collapsible in modern editors and they make it very easy to read what a section of script is doing so that you can go into the right section when you need to test/change behaviour and so that you don't forget what something is used for. You can also nest regions inside of other regions, which is helpful as well for larger chunks.
And don't forget to use the dry principle and encapsulate shared logic in functions.
by cookie.monster at 2012-09-28 12:15:18
Exactly what I was looking for, thanks for the tip!