Live data from Hacker News

I open sourced my game along with a tutorial on how to make it using Lua

github.com

31–40 of 96 posts

Re: I open sourced my game along with a tutorial on how to make it using Lua

#32
post #20

Earlier 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…

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 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

#33
post #6

Earlier quoted context omitted.

1-index kept throwing me off though

How about this: The empty string and 0 are truthy. Why?

Maybe because all variables are `nil` by default, and checking on undeclared variables does not raise an error. So `if foo then ... end` is often used as an existence check, where `foo = 0` should be truthy.

Re: I open sourced my game along with a tutorial on how to make it using Lua

#34

Earlier 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,…

Fwiw Dijkstra practically invented bikeshedding

Re: I open sourced my game along with a tutorial on how to make it using Lua

#35
Cool project with awesome visuals!

It'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

#36
post #32

Earlier 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…

> 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.

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

#37
post #25

Earlier 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.

To save someone a search, here it is:

https://github.com/coronalabs/corona

Re: I open sourced my game along with a tutorial on how to make it using Lua

#39

Earlier 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

bikeshedding considered harmful

Re: I open sourced my game along with a tutorial on how to make it using Lua

#40
post #32

Earlier 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…

It's useful, if you are writing ternary search (over integers) or some such thing concerned with intervals, to be able to compute the length as hi-lo, and to be able to use hi<lo to check whether an interval is malformed, rather than writing hi-lo+1 and hi+1<lo. In the example about using modulo to place all integers into some interval upthread, most programming languages let you write (n-lo)%(hi-lo)+lo, but in Lua you should maybe write (n-lo)%(hi+1-lo)+lo. It doesn't seem like I am getting less likely to make errors here!
Post reply on HN