C# style suggests using CamelCase in identifiers to delimit words. Lisp tradition suggests using-dashes-instead.

Has there ever existed a programming language where using spaces in identifiers was not only allowed, but a commonly used idiom when employing multi-word identifiers?

It's possible to have identifiers with spaces in some Scheme implementations, but it's not a widely seen practice. Here's an example:

Petite Chez Scheme Version 8.4
Copyright (c) 1985-2011 Cadence Research Systems

> (define |hey there| 100)
> (define |x y z| 200)
> (list |hey there| |x y z|)
(100 200)
  • If you have namespaces, that is a form of compound identifier. E.g. C++: bobs_utilities :: string_functions :: scramble. This is a name, and we can include arbitrary whitespace if we want because it is syntax, an not a simple token. Names with multiple components want to be abstract syntax; shoehorning namespace info into a single identifier is basically a "name mangling" hack for representing structure inside text where you are lacking the mechanism to represent the structure. – Kaz Apr 24 '12 at 18:25
  • Pretty common in JS, whose primary author was a Scheme guy. – Erik Reppen Jun 14 '13 at 23:58
  • 1
    @ErikReppen As far as I know, spaces are not valid as part of javascript identifiers... – Izkata Jun 15 '13 at 4:58
  • Not for vars no. For property names we can use any string in brackets. e.g. alert({'some Prop':'bob'}['some Prop']); but if those string property names fail the identifier/label test you can't use them with dot notation. – Erik Reppen Jun 15 '13 at 6:08
  • In Ruby you can: define_singleton_method "sjdlkfjsljk#$SDEF SDFSDF@# @#$!!~" do; puts 42; end; and then you can: send "sjdlkfjsljk#$SDEF SDFSDF@# @#$!!~" but it is not common. – Darek Nędza Apr 4 '14 at 8:15

22 Answers 22


FORTRAN compilers ignored spaces so:

   result = value * factor  
   r e s u l t = val ue * fac tor

were identical as far as the compiler was concerned.

Some SQL dialects allow embedded spaces in column names but they need to be surrounded by backquotes or some other delimiter before they can be used.

  • 7
    +1, this is new to me. I always wondered why I only got a B in Fortran but now I know :) – NoChance Apr 24 '12 at 5:44
  • 35
    Sun's FORTRAN manual used to include this sentence: "Consistently separating words by spaces became a general custom about the tenth century A.D., and lasted until about 1957, when FORTRAN abandoned the practice." – Blrfl Jun 14 '13 at 21:52

Visual Basic (and VBScript) also allow whitespace in identifiers if you surround the identifier with square brackets.

Dim [Hello World]
[Hello World] = 123

However, doing so is quite rare.

| improve this answer | |

Does SQL count?

create table "Registered Members" (
    "Full Name" varchar(100),
    "Mailing Address" varchar(100),
| improve this answer | |
  • 3
    It's certainly possible, but I wouldn't call it idiomatic. – Joachim Sauer Apr 24 '12 at 7:05
  • 3
    If you need masking, it doesn't seem to be encouraged. – user unknown Apr 24 '12 at 11:53

Inform 7 is a system for developing interactive fiction using natural language–like syntax, in which multi-word identifiers are commonplace:

Mr Jones wears a top hat. The crate contains a croquet mallet. 

The restriction, of course, is that an identifier can’t contain a keyword when this would be ambiguous.

In a similar vein, identifiers with underscores in Agda can be used mixfix, the simplest example of which is probably the if_then_else_ operator:

if_then_else_ : {A : Set} -> Bool -> A -> A -> A
if true  then x else y = x
if false then x else y = y

In Algol 68 you could have space in identifiers (I don't remember if they were significant or not). But keywords were marked by stropping. Using names with space in them was idiomatic (at least around me).

VHDL allows escaped identifiers with significant spaces in them: \foo bar\. This allows also to use keywords as identifier \and\, any character \n<42>\ and case sensitivity in identifiers (\Foo\ and \foo\ are different while Foo and foo are equivalent, and different from either \Foo\ and \foo\!). Verilog also has espaced identifiers with most of these characteristics (normal identifiers are case sensitive and escaping them unnecessarily doesn't make another identifier), but doesn't allow spaces in them. The need from escaped identifiers in VHDL and Verilog come from the fact they are often produced automatically from other sources (such as schematic) where identifiers customarily don't have the same restriction as in programming language; AFAIK, they aren't idiomatically used in other circumstances.

| improve this answer | |
  • I seem to remember (looking back to the 1980s here!) that CORAL did something similar - you could (and did) have white space in variable names, but keywords then had quotes around them (like 'DEFINE' and, a personal favourite, 'COMMENT'. We used to use the macro processor to replace these with un-quoted versions). – AAT Apr 24 '12 at 21:12

Well Whitespace is all about... whitespace:

Most modern programming languages do not consider white space characters (spaces, tabs and newlines) syntax, ignoring them, as if they weren't there. We consider this to be a gross injustice to these perfectly friendly members of the character set. Should they be ignored, just because they are invisible? Whitespace is a language that seeks to redress the balance. Any non whitespace characters are ignored; only spaces, tabs and newlines are considered syntax.

Unfortunately Markdown doesn't support its syntax and I can't show you some code, but Wikipedia has a human friendly code sample.

| improve this answer | |
  • @sepp2k Whitespace has labels. – yannis Apr 24 '12 at 5:33
  • Oh, you're right. Nevermind then. – sepp2k Apr 24 '12 at 5:36
  • "Most modern programming languages do not consider white space characters". Python does :) – jadkik94 Apr 27 '12 at 16:18
  • @jadkik94 Python does use whitespace, but for indentation not as identifiers. – yannis Apr 27 '12 at 20:08
  • @YannisRizos Oh, yes. And it's also true that most languages don't use whitespace at all (identifiers or not) – jadkik94 Apr 27 '12 at 21:01

I don't know if you consider MediaWiki wikitext a language, but names with spaces are definitely idiomatic:

This example lacks text.
{{Expand section}}

Where "expand section" is the name of a template (http://en.wikipedia.org/wiki/Template:Expand_section)

I guess it meets the criteria - a language where identifiers routinely contain spaces. It's never (I think?) ambiguous because identifiers are always surrounded by lots of punctuation to separate them from raw wiki text.

| improve this answer | |
  • 2
    While wikitext certainly is a formal language, I wouldn't call it a programming language (it doesn't even have loops). – svick Apr 24 '12 at 22:57
  • @svick: Neither do Haskell, Smalltalk, Scheme, Clojure, Erlang, Lambda Calculus, Turing Machines, Io, Ioke, Seph, … – Jörg W Mittag Apr 25 '12 at 11:45
  • @JörgWMittag, but they have recursion, which is just a different way of expressing loops. Wikitext doesn't even have that. – svick Apr 25 '12 at 12:08
  • @svick Depending on which extensions you installed, you get some control structures in mediawiki markup. In particular you get ifs and recursion. Syntax and performance are pretty bad though. Templates behave pretty much like functions, and their names count as identifiers in my book. – CodesInChaos Apr 25 '12 at 12:38
  • 1
    Interesting, from [[Wikipedia:Transclusion]]: "There is no real looping functionality built into the Mediawiki software as of this time...but there are some tricks for mimicking them. For instance, repeatedly calling a template that repeatedly calls a different template can mimic a double loop. Templates can also be coerced into calling themselves (normally prohibited by the Mediawiki software past a single instance, to prevent infinite loops), by the artful use of redirects (see m:Template:Loop1 (backlinks, edit)) See also m:Help:Recursive conversion of wikitext." – Steve Bennett Apr 26 '12 at 0:46

Scala allows arbitrary identifiers using backticks. The usual use for this is to invoke Thread.`yield` because yield is a reserved word in Scala. This could be (ab)used to have spaces in names, although that would be far from idiomatic Scala code:

val `the answer` = 42
println(`the answer`)

Heck, you can even have tabs in identifiers:

scala> val `the\tanswer` = 42
the     answer: Int = 42

I suppose this could conceivably be idiomatic for the literate programming folk. Maybe.

| improve this answer | |
  • Scala allows characters like + in method names. So for obj.a+=1, it would parse it as if a+= were a method. The inventor Martin Odersky in his textbook assumes that programmers usually include spaces, so that parser ambiguities are practically not too problematic. – Jesvin Jose Apr 25 '12 at 11:20
  • 1
    @aitchnyu: Actually, in mixed identifiers, the alphanumeric part and the operator part need to be separated by an underscore. obj.a+=1 is equivalent to obj.a += 1 which is equivalent to obj.a.+=(1). You would need to have obj.a_+=1 if you want it to work the way you describe. (Actually, that will give a parse error, you need to either call obj.a_+=(1) or obj a_+= 1.) – Jörg W Mittag Apr 25 '12 at 11:56
  • That's no tab… it's a space station. And by space station, I mean a tab escape sequence. – Thomas Eding Aug 15 '14 at 14:52

You might consider this to be the case in Cucumber/Gherkin, where function names are effectively sentences with the arguments embedded inside them.

As an extension, I would expect this to be more common in tiny DSLs, where the language is supposed to be friendly to non developers. For example, many rules engines provide an abilty to define rules with an english-like description, where spaces can be used in identifiers.

| improve this answer | |

F# allows white space in identifier names, but they must be surrounded with double backticks. See the answer to this question: https://stackoverflow.com/questions/6639688/using-keywords-as-identifiers-in-f.


FWIW, Tcl allows spaces (and just about every other character) in identifiers, though it's not common to take advantage of this feature. The main reason it's not used very often is just that you have to use proper quoting. For example, the following sets a variable named "my name" to "bob", then prints it

set "my name" "bob"
puts "hello, ${my name}"

OTOH, it's very useful when building variables dynamically since, when creating such variables, one doesn't have to worry about illegal characters

| improve this answer | |

There are few I know of. I am working on one, and the lithe programming language. Inform does, but it's not exactly a general purpose programming language.

| improve this answer | |

If you consider an automated testing DSL a language, the robot framework allows spaces in keyword names, and it's very idiomatic. In the following example "Say hello" is a keyword name, "Example test case" is a test case name, and "${first name}" is a variable:

*** Keywords ***
| Say hello | [Arguments] | ${first name}
| | log | Hello, ${first name}

*** Test Cases ***
| Example test case
| | Say hello | world
| improve this answer | |

The 4D language allows white space in method names and variables. It is generally frowned upon within the community, but all built-in methods and variables use them when applicable (SET MENU ITEM PARAMETER, for example)

| improve this answer | |

Powershell allows spaces in variable names:

PS C:\> ${the var} = 100

PS C:\> ${the var}
| improve this answer | |

I saw mention of similar for VB but in JS this is used a lot actually. Any property of an object in JavaScript can be accessed and set in string form with square brackets or simply as strings in object literals. Property names that don't follow JS's variable naming rules are inaccessible via . notation but they are handy. For instance, you might want to map URLs to behavior or reference a group of people by name when you're certain they're all unique. It's often very convenient and easy to read:

var peoplesFavoriteThings = {
    "Bob Jones":"kittens",
    "Jane Doe":"chainsaws"

for(var name in peoplesFavoriteThings){
    console.log(name + ' likes ' + peoplesFavoriteThings[name] + '.\n');

This also makes it easy to restructure JSON for ease of use without losing the instant-object factor when dropped into JS.

| improve this answer | |
  • Funny that this is the only mention of JavaScript. Yes, methods and properties can contain strings: foo['my method']() and foo['my property'] – Steve Bennett Mar 3 '17 at 5:50

Smalltalk features keyword methods such as a:b:c: which involve whitespace when invoked. E.g.: a: 100 b: 200 c: 300. This is a standard idiom in the language.

| improve this answer | |

Power Query uses a lot of automatically generated code. I'd guess more than half of generated identifiers use white space:

    Source = Sql.Database(".", "Test"),
    dbo_pvt = Source{[Schema="dbo",Item="pvt"]}[Data],
    #"Filtered Rows" = Table.SelectRows(dbo_pvt, each [VendorID] <= 4),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Emp1", "Emp2"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Emp3", "Emp4"}, {{"Count", each List.Sum([Emp5]), type number}})
    #"Grouped Rows"

As you can see, like in many languages there's extra syntax to disambiguate what the identifier is.

But in places where it's unambiguous, no extra syntax is needed:

    spaceRecord = [with space = 42, recursive record = @spaceRecord],
    drilldown = spaceRecord[recursive record][recursive record][recursive record][with space]
    drilldown   // 42
| improve this answer | |

If you you count it as a real language, JMP scripting language ( http://www.jmp.com/support/downloads/pdf/jmp_scripting_guide.pdf ). It allows identifiers to have whitespace (to make them more "readable") and more or less encourages such.

| improve this answer | |

The o42a programming language I am currently developing supports a multi-word names. The language has no keywords at all and the names are usually separated with some symbol. In the rare case the two names follow each other, the underscore is used to separate them.

| improve this answer | |

Authorware, whose scripting language was based on non-object-oriented Pascal, allowed spaces in variable names, though over time people discovered the problems with using them and moved away from it http://books.google.com/books?id=bHC88YignAkC&pg=PA428&lpg=PA428 .

| improve this answer | |

Edit: This answer was shown to be not correct, see the comments.

If I understand your question correctly, a compiler can't allow space(s) in identifier name because it could cause duplicate names (unless a delimiter is used). For example:

int my=0; bool my count=false; int count=0; if (my Count)...

the term 'my count' is confusing it could either refer to the variable called 'my count' or maybe the developer forgot to write a relation operator such as > between my and count.

COBOL allowed division names and section names to be separated by space but those are not identifiers and variables as in your question.

  • 4
    Well, it's not the compiler, it's the language definition. Most languages can't allow whitespace in identifiers because they would create ambiguity. – Steve Bennett Apr 24 '12 at 5:15
  • 2
    Your reasoning seems kind of iffy to me. In your example the only alternative to my Count being a variable name would be the programmer having made a typo. That's not ambiguity. Ambiguity would be if there was another valid way to parse the expression. By the same reasoning you could say that allowing a(b+c) is ambiguous because maybe the programmer forgot a > and really meant a > (b + c). – sepp2k Apr 24 '12 at 5:32
  • 1
    But (in a language that allows spaces in variable names) there is also no ambiguity in if (my count). You're not saying there is a different, valid way to parse that statement (which would mean it's ambiguous). You're saying if you add the character <, you end up with a different, valid parse. And I'm saying if you add the character < to a(b+c) you also end up with a different, valid parse. – sepp2k Apr 24 '12 at 5:55
  • 1
    @SteveBennett Right. Any language that allowed spaces in variable names would either have to disallow them in type names or use a different syntax for type declarations (like say var name of the variable : type of the variable) - or not have type declarations at all. – sepp2k Apr 24 '12 at 5:56
  • 1
    @sepp2k, now I got your point. Thanks for taking the time to make it clear. My answer is incorrect. – NoChance Apr 24 '12 at 5:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.