I open sourced my game along with a tutorial on how to make it using Lua
31–40 of 96 posts
Re: I open sourced my game along with a tutorial on how to make it using Lua
#32Earlier quoted context omitted.
You wouldn't end up with this: s:sub(0, #s) You would end up with: s:sub(0, #s - 1) Which demonstrates the off-by-one error.
Can you explain what the intent of the code is and what the error is? It looks like the original code just grabs a substring containing the entire string. If the language used half-open intervals with an exclusive upper bound, the code I posted would also do that. In python, for example, the operation of copying a list can be correctly written l[0:len(l)]. You're more likely to see l[::] or list(l) though. Edit: I th…
Lua does do that, so in this theoretical world with 0-indexed strings, it would still work as expected.
But it doesn't change the fact that you're not actually specifying the right length - the language is correcting an off-by-one error, which means that the programmer's mental model is probably going to be wrong, and it will bite them when they don't expect it to.
That's what off-by-one errors are - a place where the programmer's mental model doesn't actually fit the real world. It is better to not introduce places where they can happen in the first place, rather than to complicate things with edge cases where sometimes it works and sometimes it doesn't.
Re: I open sourced my game along with a tutorial on how to make it using Lua
#33Earlier quoted context omitted.
1-index kept throwing me off though
How about this: The empty string and 0 are truthy. Why?
Re: I open sourced my game along with a tutorial on how to make it using Lua
#34Earlier quoted context omitted.
The main problem with that decision is that every discussion having anything to do with Lua always devolves into repetitive bikeshedding about the 1-indexing.
In the context of language design, the arguments for 0-based indexing rise above bikeshedding. https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E... Sure it may not be the most critical point about language design, but it's not just bikeshedding either. For one thing, it is a language semantics issue rather than plainly syntax issue. I still like Lua, and maybe you don't even agree with Dijkstra's argument,…
Re: I open sourced my game along with a tutorial on how to make it using Lua
#35It's always interesting to see games published made with LÖVE in lua. I'm writing an "Advance Wars 2" clone at the moment in LÖVE and hope to get some inspiration from your code.
You seem to use a lot of global variables. Is that on purpose? I try to do as much as possible with local variables (although especially in game logic global entities are sometimes just the easiest way). I'm very wary of 1. global lookup overhead and 2. confusing errors when accidentally overwriting an existing global variable.
As I have never noticed both of these I'm not sure whether my angst is justified ;-)
Re: I open sourced my game along with a tutorial on how to make it using Lua
#36Earlier quoted context omitted.
Can you explain what the intent of the code is and what the error is? It looks like the original code just grabs a substring containing the entire string. If the language used half-open intervals with an exclusive upper bound, the code I posted would also do that. In python, for example, the operation of copying a list can be correctly written l[0:len(l)]. You're more likely to see l[::] or list(l) though. Edit: I th…
If the language is using an exclusive upper bound, then it is correcting the mistake of the programmer for specifying a length beyond what the string contains. Lua does do that, so in this theoretical world with 0-indexed strings, it would still work as expected. But it doesn't change the fact that you're not actually specifying the right length - the language is correcting an off-by-one error, which means that the p…
No, it's not-correcting the not-error of the programmer specifying the correct upper bound using the half-open-interval model, a common mathematical model of range specification that has lots of useful properties.
Re: I open sourced my game along with a tutorial on how to make it using Lua
#37Earlier quoted context omitted.
Check out (the now unfortunately named) CoronaSDK from (the also unfortunately named) Corona Labs. It's all Lua based and is now entirely MIT open sourced. One of the easiest to code cross platform development languages there is.
Renamed to Solar2D.
Re: I open sourced my game along with a tutorial on how to make it using Lua
#38Re: I open sourced my game along with a tutorial on how to make it using Lua
#39Earlier quoted context omitted.
In the context of language design, the arguments for 0-based indexing rise above bikeshedding. https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E... Sure it may not be the most critical point about language design, but it's not just bikeshedding either. For one thing, it is a language semantics issue rather than plainly syntax issue. I still like Lua, and maybe you don't even agree with Dijkstra's argument,…
Fwiw Dijkstra practically invented bikeshedding
Re: I open sourced my game along with a tutorial on how to make it using Lua
#40Earlier quoted context omitted.
Can you explain what the intent of the code is and what the error is? It looks like the original code just grabs a substring containing the entire string. If the language used half-open intervals with an exclusive upper bound, the code I posted would also do that. In python, for example, the operation of copying a list can be correctly written l[0:len(l)]. You're more likely to see l[::] or list(l) though. Edit: I th…
If the language is using an exclusive upper bound, then it is correcting the mistake of the programmer for specifying a length beyond what the string contains. Lua does do that, so in this theoretical world with 0-indexed strings, it would still work as expected. But it doesn't change the fact that you're not actually specifying the right length - the language is correcting an off-by-one error, which means that the p…