lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'd like to discuss allowing @, $, !, and ? in identifier names.  I
chose these explicitly because they can't be confused with an operator
at the end of an identifier.

>From what I understand, it's common practice in Ruby and Lisp to write
methods like this if you intend they return a boolean:

empty?(some_table) -- returns true if some_table is empty

Usually is_empty() is what I see people use because it's clear that
the function is testing for emptiness and not emptying the table.

The problem is you sometimes wind up writing this terrible thing: if
not is_empty(tbl) then ... end

Ruby also makes it convention to put ! at the end of the function name
if if modifies its `self'.  The non-! version returns a modified copy.

I feel like these 2 added characters alone would make it much easier
to express semantic in function names.

@ could be used if a function creates an object that internally
references the object it was created from, so you'd know whether to
copy or deep-copy later.

I'd propose using $ if a function has side-effects, or performs some
form of I/O -- but I'd love to hear other ideas.  I've never seen $
used except as an operator in Haskell -- the expression on the
right-hand side gets evaluated and passed to the expression on its
left-hand side.  What could it mean as part of a function name?

I was told I could just modify lctype.c and add these characters for
my personal build of Lua.  That is definitely possible, but I'd like
to hear from the community if this is something others want --
especially at a time when we are eagerly watching the changes in the
5.3 work versions.