Reverse domain name notation
Reverse domain name notation (or reverse-DNS) is a naming convention for the components, packages, and types used by a programming language, system or framework. A characteristic of reverse-DNS strings is that they are based on registered domain names, and are only reversed for sorting purposes. For example, if a company making a product called "MyProduct" has the registered domain name "example.com", they could use the reverse-DNS-ish string "com.example.MyProduct" to describe it.
History
Reverse-DNS first became widely used with the Java platform, and has since been used for other systems, for example, ActionScript 3 packages.
Examples
Examples of systems that use Reverse-DNS are Sun Microsystems' Java platform and Apple's Uniform Type Identifier or UTI. The Android operating system also makes use of the notation for classifying applications, as the Dalvik virtual machine made use of Java.
dconf which is the configuration backend used by GNOME.
Example of reverse-DNS strings are:
- com.adobe.postscript-font (UTI string for Adobe Systems's PostScript fonts)
- com.apple.ostype (UTI string for Apple's OSType)
- org.omg.CORBA (Java library for CORBA)
- org.w3c.dom (Java library for W3C's DOM)
Regular expression
^[A-Za-z]{2,6}((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+$
Code
C#
/// <summary> /// Reverses a domain name. /// </summary> /// <param name="domain">A domain name.</param> /// <returns>A string with the domain name reversed.</returns> private static string ReverseDomainNameNotation(string domain) { return string.Join(".", domain.Split('.').Reverse()); }
JavaScript
function reverseDomain(domain) { return domain.split('.').reverse().join('.'); }
Perl
sub reversedomain { return join ".", reverse split /\./, $_[0]; }
PHP
function reverseDomain(domain) { return implode('.', array_reverse(explode('.', domain))); }
PowerShell
function Get-ReverseDomain($domain) { $segments = $domain.split('.') [array]::reverse($segments) return $segments -join '.'; }
Python
def reverse_domain(domain): """Reverses a domain name.""" return '.'.join(reversed(domain.split('.')))
Ruby
# Reverses a domain name. def reverse_domain(domain) domain.split('.').reverse.join('.') end
References
- "Apple Developer Connection: Introduction to Uniform Type Identifiers Overview". 2005-11-09. Retrieved 2013-04-04.