String Literal - Embedding Source Code in String Literals

Embedding Source Code in String Literals

Languages that lack flexibility in specifying string literals make it particularly cumbersome to write programming code that generates other programming code. This is particularly true when the generation language is the same or similar to the output language.

for example:

  • writing code to produce quines
  • generating an output language from within a web template;
  • using XSLT to generate XSLT, or SQL to generate more SQL
  • generating a PostScript representation of a document for printing purposes, from within a document-processing application written in C or some other language.

Nevertheless, some languages are particularly well-adapted to produce this sort of self-similar output, especially those that support multiple options for avoiding delimiter collision.

Using string literals as code that generates other code may have adverse security implications, especially if the output is based at least partially on untrusted user input. This is particularly acute in the case of Web-based applications, where malicious users can take advantage of such weaknesses to subvert the operation of the application, for example by mounting an SQL injection attack.


Read more about this topic:  String Literal

Famous quotes containing the words source, code and/or string:

    The source of our actions resides in an unconscious propensity to regard ourselves as the center, the cause, and the conclusion of time. Our reflexes and our pride transform into a planet the parcel of flesh and consciousness we are.
    E.M. Cioran (b. 1911)

    ... the self respect of individuals ought to make them demand of their leaders conformity with an agreed-upon code of ethics and moral conduct.
    Mary Barnett Gilson (1877–?)

    Amongst the learned the lawyers claim first place, the most self-satisfied class of people, as they roll their rock of Sisyphus and string together six hundred laws in the same breath, no matter whether relevant or not, piling up opinion on opinion and gloss on gloss to make their profession seem the most difficult of all. Anything which causes trouble has special merit in their eyes.
    Desiderius Erasmus (c. 1466–1536)