lua-users home
lua-l archive

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




On Friday, August 29, 2014, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2014-08-29 10:21 GMT+02:00 Thijs Schreijer <thijs@thijsschreijer.nl>:

>> There should be one and only one reason ever to change a name:
>> because the new name is used for something different.
>
> Not necessarily. The examples shown (coroutine/thread and lua_State)
> are pure legacy, if not now, then sometime in the future you'll have to
> clean that up, simply because over time you'll be accumulating more
> and more. And even then backward compatibility is only one #define
> away (for the c api at least)

As far as I am concerned, a lua_State* is something I can pass to
an API routine, containing all the information about necessary stuff
that a user of the API does not need to know. If Roberto and friends
think of that information as a "state", that is good enough for me.

Likewise, if they can write a logical sentence in which the words
"thread" (in the Lua sense) and "coroutine" both appear [1], I do
not consider it proper to tell them it's the same thing. Instead, one
should devote some time pondering the implications of the word
"implement" in that sentence.

So neither of those examples is "pure legacy".

Here is an example of a justified name change:

   Lua 5.1: luaL_register
   Lua 5.2: luaL_setfuncs

Inside module code, they are very similar. Where you used to put
luaL_register(L,NULL,lib), you now put luaL_setfuncs(L,lib,0).
But they have different argument lists, and when all three
arguments are non-trivial, the extra tasks they do are different.

[1]  "The type `thread` represents independent threads of execution
   and it is used to implement coroutines." Lua 5.2 manual, §2.1.


I think that the most important principle is internal consistency. 

Lua expects a value with the type "thread" and not "coroutine". In that sense, status's error string is confusing. Also, every other error of that kind tells you whet it got, instead. So that's a little inconsistent and not as helpful. 

I respect the prodigious refinement of software. But a wise, middle age man (me) once said, names are never "exactly" right. Once they've been chosen, that word takes on that definition to all who use it. It becomes "related" to what it does and that has tremendous value. 

In this case, the two words have a specific meaning:

A "coroutine" is the function that is the value you give to "coroutine.create". You can pass that same value to "create" a hundred times, creating a unique "thread" each time.

The only thing that makes a function a coroutine is that it is being used as an argument for create. So, it's usefull as an _expression_ of the value's role, but not otherwise. (Except when a function contains yield, without being protected by is yieldable())


-Andrew


Analogy: In the same way, you may meet a girl that seems like an even better fit for you than your wife, but your existing relationship (your understanding and history), your mortgage and your kids (your code) have a ton of value. :)