In my opinion, form is the crucial point that separates noodling from composition. It is also the most difficult part, because there are no fixed rules. Most people consider harmony and counterpoint difficult, but once you know their rules, you have something to cling to. You break the rules only on purpose to create a specific effect. See for instance the hidden parallel fifth in the first bar of the Aria of the Goldberg Variations. This could easily have been avoided, but Bach actually puts it on a pedestal as if he would be shouting: "Parallel Fifth! See what I'm doing here!"
With form it is exactly the opposite. There are no reliable rules to set you free. How much exact repetition or immediate variation of a theme is enough, how much is too much? The more you try to tweak it, the more you tend to mess it up. If the legend is correct, Chopin wrote many of his pieces as spontaneous improvisations, then he tried to "fix" them for several days, and at the end of his nerves he gave up and went back to the initial version.
Every composer has his own ways to keep pieces together. As an example, look at the Prelude BWV 998. The theme starts on the root note, then it is repeated lower, starting at the fifth, then at the third. While it still is running in "third mode" the piece modulates to the dominant key and everything starts again. Then, at the same spot as in the original key comes a modulation to the dominant (of the dominant), and in the new key the theme is modified for the first time, while the lower voice starts a kind of "walking bass". There is not really that much variation going on, but the piece doesn't get boring at all.
Scarlatti does things completely differently. Almost all of his sonatas have two parts. The first usually is a succession of motives that tend to have nothing in common. He uses repetitive patterns to avoid putting too much material into it. Then these motives are modified and combined with one another in part two, often with surprising key changes. It is actually the B parts that make Scarlatti a great composer.
So here are already two completely different approaches, and both do the trick. I don't think that either of them is easier to emulate. But there is one thing that I'm sure of: what distinguishes a top notch composer from the rest is not how well he knows the rules of the game (they all know the tricks of the trade), but how well someone is doing in places where you cannot find any rules.