Difference between revisions of "Tech Tips"
From kemiko
Line 62: | Line 62: | ||
<ul> | <ul> | ||
<li> | <li> | ||
− | Top-down | + | Top-down vs bottom-up design |
</li> | </li> | ||
<li> | <li> | ||
− | Always add comments | + | Always add comments...you may not remember what you did day, months, years from now |
</li> | </li> | ||
<li> | <li> | ||
− | Line block brackets up vertically | + | Line up block brackets up vertically |
</li> | </li> | ||
<li> | <li> | ||
Line 77: | Line 77: | ||
</li> | </li> | ||
<li> | <li> | ||
− | Pick a style and stay consistent | + | Pick a style and stay consistent...this sometime means following someone else's style when modifying existing code |
</li> | </li> | ||
<li> | <li> | ||
Line 83: | Line 83: | ||
</li> | </li> | ||
<li> | <li> | ||
− | Give some thought to designing your log files. | + | Give some thought to designing your log files... |
<ul> | <ul> | ||
<li> | <li> |
Revision as of 21:55, 10 February 2017
Trouble Shooting:
- Start with the basics...like power, network, etc.
General:
- Know the animal before trying to tame
- Some vendors use MB/GB (decimal...1000s) and some use MiB/GiB (binary...1024s)
- Always query before running modification command(s)
- Backup or already have a backup before modifying files
- Learn your editor(s) well...it's functions can save a ton of time
- Always tail -f error logs when developing
Development:
-
Naming
- Avoid spaces.
- Use camelCase.
- Name common items with the common word starting each item.
- Name same item, but numbered with enough padding to sort correctly. ex: if going to at least 10 use 01-10 instead of 1-10.
- Name date by number not name and most general to specific. So they sort correctly. ex: 20161231 instead of Dec31-2016, etc.
- Name using noun first then verb. ex: logCreate, logList, dateStart, dateEnd, etc.
-
Coding
- Top-down vs bottom-up design
- Always add comments...you may not remember what you did day, months, years from now
- Line up block brackets up vertically
- Happy balance between elegance/complexity and readability/maintainability
- Happy balance between too long and too short variable naming
- Pick a style and stay consistent...this sometime means following someone else's style when modifying existing code
- Learn your debugging tool(s)...they can save a ton of time
-
Give some thought to designing your log files...
- Put the date and time in each record
- Format well...XML, JSON, delimited, etc.
- Make sure enough data is included to be helpful
*nix:
- Type "env" in the shell to display all the environment variables
- Use "set -x" to debug shell scripts ("set +x" turns it off)
- Use "set -o vi" to use vi to navigate/modify shell commands ("set +o" turns it off)
-
crontab
- Put number in 09 format to make easier to read, parse and sort
- Always redirect command output somewhere, log file, /dev/null, etc., so it does not fill up your email
SQL:
- Always use a where clause even if for everything...where 1 or where 1 = 1. This reminds someone editing the code that this query is operating on EVERYTHING.
- Comments are handy even in SQL for debugging and as comments. "--comments" is universal, but also /* comments */ in MySQL, {comments} in Informix, etc.