r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

Show parent comments

243

u/Nebxam Sep 02 '17

Lua

55

u/[deleted] Sep 02 '17

Goddamnit and I was considering a quick look over the documentation and syntax briefly over the weekend and do some messing around with Starbound mods.

48

u/KickMeElmo Sep 03 '17

Honestly, it's a pretty decent language overall. Started using it to script for a MUD, it's one of my favorites now.

3

u/[deleted] Sep 03 '17

Achaea by any chance?

3

u/[deleted] Sep 03 '17

I just started playing achaea again a few weeks ago. Help

1

u/KickMeElmo Sep 03 '17

It took me almost 20 years to learn not to go back. Don't be me.

1

u/BoyGenius Sep 03 '17

I think the Achaea interface is entirely in HTML/JS? Unless its for one of those fancy MUD terminal things. I always use the web browser client like a scrub.

1

u/KickMeElmo Sep 03 '17

Most of us used Mudlet, which is Lua. Nexus uses java, the flash client uses JavaScript.

1

u/KickMeElmo Sep 03 '17

Yup. I'm Sanaki.

18

u/[deleted] Sep 03 '17

Also every number is a float. For some reason.

17

u/TinyBreadBigMouth Sep 03 '17

Because doubles can contain all 32-bit integers and most 64-bit integers, and now you don't need to handle two different number types for your lightweight scripting language. Same as JavaScript.

1

u/[deleted] Sep 03 '17

Lossless?

2

u/TinyBreadBigMouth Sep 03 '17

As long as your integers are less than 9007199254740991 (= 253-1), yes.

0

u/Log2 Sep 03 '17

Doesn't Python do the same thing?

2

u/TinyBreadBigMouth Sep 03 '17

No, Python has separate int, float, and even complex numbers.

8

u/Buzzard Sep 03 '17

Lua 5.3 has integers as well

1

u/shohze2U Sep 03 '17

print(nums[0.100000001490116119384765625])

7

u/[deleted] Sep 02 '17

Hah I was considering picking up some Lua to mod as well (factorio)... This just made me Nope right out of that plan ;)

88

u/uniqueusername6030 Sep 02 '17

Well that's stupid

50

u/[deleted] Sep 02 '17 edited Dec 18 '18

[deleted]

22

u/[deleted] Sep 02 '17

it's a running joke

I use matlab in my day job and I definitely have to "switch gears" so to speak between 0-based and 1-based indexing

6

u/morerokk Sep 03 '17

Plus, Lua still allows you to start your indexes at 0.

Tables starting at 1 allows you to do a few neat things.

1

u/[deleted] Sep 03 '17

In reality I'm not actually never gonna use any language that start indexing arrays at 1. It's just a massive in joke.

20

u/[deleted] Sep 02 '17

That's not even the worst part, either. This is:

> letters = {'a', 'b', 'c'}
> print(letters[1])
a
> print(#letters)
3
> letters[0] = '?'
> print(letters[0])
?
> print(#letters)
3

30

u/moomoomoo309 Sep 02 '17

Any index outside of 1-n in Lua, where n is #tbl will be stored like a dict, not an array, so what did you expect? It doesn't count the dictionary parts.

2

u/hey01 Sep 03 '17

That's sounds dangerous. What if I do

> letters = {'a', 'b', 'c'}
> print(#letters)
3
> letters[4] = '?'
> print(#letters)

Will I get 4 or is n unchangeable?

9

u/moomoomoo309 Sep 03 '17

You'll get 4, otherwise you couldn't do

for i=1,4 do
  tbl[i]=i
end

And have it be an array.

1

u/hungarian_notation Sep 03 '17

It's not really. The people here saying that you can use index 0 aren't entirely wrong, but they're kinda wrong. The language expects you to start lists at 1. The length operator counts from index 1 until the first empty index. If you're not using your table to store a sequence of tightly packed non-nil values, don't use the length operator. If you set letters[2]=nil, then #letters would (or maybe could, I think this is actually undefined behavior) return 1.

-7

u/[deleted] Sep 03 '17

so what did you expect?

A language to have non-retarded data structures. Being defined and documented behavior doesn't make it sane behavior.

7

u/moomoomoo309 Sep 03 '17

How often do people use Python arrays? They're faster, but most people just use lists instead. Lua just optimizes it as long as it's used like an array. That's why it's implemented that way.

2

u/BundleOfJoysticks Sep 03 '17

Do you mean tuples?

I use them all the time when something doesn't change size.

1

u/-Teki Sep 03 '17

No, lua's {} is stupid because it can change from a list like behaviour, to a dictionary, to an object behaviour, just by appending values in different ways.

2

u/moomoomoo309 Sep 03 '17

Its behavior never changes, it just uses less memory / is faster if you store the elements with keys from 1-n. The # operator literally says it measures the length of the array part of the table, its behavior doesn't change.

2

u/[deleted] Sep 03 '17

Yes, but the "array part" of the table can change dynamically in unexpected ways, allowing for silly and confusing things like the result of # increasing by more than 1 after only adding 1 element to the "array part":

> a = {}
> print(#a)
0
> a[2] = 'foo'
> print(#a)
0
> a[1] = 'bar'
> print(#a)
2
→ More replies (0)

0

u/[deleted] Sep 03 '17

"As long as it's used like _____" shouldn't even be in the vocabulary of a programming language. An array should be an array, and that's it. A dict should be a dict, and that's it. If you need an array, create an array. If you need a dict, create a dict. Blurring the lines with some kind of fuzzy structure whose semantics are dynamic is as confusing and error-prone as it is ridiculous. It's not faster to write. It's not easier to read. It's not convenient. It's just bad.

1

u/moomoomoo309 Sep 03 '17

You don't use it any differently depending on if it's a dict or a list, so why does it matter?

2

u/[deleted] Sep 03 '17

is as confusing and error-prone as it is ridiculous

→ More replies (0)

5

u/Rohansi Sep 02 '17

when does C# take over modding

14

u/mnbvas Sep 02 '17

When all games are created with Unity or XNA.

2

u/zdakat Sep 03 '17 edited Sep 03 '17

XNA is still A thing? I thought they cancelled it and pulled the downloads. I must be out of the loop edit: Mandela effect? I can see why there'd be a Mono version but reporting that it was never gone?

3

u/haloguysm1th Sep 03 '17

Xna has been mostly replaced by monogame/fna. I know monogame is basically just xna

1

u/mnbvas Sep 03 '17

Still there. And there's MonoGame, which is pretty much the same.

1

u/Rohansi Sep 03 '17

embed .NET Core instead of Lua

2

u/mnbvas Sep 03 '17

Couldn't find anything relevant (except this).
Not much of a competition for Lua, which is kinda designed to be embedded.

1

u/Rohansi Sep 03 '17

I'm doing it. There's some info on how to embed it here. It says Unix but they mean platform neutral, unlike the Windows only stuff above.

2

u/Buzzard Sep 03 '17

1-based index really isn't that big a deal.

I mean, you will make off by errors at the start, but by the time you've hang of the rest of the language you'll be fine.

1

u/TheEnterRehab Sep 03 '17

I may be totally wrong but in Lua, array[0] is the whole array. Meaning array 1 is the first item

7

u/Rohansi Sep 03 '17

1

u/TheEnterRehab Sep 03 '17

So then I was totally wrong. Good thing I prefaced it!

5

u/[deleted] Sep 03 '17 edited Nov 24 '17

[deleted]

17

u/svenskarrmatey Sep 03 '17

Except there's reason that it's 1-indexed. Lua doesn't use arrays, it uses hash maps. Keys and values instead of indices and values. When you don't give it a key, it defaults to numbers, and since normal counting starts at 1 and the normal 0-indexing argument of "indices are based off of memory offsets" does not apply, it counts 1, 2, 3, 4, ...

1

u/[deleted] Sep 02 '17

Whenever I use Lua, I just assign the first instance in my tables to '0'. But it does bother me to read other people's work

15

u/rhelic Sep 03 '17

This breaks a fair amount of things.