01 Jul, 2009, JohnnyStarr wrote in the 1st comment:
Votes: 0
So, i've been looking into Lua and what not, but it appears (to me) that you can just as easily use python to embed as a scripting language for your mud, now, i dont have much experience with python, and none with Lua, but what you guys think about it? From what i know (which aint much) is that python allows implicit OOP as where with Lua (from what i've read) does not, but you can simulate it using features. It seems that Lua is more designed to work with C, but i personally like the idea of python. anyway, just wondering, not trying to sound like i know more than anyone.
01 Jul, 2009, Runter wrote in the 2nd comment:
Votes: 0
Lua is probably easier to do that with, actually, and OO paradigms can be used even with C. Some languages may just make it easier to do this.

I personally like Python better, though.

You can expect to hear from David on this subject shortly. :P
01 Jul, 2009, quixadhal wrote in the 3rd comment:
Votes: 0
Yep… I like the python language better, but I've heard that lua is much simpler to embed (easier to transfer data in and out of the sandbox). I haven't actually DONE that, so it may simply be a rumor. :)
01 Jul, 2009, JohnnyStarr wrote in the 4th comment:
Votes: 0
quixadhal said:
Yep… I like the python language better, but I've heard that lua is much simpler to embed (easier to transfer data in and out of the sandbox). I haven't actually DONE that, so it may simply be a rumor. :)


i am not authority on the subject, but everything i've read on it dosn't look simple at all, python however seemed (to me) to be more straight forward than Lua, maybe thats because i am very comfortable with ruby, maybe the tutorials i read were crummy, i dunno.
02 Jul, 2009, Davion wrote in the 5th comment:
Votes: 0
If you're going to embed python into a C program, make sure you check out boost::python. Needs a bit of voodoo to get going though. Also make sure you find out how to sandbox the language so people who use the python scripting can't lay waist to your server.
02 Jul, 2009, JohnnyStarr wrote in the 6th comment:
Votes: 0
:biggrin: looks sweet! have you used it for your mud or *a mud? just checking to see how you applied it IE are you using it as a more powerful MobProg system? etc.
02 Jul, 2009, David Haley wrote in the 7th comment:
Votes: 0
Lua is trivial to embed into C and extend with C. Python is relatively easy but still more difficult than Lua; this is perhaps to be expected because Lua was designed to do this, to a large extent.

What seemed straightforward in Python and complex in Lua? Just curious.

The best Lua tutorial I know of the "Programming in Lua" book, the first edition of which is available for free online at lua.org.

I'm actually not sure I'd recommend Lua to a newbie because you need a few more things to get it working. The standard libraries are quite small. I believe that Lua is better for embedding and for various reasons I prefer it as a language anyhow, but if you don't know how to take advantage of its strengths then you might as well not use it.

One of Lua's biggest strengths is its simplicity, with extremely clear extension semantics with metatables etc. This means that you can very easily make the language behave to a large extent as you want it to. Python gives you similar flexibility in some places, but the documentation is far inferior and involves tracking things down in various different places to piece together an answer.

Python is hardly a "bad" choice, though: EVE Online uses it extremely heavily not just for scripting but also to implement the vast majority of their game logic.
02 Jul, 2009, David Haley wrote in the 8th comment:
Votes: 0
Davion said:
Also make sure you find out how to sandbox the language so people who use the python scripting can't lay waist to your server.

I'm not sure I want to know what it means for somebody to lay waist with a language… :tongue:
15 Jul, 2009, MaineCoon wrote in the 9th comment:
Votes: 0
Is the scripting language for yourself, for your coders, or for any builder to be able to add behavior?

If it's intended for 'any builder to be able to add behavior' then you want a language that is very easy for people to pick up. It's hard enough teaching people about variables and simple if-then conditional blocks of code; trying to teach them to use a consistent indentation method is just compounding your headaches.

That is why you should not use Python as an embedded scripting language.
15 Jul, 2009, Runter wrote in the 10th comment:
Votes: 0
MaineCoon said:
Is the scripting language for yourself, for your coders, or for any builder to be able to add behavior?

If it's intended for 'any builder to be able to add behavior' then you want a language that is very easy for people to pick up. It's hard enough teaching people about variables and simple if-then conditional blocks of code; trying to teach them to use a consistent indentation method is just compounding your headaches.

That is why you should not use Python as an embedded scripting language.


I disagree. I think enforcing indention could be an extremely good thing for programmers (that's what they will be) who have no concept of the usefulness of writing maintainable, uniform code.

That being said, I'm not a python fan.
15 Jul, 2009, Idealiad wrote in the 11th comment:
Votes: 0
I agree with the spirit of MaineCoon's comment. If you want something easy for builders to pick up I would get rid of scripting altogether, and use OLC-defined templates for 'scripting'.

Also, as a beginning programmer, indentation in Python is the leastproblematic thing I have to deal with. ;D
15 Jul, 2009, Runter wrote in the 12th comment:
Votes: 0
Well, I don't think the debate of script or not to script will be settled today. I'll just say this—If you are going to script then python is a powerful, easy, intuitive choice after the fact.
16 Jul, 2009, MaineCoon wrote in the 13th comment:
Votes: 0
Runter said:
I disagree. I think enforcing indention could be an extremely good thing for programmers (that's what they will be) who have no concept of the usefulness of writing maintainable, uniform code.


You're welcome to disagree, however - having taught many newbies learning to program for the first time, I've discovered there's a huge difference between enforcing indentation, and actually getting users to understand when to use it and why. That's a whole lesson in itself, after you're done explaining what a variable is and what 'if/else' does.
16 Jul, 2009, Scandum wrote in the 14th comment:
Votes: 0
TinTin++ automatically indents when writing out scripts, and my mud's mob progs are highlighted when viewed from within the mud. Not sure if such a thing would be easy to do with Python or Lua, but when dealing with newbie programmers it's certainly a plus, and it also makes it easier to detect errors.
16 Jul, 2009, David Haley wrote in the 15th comment:
Votes: 0
It is basically impossible to automatically indent code when using a whitespace sensitive language. Consider the following lines of code:

def f(x, y):
if x > 2:
x = x + 1
x = x * y
return x

The example is contrived, but the point is made perfectly. Where do you put the line x = x * y? Do you put it inside the if block or not? In other words, do you assign x*y to x only when x > 2, or always?

Languages like Python basically have to be indented manually: you can sometimes "guess" as to what must happen (for example, a return statement must finish a block, and an if statement must start a new indentation level) but in general you cannot always infer where things must be indented.

Python's whitespace policy is actually one of people's biggest beefs with the language. It's extremely easy to make mistakes because you happened to forget to indent something; it's much harder to make that kind of mistake in a language that enforces explicit blocks.

(Also, I personally find that having block terminators makes a far better visual separation, and makes it easy to see where blocks start and stop, and especially which starts/stops correspond to which stops/starts.)
16 Jul, 2009, quixadhal wrote in the 16th comment:
Votes: 0
David Haley said:
def f(x, y):
if x > 2:
x = x + 1
x = x * y
return x

The example is contrived, but the point is made perfectly. Where do you put the line x = x * y? Do you put it inside the if block or not? In other words, do you assign x*y to x only when x > 2, or always?


I don't consider that a downside. Why do we bother to indent anyways? Because it makes the code clear and easy for others to follow. Except nobody seems to be able to agree on the stupidly nitpicking details of it.

if(x){foo();}else{bar();}

if(x) {
foo();
} else {
bar();
}

if(x)
{
foo();
}
else
{
bar();
}


All perfectly valid C code, but totally different in appearance. In such tiny examples, it doesn't matter, but go look at a decent sized codebase where you have a dozen levels of indentation, half of which use one style, half of which use another, and tell me again, how having a language-enforced level of consistency is such a horrible idea.

In the contrived example David presented, we can't know which parts he meant to include in the if statement, but the author presumably knew. The same can be said for this C code….

if(x)
foo();
bar();
if(y)
foobar();


Sure, it SAYS to always call bar(), but is that what the author meant to do, or did he just forget to put braces around the foo();bar(); calls? Does having the begin/end symbols help you there? In they python example, the compiler will probably fail to compile that, but if you indented everything below the def line one level, it would be valid… and just as confusing as the C example here.

Scanning a chunk of code that's hundreds or thousands of lines long, it's much easier to spot a change in the indentation level than it is a missing brace or END statement. If the language requires you to indent, you'll very quickly learn to indent. If not… well, I've dealt with a lot of really ugly (but functional) perl code that makes me wish it had been python.

Of course, this isn't an argument that can be won… but I feel compelled to point out that lack of enforced indentation can lead to exactly the same problems that forced indentation can. You can mitigate this somewhat if your language always requires begin/end symbols, but then people would complain about how cumbersome it is to write quick one-liners. :surprised:
16 Jul, 2009, Scandum wrote in the 17th comment:
Votes: 0
quixadhal said:
Of course, this isn't an argument that can be won… but I feel compelled to point out that lack of enforced indentation can lead to exactly the same problems that forced indentation can. You can mitigate this somewhat if your language always requires begin/end symbols, but then people would complain about how cumbersome it is to write quick one-liners. :surprised:

I've picked up the habit to always use braces which probably saved me a lot of trouble over the years.

Auto indentation in Python is possible because Python will know the internal indentation level, so it could write out the tokenized code indenting with 2 spaces, 1 tab, 4 spaces, etc. It'd be more like standardizing the indentation than adding indentation. On the other hand, I don't think the Python developers would understand the need for this functionality since it only makes sense for online development.
16 Jul, 2009, David Haley wrote in the 18th comment:
Votes: 0
Yes – you can solve this problem in C/C++/Java etc. by simply always using braces. It's a good habit to pick up.

Lua doesn't give you a choice, you must use explicit block terminators, e.g.:

if x > y then
return 2
end


Quote
Auto indentation in Python is possible because Python will know the internal indentation level, so it could write out the tokenized code indenting with 2 spaces, 1 tab, 4 spaces, etc. It'd be more like standardizing the indentation than adding indentation. On the other hand, I don't think the Python developers would understand the need for this functionality since it only makes sense for online development.

No, as I said, it is impossible in general to automatically indent Python code that isn't already indented. The example I gave is enough to show that. However it is true that the editors can make pretty good guesses most of the time, again as I said. But this is quite different from automatically indenting Python code in general.

quixadhal said:
In they python example, the compiler will probably fail to compile that, but if you indented everything below the def line one level, it would be valid…

I don't think it would be, as you must start a new indentation level after the if statement, or put the if-block on the same line.

quixadhal said:
In such tiny examples, it doesn't matter, but go look at a decent sized codebase where you have a dozen levels of indentation, half of which use one style, half of which use another, and tell me again, how having a language-enforced level of consistency is such a horrible idea.

Python doesn't enforce the style of indentation, just that indentation separates blocks. Nothing prevents one developer from using four spaces, another from using 3 spaces, another from using tabs, another from putting things on the same line as the if statement, and so on and so forth. The rule is that one block must have the same indentation through the block, but different blocks in the same function can mix indentation levels…
16 Jul, 2009, Scandum wrote in the 19th comment:
Votes: 0
David Haley said:
Quote
Auto indentation in Python is possible because Python will know the internal indentation level, so it could write out the tokenized code indenting with 2 spaces, 1 tab, 4 spaces, etc. It'd be more like standardizing the indentation than adding indentation. On the other hand, I don't think the Python developers would understand the need for this functionality since it only makes sense for online development.

No, as I said, it is impossible in general to automatically indent Python code that isn't already indented. The example I gave is enough to show that. However it is true that the editors can make pretty good guesses most of the time, again as I said. But this is quite different from automatically indenting Python code in general.

You're mistaken, for example:
if 1 + 1 == 2: print "foo"; print "bar"; x = 42

Could be auto indented as:
if 1 + 1 == 2:
print "foo"
print "bar"
x = 42


There's really no 'auto indentation' in the way you speak off (except for editors), because code is always indented by the parser according to the rules of the language. I understand your confusion, perhaps try to think of it as 'standardized indentation', though it doesn't matter a whole lot how you think of it. This because the concept is implicit when tokenized data is written back to file as untokenized data.
16 Jul, 2009, David Haley wrote in the 20th comment:
Votes: 0
My claim is that in general it is impossible. It is not logically correct to dispute that claim by showing one example where it is possible. There are many examples where it is possible. But it is not always possible, as my very short example above showed. There is no confusion on my part.

By the way, the parser is most certainly not the thing that is indenting the code. The parser is the thing using indentation to understand where blocks start and stop.
0.0/25