The more effort you put in, the better your trains will run. Make your track smooth and level, gradual transitions up and down, and level across the rails. Many people blame derailments on the cars and locos, when it's the track. Yes, I believe you, it's always one loco at first. That's just the loco or car that is affected the most.
Believe it or not this is a train manufacturer's layout! (19 seconds into the video)
Believe it or not, you should check the gauge of your track every so often. Many people have reported out of gauge track, even on straights! This can happen from age, pressure from the surroundings, screws distorting the ties, etc. For example, Aristo track gauge can vary all over the place, I know from direct experience.
Check your switches!
I have a couple of sections on specific makes/models, but get a good gauge (like the Aristo), check the flangeways, wing rails, how the points fit, and the gauge. Aristo switches especially need reworking out of the box.
Use good track design!
Try for easements into curves and grades. If you have a tight curve, try putting a section of broader curved track at the beginning and end of the curve to ease the "transition" from straight to curved.
Keep grades to 1 or 2% unless you are running a logging railroad with geared locomotives. Remember that for every increase in grade (1%) your pulling power will reduce by about HALF.
Try to eliminate "S" curves, where a curve in one direction is followed immediately by a curve in the other direction. Try to put a minimum of 1 length of straight between the two curves that is at least as long as your longest car. It's better to make it 2 car lengths, thus the couplers are never being twisted in opposite directions.
Make all your switches dead flat if possible. Switches are the most likely location for derailments, with the wheels being pushed from one side to another. Having an out-of-level switch is just more opportunity to have a derailment. Switches on grades are problematic.
Clearances:
Leave enough clearance for trains that have a lot of overhang. Don't make it too tight!
I use about 9 inches center to center on the main line, but I only run 1:29 and have 10 foot minimum curves.
Leave room for expansion between rail ends if you have a climate with temperature extremes. In San Diego, I just use the thickness of a credit card. Many people in Arizona need special expansion track that can move 1/2 inch or more.
Not handling expansion and contraction can make kinks. Many people use 1/16" to 1/8". Since I free float my track, I can use tighter joints.
Make sure the rails are well aligned where they join. Track joiners, even rail clamps, don't always align the rails well, take a pair of pliers to the area to align things so your hand feels no bump as you sweep it across the joint.
Check your wiring for looseness or corrosion. Get a can of a spray corrosion inhibitor. Look in the marine supply stores, since they are always fighting corrosion.
Special tips for track power:
Do it right the first time. If you save a few bucks or hours now, you can be sure it will cost you much more time and money later.
I prefer rail clamps. If you use joiners alone, they usually are headaches. If you use brass or nickle silver rail, you can solder jumpers.
Just do what it takes to make good power conduction.
Be sure to look for corrosion or a situation where you have the suseptability to corrosion. Inspect the rail joiners / clamps every so often. Your track wiring should be every 20 to 30 feet if you are running large engines or multiple locos per train.
I use insulated joiners between power dirstrict/sections, then if a bad joint appears, it is immediately apparent. If you feed power on either side of a bad joint, it cannot be isolated easily. Bury wire alongside the track so you can find it again! (or use conduit as I did)