Why does all life use the same macromolecules in their genetic code?
Preamble
Any answer regarding the origins of our biochemical evolutionary origin will be reasonably speculative given that this is a very hard question to scientifically test and this field is generally understudied to say it is pretty much the most fundamental biochemical question. But there are a few reasons why RNA makes sense as the prime genetic molecule compared to other established macromolecules present in the primordial soup, and also there are good reasons why DNA superseded it as genetic storage for most cellular organisms.
In summary, the alternative abundant polymer macromolecules that came from the primordial soup aren't as versatile as RNA, and over time DNA was used more over RNA due to it being a more reliable information storage molecule.
We must remember though that the conditions that lead to the genesis of RNA is a much tougher question. There are an unfathomable amount of combinations of chemicals that could have facilitated an evolutionary process. @WYSIWYG made an excellent comment regarding why this is an almost impossible question to answer definitively:

...Why is there a phosphodiester backbone used rather than
ether, amide, carboxyl ester or any other kind of linkage? Or why
purines and pyrimidines, why not naphthalene ring heterocycles? Why
imidazole, why not oxazole or furan? You cannot reason this out in a
reverse manner.

Therefor in this answer we will be discussing RNA and other bio-polymers that were established in abundance from the very early primordial soup, not the original genesis of such biochemicals. What made each of them good vessels for an evolutionary process?
A genetic code macromolecule needs the following features:

Stable.
Variable structure.
Expandable.
Replicable.

RNA has all these and doesn't rely on a biological system for reproduction of the RNA molecule.
RNA world.
Let's not forget that DNA is probably not the first one along and there was an RNA world before the cell as we know it. Even today many viruses particularly make use of ssRNA.
RNA was a good molecule because it was a polymer made of 4 base monomers that could bind with other polymers to make any array of compositions of the base components and was spontaneously replicable. This allowed a primordial form of molecular evolution as we know it today. It is able to carry more varied information than other abundant macromolecule polymers.
RNA can also carry out functions in a similar way a protein might, including catalysis. No known sugars or other macromolecules are able to demonstrate the same level of variability and versatility as RNA, although deoxyribosymes have been artificially designed in laboratories.
This probably gave it a good chance at establishing itself as the first molecule to trigger biogenesis, and this lead to nucleic acids being established as the fundamental molecule of molecular evolution.

DNA chemical structure.
Eventually RNA evolved into more complex structures and DNA broadly superseded RNA as a storage device for genetic information in cellular organisms primarily due to the increased stability DNA offers over RNA. If we take a look at DNA specifically we see a very good data storage mechanism for a couple of reasons.

Intra-strand hydrogen bonding and different chemically structured sugar group makes a more stable overall structure.
More rigid grooves allow proteins to bind at particular sites.
Again, it's a polymer of variable composition.


Alternative coding macromolecules.
What are our other options from the biological polymers?

Carbohydrates. The glycocalyx coats most cells in our body, and clearly sugars (specifically polysaccharides and glycoproteins) are an expandable, information rich molecule. However it relies on proteins for assembly in the same way proteins do, so it never really got the chance to be that prime molecule.
Lipids. A brilliant expandable polymer, and many are spontaneously expanding in the right conditions, but generally lipids cannot carry as much &quot;information&quot; in the polymer (pretty much just varying lengths of CH2 groups).
Proteins. Too complex and not spontaneously replicable. They rely on other systems for production (except in some rare examples, although they arguably still rely on a complex biological system).