About definite article before "Earth", "Moon" and "Sun"
Solution 1:
For Sun, you always need the definite article when referring to the star itself. The only time you don't need it is when you're referring to the Sun's light/heat output...
"I like sun" is just about valid, but sun there just functions as shorthand for sunshine. Certainly that's what it means in the more common form "I like the sun" (note lack of capitalisation).
For Moon I can't come up with any context where you don't need the article...
"We put a man on the Moon", but you couldn't do anything on Moon.
Earth can take it or leave it (unlike world, which always needs the article)...
"The Earth is flat".
"Climate change threatens the Earth"
"The astronauts returned to Earth".
"It's like nothing on earth".
"Where on earth have you been?" (contrast with "What in the world was that?")
When the Earth is spoken of as a physical body, occupying space-time, it's normally preceded by the article, and often capitalised. As are Sun and Moon, but there's no universality about either convention, nor is capitalisation necessarily governed by whether the article is present or not. I've capitalised every usage after the article (as do most people), but there are exceptions.
When Earth is used more "metaphorically" to mean our whole environment (really, just the thin skin of biosphere on the surface of the planetary body, where nearly all things that concern us take place) it's more normal to omit the article, and I wouldn't normally capitalise either.
Solution 2:
"Sun" and "moon" can be countable nouns. "Earth" is the name of this planet (a proper noun). For instance, you wouldn't say "The Jack and the Jill rolled down the hill".
Moon is demonstrated as a countable noun with this sentence: Jupiter has many moons.
It used to be common to refer to any star as a sun, and in this context it makes sense to say "the" before it to make sure we are talking about our sun.
However, "star" is now used much more commonly to denote stars other than the Sun, so it would make sense to drop the "the" before mention of the Sun. Maybe it will happen, maybe it won't.
"Earth" as a proper noun is no different than talking about Jupiter or Mars. We never say "The Jupiter" or "The Mars".
But earth is also used as an uncountable mass noun, and like sun, could also have been used to refer to other planets. It is in a nice situation where it can be referred to as "the Earth" OR "Earth". A lucky little planet it is.
Solution 3:
OK, one more attempt to synthesize an answer (with particular thanks to Ham and pavium). The word 'sun' may refer to sunshine (a patch of sun) and 'earth' to dried mud; that's no more relevant than 'moon' meaning point your backside at. "Sun" and "moon" have astronomical meanings, in which they take neither capital letter nor article: Mars has two small moons. ('Earth' in this sense has been superseded by planet; 'sun' here is a synonym of 'star') All three words may also refer specifically to the body in our solar system, in which case, as names, they require "the". "Earth" is a special case; as well as the name of this planet (with article), it may refer to the place where humans live (without): coterminous but not synonymous. If an asteroid passed close, as in the H.G. Wells story, the Earth would not be affected from an astronomer's viewpoint, but Earth as we know it would be devastated.
Solution 4:
I think you can see things roughly as follows:
- "earth", "moon" and "sun" define types of bodies: you could use them just like any boring old noun-- countably, with an article, possessive etc ("Jupiter has over sixty moons", "our earth may simply be one of many", "we are discovering that many stars are themselves suns with planets orbiting around them", "we may discover another earth within our lifetime")...
- ...but, in practice, all three are used with "the", and often capitalised, when they mean "the most local [sun/moon/earth] in question"-- in practice, this tends to mean 'our' sun/moon/Earth, but if you said e.g. "Klax lived on the planet Blingon and one day decided to visit the Moon", that this could imply that he visited the moon of Blingon, not the moon of Earth;
- simultaneously, Earth is the name of a celestial body, just like Venus, Jupiter, Titan, Europa etc. So in contexts where you might use the name of any other planet/moon/asteriod/other heavenly body, you would generally not use the article: "Of the eight planets orbiting our sun, Earth is the thirdmost inner planet and Mars the fourth"; "When will the robot land on Venus/Earth/Mars/Titan?"; "aliens visiting Earth (/Mars/Europa) may fail to find life intelligent enough to be worth conversing with".
(As other posters have mentioned, there is also a secondary use of "sun" to mean "heat/light from the sun", in which case it behaves more like a mass noun such as "water".)