lua-users home
lua-l archive

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

It was thus said that the Great Coroutines once stated:
> On Fri, Apr 25, 2014 at 2:38 AM, steve donovan
> <> wrote:
> > Perhaps because I grew up with Pascal, I've always thought keywords
> > were sacred words. I usually get around this one by prefixing an
> > underscore (_end) or title-casing (End).  I don't think the language
> > needs to be distorted to allow conventions from other languages to be
> > imported (begin/end iterators)
> Well, strongly disagree. :\  I think it's pretty obvious 'end' is not
> being used as a keyword if it appears as some_table.end.  Yes, I can
> _prefix but it still feels like an unnecessary constraint on the
> identifier used in that table.index sugar.  I also wish punctuation
> could appear in a Lua identifier from the 2nd character onward.

  Careful what you wish for.  Both these fit your rule (punctuation after
second character) and both are unique. = {}
	x     = { foo = 3 }

	print(	-- prints what?

  How about?

	local x,e = 3

  Is that "x,e" (a single variable) being set to 3, or two variables ("x"
and "e") one of which is now 3?

> I know you to be a very smart/clever guy but I want to shake my head
> when it feels like you are against incorporating any concept that may
> be best known from another language.

  It could be that you are butting heads against people who have more years
of experience than you do and have had to deal with code that is "too clever
by half" to be clearly understood.  

  There is a language out there (I want to say one of the Algols, but it's
rather hard to search for this example) that allows you do to:

	if if == if then then = then else else = else

or how about:

	if then = else then else = then else else = if

Then there's this beautiful C code:

	/* to fully understand this code, the following defines
	   are in some headerfile squireled away somewhere */

	#define BEGIN {
	#define END }
	#define IS ==

	if (x IS 5) 
	  printf("x is 5\n");
	  printf("x is not 5\n");

Or this from an actual example at work:

	  /* C code */

FSM_STATE() is a C macro that expands out to the actual function header.  My
first bitch is---great!  Now I have to hunt down the @#$@#$@ defintion of
FSM_STATE() to see if the variable "context" is a global (it's not) or a
paramter (it is) and exactly "context" is (it's a structure).  Worse, gtags
[1] can process C code into a hyperlinked tree to make following the code
easier ("oh, what calls this function?  <click> Ah, I see where it's called
from") but while it doesn't choke on the above, it can't hyperlink the
function, so I *still* have to go back to grep and friends (ctags can't deal
with this either, meaning I can't use my editor to jump to the defintion of

  And if 

	sum += * (unsigned short *) addr++;

doesn't send shudders down your spine, you haven't dealt with bad code. [2]

> I'd want ? in identifiers so I could use it for methods returning
> booleans (not "coerce to boolean").  I like the convention Ruby has:
> some_table:do_something!() -- modifies some_table
> some_table:do_something() -- copies some_table and modifies the returned copy
> some_table:empty?() -- returns a boolean

  You'd really love Forth.  The only restriction on an identifier in Forth
is "no space or control character"; every other character can be used in an
identifier.  No kidding.  You can even define 2 to be a function!  [3]

  -spc (And there's APL, with no keywords at all ... )

[1]	GNU Global source code tagging system.  It's actually pretty nice.

[2]	It's programmers who write C code like this that give C a bad name.

[3]	Yes, there are Forth systems that do this.  Of course, it's a
	function that returns 2, and it's done because a function called 2
	takes less space than a literal 2 in the object code.