Separators inside a var name

Alexander Schmolck a.schmolck at gmail.com
Mon Jun 9 17:34:45 EDT 2008


Rainy <andrei.avk at gmail.com> writes:

> I have a stylistic question. In most languages words in var. name are
> separated by underscores or cap letters, resulting in var names like
> var_name, VarName and varName. I don't like that very much because all
> 3 ways of naming look bad and/or hard to type. From what I understand,
> scheme can have variables like var-name. I'm curious about reasons
> that python chose to disallow this. 

Legacy -- mathematical notation is broken and conflates negation and
subtraction (causing all sorts of annoyances including this one). Thus if you
want to be able to name a variable ``a-b`` you either have to write ``a - b``
to disambiguate subtracton from the variable name ``a-b`` or you need to chose
a different symbol for subtraction (writing "a ~ b" would likely be the best
choice).

> Another question I have is what other languages allow this naming scheme?

All lisps. Dylan. Rebol. Postscript. Forth. I'm sure there are a few others.

> Were there any languages that allowed space as a separator? 

Sure.

> What would be a practical way to separate variables from keywords in that
> case?

Lisp allows you to use pretty much anything in a variable name, you just have
to quote it, either 

 like\ this 

or

 |like this|


> "some long variable name", 'just a string', or maybe using 2 spaces: one var
> + other var + third var ? I think being able to easy have very long names
> for vars that are easy to type would be a fairly significant advantage.

I assume you haven't programmed too much? The problem with long names is that
they obscure structure, so they are only worthwhile for rarely used and fairly
obscure concepts where the added descriptiveness yields a net advantage.

> I know I'm probably being too obsessive about this, but that didn't stop me
> from posting. Comments?

I think you're right -- the common naming convention's suck and "python's" is
particularly bad (HtmlFrob HTMLFrob htmlFrob html_frob htmlfrob HTML_FROB
HTMLFROB -- which one will it be? No way to know without looking at the rest
of the code, the only consistency is that the last two are mostly used for
constants; everything else is completely up for grabs). You'd better get used
to it though, it's become "standardized".

'as



More information about the Python-list mailing list