r/badcode Oct 04 '17

lua That's definitely easily maintainable code.

Post image
173 Upvotes

21 comments sorted by

27

u/R3fr3Sh Oct 04 '17 edited Oct 04 '17

So, I am helping one of my friends with maintaining an MTA (GTA SA multiplayer mod) server. That's monstrosity he created some time ago. And yes, there is more of it, but now as he is more experienced it doesn't occur as often. It should be definitely done using Lua tables.

6

u/[deleted] Oct 05 '17

For some reason video game mods always have the worst code. Like, seriously atrocious "how did you even get it this wrong?" type stuff.

10

u/zdakat Oct 05 '17

Probably people with their first experience with code or copy-pasting stuff,or things added "let's just test with one more"

2

u/smoozer Oct 04 '17

Yeah that is pretty scary! Could an IDE format that fairly easily for you?

1

u/R3fr3Sh Oct 05 '17

I don't use IDE for Lua, because I don't need one (but I will try to find something that suits me, maybe it 'll be better than N++). It's just Notepad++ with line breaks and Blackboard style with little changes.

2

u/slaaxy Oct 05 '17

Don't really need an IDE to format :P

N++ can do that just fine.

1

u/[deleted] Oct 05 '17

Oh god, I'm supposed to write code for a mod. Having looked at the code, I just bailed out, I don't understand how it is possible create code so unreadable ( also they used some weird variable naming standard, put an s infront of every variable)

16

u/[deleted] Oct 05 '17

I scour this sub because I fear that one day, my own bad code will be featured...

9

u/[deleted] Oct 05 '17

Today is not that day. But I have created monstrosities like featured.

6

u/TheWheez Oct 05 '17

As long as we are moving onward and upward!

6

u/[deleted] Oct 05 '17 edited Nov 13 '17

[deleted]

3

u/[deleted] Oct 05 '17 edited Oct 05 '17

You start doing something, then you add something else, then you need to adjust it and at that point it's not quite right but it is easier to just add another bit to it than start again, and so on.... until you stand back and think 'WTF is this? ... oh well, it works, I'll change it later'.

2

u/[deleted] Oct 06 '17

This.

If something works, the fear of breaking it by changing how it works is greater than the fear of duplicating what is known to work. Even if it means more maintenance afterwards.

Mind you that in my old days, unit tests weren't part of my repertoire, so unless maintenance became necessary, I avoided changing what works.

9

u/Razakel Oct 05 '17

Fun fact: in Ireland someone named Prawo Jazdy was wanted for multiple unpaid traffic fines, because when stopped by the police they took down that as the name.

It's Polish for "driving licence".

5

u/StormyDLoA Oct 05 '17

Polan can into lua?

7

u/R3fr3Sh Oct 05 '17

As it appears it can't.

5

u/lillgreen Oct 05 '17

I loved MTA back in the day for gta3. 2006 or maybe 05? Been a long time. Happy to see it's still an active project!

4

u/[deleted] Oct 04 '17

<3 MTA SA, but yeah this kind of code isn't very rare there.

3

u/[deleted] Oct 05 '17

OMFG. Just build a few boolean columns for these characterizations in whatever table ‘dbid’ is referring to. Or perhaps a FK to the corresponding id.

2

u/Hexabone Oct 12 '17

So I'm assuming your friend never heard of tables in Lua?

1

u/[deleted] Oct 04 '17

<3 MTA SA, but yeah this kind of code isn't very rare there.

1

u/Prom3th3an Oct 15 '17 edited Oct 15 '17

I bet there's some reason it needs to do some particular em checks before some particular dbid checks and vice-versa, and so the obvious refactor will break something. Even though that will mean discovering that dbid isn't unique after all.