|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#32 id:60359 Posted Jan 29, 2012, 1:32 pm
|
In response to one of David H's posts concerning Liao, I would just like to point out that Lua ships with etc/strict.Lua to catch access to undeclared variables within the global namespace. It is remarkably easy to map strict structures with this module enabled using __index metamethods and named arguments. It takes just a little extra work to describe structures in this manner, and incurs very little extra overhead while allowing you to avoid the headaches caused by dynamic typing (generally turning run time crashes into more friendly compile time errors.)
|
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#33 id:60360 Posted Jan 29, 2012, 3:04 pm
|
Meant Lua, not Liao and if it wasn't clear, im saying: strict typing is an easily implemented feature of Lua using metamechanisms already provided with stock Lua.
|
|
|
|
|
Chris Bailey
Wizard

Group: Members
Posts: 809
Joined: Sep 12, 2008
|
#35 id:60370 Posted Jan 29, 2012, 7:34 pm
|
Joseph Locke said:In response to one of David H's posts concerning Liao, I would just like to point out that Lua ships with etc/strict.Lua to catch access to undeclared variables within the global namespace. It is remarkably easy to map strict structures with this module enabled using __index metamethods and named arguments. It takes just a little extra work to describe structures in this manner, and incurs very little extra overhead while allowing you to avoid the headaches caused by dynamic typing (generally turning run time crashes into more friendly compile time errors.)
I'm missing something here because I'm not sure what you are saying.
|
|
......................... If what Proust says is true, that happiness is the absence of fever, then I will never know happiness. For I am possessed by a fever for knowledge, experience, and creation.
Last edited Jan 29, 2012, 7:36 pm by Chris Bailey
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#36 id:60380 Posted Jan 29, 2012, 9:45 pm
|
David said:
1- it is really, very, awfully nice to have static typing for "core engine" functionality. Lua doesn't allow this.
Lua "allows" for precisely this. Why you would want to write "core engine" functionality in the script language as opposed to the staticly typed host language in the first place is a mystery to me. That said, it is very easy to implement static typing within Lua, using Lua, and that is exactly what im talking about. It is also not at all a new idea; people have been doing this to varying degrees within a wide range of projects. Try googling static typing in Lua.
I don't necessarily believe it's the winning strategy; if you are going to use Lua at all, you should use it for what it is. Its dynamic typing is a strong feature, but some "safety" should be implemented by the coder to fit the needs of the application. If you need to differentiate between nil and an undeclared variable, you need to tell Lua that. If you need static types, or static structs, they need proper forward declarations and to be initialized correctly. Tables and metamethods, tables and metamethods..
|
Last edited Jan 29, 2012, 9:46 pm by Joseph Locke
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#37 id:60382 Posted Jan 29, 2012, 10:01 pm
|
As another author has remarked, if you actually care about memory footprint, startup time, and having a lightweight distributable that is easy to embed and plays well with others, Groovy isn't such a great choice. Besides, LuaJIT > JVM :P
|
|
|
David Haley
Wizard


Group: Members
Posts: 7,841
Joined: Jun 30, 2007
|
#38 id:60389 Posted Jan 30, 2012, 9:12 am
|
Joseph, Lua is not a statically typed language. Ever. The 'strict' module is not static typing. In fact, it has nothing to do with types, but with variable declarations. Declarations are not types.
I'm not sure what you're saying is "very easy" because you're not using the term the usual way, but when people have attempted to force type annotations onto Lua (typically using something like a syntax modification or a token filter) it's certainly not easy.
Quote:Why you would want to write "core engine" functionality in the script language as opposed to the staticly typed host language in the first place is a mystery to me.
Why is this a mystery?
|
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#39 id:60401 Posted Jan 30, 2012, 12:52 pm
|
David, your last response made no apparent indication that you read my previous two posts. While I concede where declarations are concerned (a declaration certainly isn't a type), I think I spoke pretty plainly; static types, either for compiler optimizations or code-programmer friendliness, are easy enough to implement as either a modification to the language or, as you alluded to, within the application via syntactic sugar and filters. I'll contribute code to this discussion when I have the chance to use something friendlier than my phone.
|
|
|
David Haley
Wizard


Group: Members
Posts: 7,841
Joined: Jun 30, 2007
|
#40 id:60404 Posted Jan 30, 2012, 1:08 pm
|
OK, I look forward to seeing your code then, because that will clarify things... I think there might be some vocabulary mismatch here.
I don't really consider it to be supported when you have to modify the language itself. That's like saying that C supports type inference if only you modify the compiler to support it.
And to be honest with you, I really do suspect that terms are being misused, because static typing in a dynamic language is a non-trivial project (and somewhat oxymoronic), and is typically only achieved by imposing very strong constraints on the language -- resulting in a rather different language entirely.
If it helps you, the specific issues I have with your posts (which, yes, I did read, but thanks anyhow -- would you like me to say that you didn't read anything I wrote either because you still don't see what I'm saying? eh):
"If you need to differentiate between nil and an undeclared variable, you need to tell Lua that."
This isn't static typing, this is declaration.
"If you need static types, or static structs, they need proper forward declarations and to be initialized correctly."
Forward declarations aren't static typing, they are making sure that a dynamic structure fits a given constraint.
I suspect that what you are referring to is essentially an extension of the 'strict' module, where you impose certain checks on what's going on. But this is very different from static typing. For example, with 'strict', you can do something like:
local a = "abc"
compute_something(a)
a = 123
but this is not static typing.
Then you have something like this (in pseudocode):
define_type:
my_struct
fields:
name (string)
zipcode (number)
bla = new my_struct()
bla.name = "abc"
bla.foo = "bar" <-- error, invalid field
this is also not static typing.
|
Last edited Jan 30, 2012, 1:09 pm by David Haley
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#41 id:60405 Posted Jan 30, 2012, 1:12 pm
|
"core engine functionality" sounds to me like sockets, threads, file i/o, etc.. Low(er)-level operations than say, assigning item attributes, calculating racial stats, describing mob behavior, etc. which would all likely be modified much more frequently than functionality hard-coded into the host language.
|
|
|
Joseph Locke
Apprentice

Group: Members
Posts: 34
Joined: Oct 12, 2011
|
#42 id:60406 Posted Jan 30, 2012, 1:15 pm
|
Round and around,
Like a wheel within a wheel,
Never ending or beginning,
On an ever spinning reel..
|
|
|
|
|