JeronimoColon
12th May 2006 17:10 UTC
Question on Best Practices...
The latest product that I'm using NSIS to package is pretty big (at least I think so 1000+ lines) and does a lot of neat and fancy things. I was curious to see if there were any post on "Best Practices" for an installation of this size - if not let's start one.
Basically, I'm interested in anything from Naming Conventions, Source Code Management, Codefile Partitioning i.e. what sorts of things should be broken out to separate NSH/NSI files and included/macro'ed in, or anything else that I might not be thinking about that I should be thinking about.
Thanks in advance.
jc3
Comperio
14th May 2006 18:14 UTC
Unfortunatley, I'm not sure anyone really has any 'best practices'. (Or at leaset I'm not aware of any.)
Some things I usually try to do:
- I try to keep all my defines as upper case, whereas normal variable are declared with mixed case. (for example, !define VARIABLE or var MyVariable)
- When writing macros, it's good to include a !define so that you can enclose the entire include file inside an !ifdef statement. This way, if you try to include the same file twice, you won't get any nasty compiler errrors.
- Wrapping your macros inside of a define makes it easier to call the function. You'll find many examples of this throughout the various plugins that people have posted.
- While there is no hard and fast rules about when you should use an external include file, but generally it's good to do so if it would make your code easier to read. It's also wise to do it if you have certain functions that you find you share a lot between scripts. The downside is that sometimes it gets cumbersome to manage if you have too many NSH files.
- When working with large scripts, I find the best tool has been the NSIS plugin for Eclipse. (If you haven't looked into Eclipse, I would hightly recommend it. I has many so many useful functions to numerous to list here. I don't know how I ever coded without it!)
- I find my code is easiest to deal with if I place things in separate sections. For example, I group all my page functions separately from my 'real' functions. Also macros, variables, etc. have their own sections in my script.
- Last is document, document document! Unless you are blessed with photographic memory, it will make the code mush easier to deal with by having a good amount of comments in case you have to come back to it 6 months down the line and need to remember what you did! (Plus it helps anyone else if they need to help you modify the code.)
I'm sure there's probably more, but this should be a good start. :D
JeronimoColon
15th May 2006 21:49 UTC
Thank you Comperio, very good points.
I've been using the NSIS Plugin for Eclipse for a couple of months now and agree - I don't know how I coded without it! (wonder if the dev is working on more improvements to it...) ;)
jc3