Directives is an actively used design pattern created in 1968.

51Years Old
  • Directives ranks in the top 50% of entities I track
  • the Directives wikipedia page
  • Directives first appeared in 1968
  • I have 24 facts about Directives. what would you like to know? email me and let me know how I can help.

Languages with Directives include ada, algol-68, c, common-lisp, cpp, erlang, f-sharp, haskell, javascript, perl, python, ruby, rust, turbo-pascal, visual-basic

Example from algol-68:

.PR POINT .PR
.PR UPPER .PR
.PR RES .PR
'pr' quote 'pr'

Example from c:

#include <stdio.h>
#define height 10
#ifdef
#endif
#if
#else
#ifndef
#undef
#pragma

Example from cpp:

// #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation.
#pragma once
struct foo
{
   int member;
};

Example from erlang:

-define(TIMEOUT, 200).
...
call(Request) ->
   server:call(refserver, Request, ?TIMEOUT).
-undef(Macro).

Example from f-sharp:

#if VERSION1
let function1 x y =
   printfn "x: %d y: %d" x y
   x + 2 * y
#else
let function1 x y =
   printfn "x: %d y: %d" x y
   x - 2*y
#endif
// Line directives as source maps can be used when compiling to F#:
#line 25 "C:\\Projects\\MyProject\\MyProject\\Script1"

Example from haskell:

{-# INLINE foo #-}

Example from javascript:

"use strict";
"use asm";

Example from perl:

# In Perl, the keyword "use", which imports modules, can also be used to specify directives, such as use strict; or use utf8;
use utf8;

Example from python:

from __future__ import feature
# coding=<encoding name>

Example from ruby:

coding: UTF-8

Example from rust:

// A conditionally-compiled module
#[cfg(target_os = "linux")]
mod bar {
    /* ... */
}
// General metadata applied to the enclosing module or crate.
#![crate_type = "lib"]
// A function marked as a unit test
#[test]
fn test_foo() {
    /* ... */
}
// A lint attribute used to suppress a warning/error
#[allow(non_camel_case_types)]
type int8_t = i8;

// Inner attribute applies to the entire function.
fn some_unused_variables() {
  #![allow(unused_variables)]

  let x = ();
  let y = ();
  let z = ();
}

Example from turbo-pascal:

// In Turbo Pascal, directives are called significant comments, because in the language grammar they follow the same syntax as comments.
// In Turbo Pascal, a significant comment is a comment whose first character is a dollar sign and whose second character is a letter;
// for example, the equivalent of C's #include "file" directive is the significant comment:
{$I "file"}

Example from visual-basic:

Option Explicit On|Off
Option Compare Binary

Last updated July 8th, 2019