Should I use a hyphen to connect the following words? What is the general rule about that?
environment friendly --> environment-friendly
frontend --> front-end
backend --> back-end
speedup --> speed-up
Two words are joined by a hyphen when the collocation occurs in a non-standard context. For instance, we speak of the front end (space, no hyphen) of a car when this acts a noun phrase:
But when we use front end as an attributive, we hyphenate it:
This lets the reader understand that we are speaking of a collision involving the front end rather than an "end collision" (whatever that might be - it has no obvious meaning) at the front.
In the same way, the phrasal verb is always speed up (space, no hyphen) when we use it as a verb:
But if we want to use speed up as a noun, we hyphenate it.
Two words are compounded - stuck together with neither a hyphen nor a space - when the collocation acquires a distinct sense, or the phrase becomes so common that it is felt to be a single word rather than two separate words. For instance, a dead line or dead-line was originally a line around a military prison which a prisoner could be shot for crossing; but when the phrase came to be applied metaphorically to the point by which a project must be completed, and became very common in the sense, it turned into the single word deadline.
Hyphens are used in English in a number of distinct ways. Here are a few:
In the last case the hyphen is only used when it is really needed, which is why I said "a show that is long running", rather than "a show that is long-running". There is nothing that "long" could modify other than "running". So no hyphen is used.
Most of your examples depend on context. You would say.
because an "environment friendly detergent" is some kind of friendly detergent. Note though that you say
because "environmentally" is an adverb and adverbs can only modify adjectives (and verbs of course) but not nouns. There is no chance that you are saying the friendly detergent is environmentally.
You would write
because "front" must modify "end". No need for a hyphen. But you should write
because you mean that the optimization is done in the front end of the compiler, not that the end optimization is front. You wouldn't write
for the simple reason that "frontend" is not a word. Someday it may be, but for now it's not. The great thing here is that you can check the dictionary. If it's not in the dictionary, it's likely not a word.
You could write that
In this case you have a noun "speed-up" made up of two words. But you could also write
I checked two dictionaries. One preferred "speed-up", the other "speedup". On the other hand it is
In this case "speed" is a verb and "up" is an adverb. Two words; no hyphen.
They are written as you wrote there.
Please note that these are compound nouns (except the first one which is noun+adjective and the last one which is a phrasal verb) and can be written without the hyphens as well as described in Oxforddictionaries.com