Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do programming languages not allow spaces in identifiers?

This may seem like a dumb question, but still I don't know the answer.

Why do programming languages not allow spaces in the names ( for instance method names )?

I understand it is to facilitate ( allow ) the parsing, and at some point it would be impossible to parse anything if spaces were allowed.

Nowadays we are so use to it that the norm is not to see spaces.

For instance:

 object.saveData( data );
 object.save_data( data )
 object.SaveData( data );
 [object saveData:data];

etc.

Could be written as:

 object.save data( data )  // looks ugly, but that's the "nature" way.

If it is only for parsing, I guess the identifier could be between . and ( of course, procedural languages wouldn't be able to use it because there is no '.' but OO do..

I wonder if parsing is the only reason, and if it is, how important it is ( I assume that it will be and it will be impossible to do it otherwise, unless all the programming language designers just... forget the option )

EDIT

I'm ok with identifiers in general ( as the fortran example ) is bad idea. Narrowing to OO languages and specifically to methods, I don't see ( I don't mean there is not ) a reason why it should be that way. After all the . and the first ( may be used.

And forget the saveData method , consider this one:

key.ToString().StartsWith("TextBox")

as:

key.to string().starts with("textbox");
like image 456
OscarRyz Avatar asked Nov 26 '09 18:11

OscarRyz


People also ask

Why is character space not allowed in identifier?

I understand it is to facilitate ( allow ) the parsing, and at some point it would be impossible to parse anything if spaces were allowed. Nowadays we are so use to it that the norm is not to see spaces.

Are spaces allowed in an identifier?

Identifiers contain characters from any of: alpha, digit, underscore, and dollar sign. You can't use spaces or tabs or symbols like #, @, !, and so forth in an identifier.

Why space is not allowed in variable?

No other characters are permitted in the variable name. Specifically, spaces are not permitted in the variable names, as the variable name must be a single word.

Can C++ identifiers have spaces?

The identifiers in C++ can have identifiers with any length of characters. These characters can be alphanumeric i.e can contain letters, digits and underscores and whitespaces and special characters such as @,#,! etc are not allowed.


1 Answers

Be cause i twoul d makepa rsing suc hcode reallydif ficult.

like image 178
Jay Riggs Avatar answered Nov 15 '22 08:11

Jay Riggs