Background: Recently while looking at a ‘structured text editor’ I noticed they used a trick to change python/perl/c++/java et al. into a ‘structured’ outline by sneaking XML into the comments of the respective languages.
I remembered seeing this trick inside a windows bat file once as well. The REM statements of the bat file were used to ‘hide’ some perl code.
Question: Have you ever seen an instance where someone used the comments of a programming or markup language to embed the syntax of an entirely different language? If yes, can you give a link to the example or explain what it was?
If you have not, here is an example:
Question: Is this kind of ‘trick’ a clever and useful idea? If so, can you enumerate a special instance where you used this trick? If no, can you describe why you think it is a bad idea?
You’re speaking of polyglots, an absolutely fascinating aspect of computer programming and a wonderful exercise in the ambiguous nature of some scripting/programming languages. While most definitely an intriguing notion, they are rarely seen outside of the arena of novelty. Speaking from the standpoint of a coder, however, it would most definitely be a feat to get your work to function in several, vastly different environments; seeing, however, as polyglots generally rely on all sorts of hacks and work-arounds via comments, this is almost always outside of the realm of feasibility. Definitely worth a look if you haven’t seen what they can do, though; I’ll recommend this one.
Believe it or not, that single file will properly compile (in some way, shape, or form) in fifteen separate languages: