Well, I generally find that the best way is to do both.
That is, you jump in and start putting stuff together, and play it over and over and over... Then you'll start thinking "I need an oboe right about here..." or "What will it sound like if I change to the relative minor now?".
If you're righting a pop song, chances are you'll have a great idea for the chorus. So write it down, get it sounding great, even if it's only twenty seconds or so long. Then, have a think about how you're going to structure the entire track: Intro Chorus Verse Chorus Verse Bridge Chorus Outro is a good, standard way. A few suggestions:
- If your chorus is major, what about making your verse or bridge minor (and vice versa)
- Should you really be adding yet another instrument on top of everything?
- What about if you bring everything back, so you can build it up again?
- How am I going to move from the bridge back to the chorus (or whatever)?
- Do any words pop into my head while I'm listening to it?
That last one is a great one for developing a track. If you start singing something in your head while you're writing it, you've got two creative streams happening at once, which can feed off each other. Don't worry about how inane or stupid your lyrics sound to you - you don't have to include them in the final track, and they're not set in stone!
If you're writing classical stuff, you can save yourself a lot of effort by deciding, before you put down your first note, what form you're gonna use. Will it be a rondo, a sonata, a fugue? Will it be through-composed, serial, or more formalised? Will it be a wind quintet, a string quartet, an orchestra? The well-established structures exist to help you. Use them!
For dance music, it can be a little bit harder. You can go down the path of a standard pop layout, or you can stick with a single primary idea throughout. If you do stick with one idea, you have to use all sorts of tricks to keep it interesting. You could change instrumentation - take the lead away from that long synth and give it to a pluck, maybe. You can drop the tension entirely, and then have it come back in pounding, to give that full, fat sound that everyone loves. You can throw in extra bars, or bars of 5-4, to add variety.
There's no hard-and-fast rule on how to compose music. Do what works for you. Hopefully you'll find something useful in the suggestions I've made, though.