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:

    It is very difficult to be wholly joyous or wholly sad on this earth. The comic, when it is human, soon takes upon itself a face of pain; and some of our griefs ... have their source in weaknesses which must be recognized with smiling compassion as the common inheritance of us all.
    Joseph Conrad (1857–1924)

    ...I had grown up in a world that was dominated by immature age. Not by vigorous immaturity, but by immaturity that was old and tired and prudent, that loved ritual and rubric, and was utterly wanting in curiosity about the new and the strange. Its era has passed away, and the world it made has crumbled around us. Its finest creation, a code of manners, has been ridiculed and discarded.
    Ellen Glasgow (1873–1945)

    ... looped with the creep of varying light,
    Monkey-brown, fish-grey, a string of infected circles
    Loitering like bullies, about to coagulate....
    Philip Larkin (1922–1986)