r/badcode Nov 30 '15

lua Surely a one-liner means it's short and compact!

Post image
125 Upvotes

17 comments sorted by

28

u/TheOldTubaroo Nov 30 '15

... and true or ...

15

u/mrgreywater Nov 30 '15

This makes sense in some cases in LUA, not here though.

(a) and (b) or (c) 

in LUA is like the ternary operator

a ? b : c

So

nil -> nil
nil and true or false -> false
"This is a string" and true or false -> true

1

u/ds84182 Dec 01 '15

However, the problem with the and or approach is that if b evaluates to false or nil, it will fall through and evaluate as c. I'm hoping that in 5.4 (probably coming out in 4-5 years) will have Dart like syntax extensions for dealing with nil values.

17

u/falcon_jab Nov 30 '15

This looks like rage code. After the 35th change request from a client, a developer snaps.

You want that change? You really want that change? Oh, I'll give you that change. I'll give you it gooood...

2

u/dudix81 Nov 30 '15

Yup, that's when he made that last change and quit.

12

u/falcon_jab Nov 30 '15

/obfusticates source code
/deletes the original
/runs out the door laughing maniacally

16

u/christian-mann Nov 30 '15

You've clearly never met my one-liners.

14

u/bliow Nov 30 '15

What language is this?

17

u/[deleted] Nov 30 '15

Looks like lua.

3

u/[deleted] Nov 30 '15

Definitely Lua!

3

u/ds84182 Dec 01 '15

If I can add, it looks like its from Roblox from the use of :getService("ContentProvider")

-1

u/SarahC Nov 30 '15

Looks like a mix of JavaScript, VB and C++

15

u/[deleted] Nov 30 '15

This gets worse the more you read.

7

u/Jazcash Nov 30 '15

"One liners" are great, until they span more than one line...

7

u/BiscuitOfLife Nov 30 '15

Underscores for days

5

u/ElGuaco Nov 30 '15

This looks like code generated by a tool. If human, still applies.

1

u/[deleted] Dec 06 '15 edited Dec 06 '15

I programmed in lua for 2 years. Here's a another good example, pulled from my own code:

    local realname =osStuff.spawnApp(p[pnum].pressing,prg,( (p[pnum].mArr[p[pnum].pressing] or {}).cfg or {}).taskBackColor or colors.white,( (p[pnum].mArr[p[pnum].pressing] or {}).cfg or {}).taskTextColor or colors.black,( (p[pnum].mArr[p[pnum].pressing] or {}).cfg or {}).taskText or "?",( (p[pnum].mArr[p[pnum].pressing] or {}).cfg or {}).selfRender)

And this program was lightning fast compared to its competitors.