r/shittyprogramming • • Feb 07 '15

Arrays? Never heard of it.

Post image
319 Upvotes

35 comments sorted by

66

u/[deleted] Feb 07 '15

"prolaps1"

Ooookayyyy......

44

u/TheRealKidkudi Feb 07 '15

Also hardon_1 and cj_sex_sign1

44

u/Noneatme Feb 07 '15

That are Rockstar Game's in-game texture names

4

u/[deleted] Feb 07 '15

semi3dirty talk

1

u/VertigoShark Feb 07 '15

Too much shitty

1

u/marx2k Feb 07 '15

Project Rosebud

37

u/manghoti Feb 07 '15

It's not a slam dunk for arrays here. We're not seeing the whole block, it's possible there are cases half way down that prevent simpleminded looping, and you do see stuff like this when a list grows organically. A refactor may be needed, maybe not a loop.

Check out that commented out field, if you're doing something similar with arrays, you'd do something like this:

		[
			homies_1,
			homies_2,
			homies_3,
			--eris_1,
			eris_2,
			eris_3,
		]

so what are you saving here? lines? Not really, typing? This was copy pasted anyway. DRY concept, what if you need to change the behavior for each instance? Maybe an argument there, but it looks like the procedure is codified in a function, so the authors bases seem to be covered.

What WOULD merrit a loop was if the author could of obtained this information at runtime. If there is some folder of billboards that the author could just list out rather than codifying each entry in an array, then this would be shittyprogramming.

No need to assume the worst though.

17

u/Noneatme Feb 07 '15 edited Feb 11 '15

http://i.imgur.com/Rg5wxq6.png

Well heh, not really. The textures can be found in-game and I prefer --[[ "homies_01", ]], "homies_02" for commenting in one-line arrays.

"This was copy pasted anyway"

That's the problem sir

13

u/manghoti Feb 07 '15

I wrote a class for dynamic texture replacing and he didn't even used it

lol.

ahh well, can't be too hard on him, modding is often peoples first starts with programing, python too.

He might not understand classes and decided to just avoid fanciness.

8

u/Tynach Feb 07 '15

python too.

This isn't Python. /u/Noneatme, what language is this?

14

u/Noneatme Feb 07 '15

It's lua :p

10

u/HINDBRAIN Feb 08 '15

The --[[ syntax is kind of a tell!

I'm writing a Lua API for my job, learning the language, pleased at how noob-friendly it is to use.

1

u/[deleted] Feb 17 '15

Lua is surprisingly similar to javascript. Threre's tables, function expressions, ...

Best thing is how vararg and multiple return work IMO

2

u/manghoti Feb 07 '15

oops...

10

u/choikwa Feb 07 '15

python wasn't even close

2

u/expugnator3000 Feb 07 '15

At least they are both dynamically typed :P

2

u/Tynach Feb 08 '15

I keep meaning to learn Lua, but haven't yet. Thanks for the clarification!

1

u/pzduniak Feb 13 '15

This code looks quite Arabic :^)

5

u/supergnawer Feb 08 '15

Any copy-paste is inherently evil. You're going to assume that all copy-pasted segments are working the same. And eventually they won't. In this case, there could be something like this:

engineApplyShaderToWorldTexture(billboardLarge, "bobo_1");
engineApplyShaderToWorldTextur2(billboardLarge, "bobo_2");
engineApplyShaderToWorldTexture(billboardLarge, "bobo_3");
engineApplyShaderToWorldTexture(billboardLarge, "bobo_4");

It'll happen like this: some dude will come to this code to make a minuscule fix, he'll do it to cover his specific case, and then one day you'll spend 4 hours trying to figure out why one particular shader works weird. By doing it with array, you're robbing that guy of the opportunity to shit in your code, and forcing him to implement it in a human-readable way.

2

u/indyK1ng Feb 08 '15

Could have.

5

u/PlasticCan Feb 07 '15

I'm confused, could someone please explain what's happening and how an array would solve this problem?

24

u/Noneatme Feb 07 '15

local array = {"texture1", "texture2", "texture3" {...}} (It's actually a table)

for index, key in pairs(array) do engineApplyShaderToWorldTexture(shader, key) end

Done

9

u/PlasticCan Feb 07 '15

Oh right, it would require a lot less typing as well god how did I not realize.. Thank you so much for explaining!

4

u/drjeats Feb 07 '15

To be fair, multiple cursors sort of negates the effort of having to type or copy-paste the function call.

4

u/[deleted] Feb 07 '15

To not be fair. It is not very hard to assign these strings to Enums and do arrays.

2

u/shea241 Feb 08 '15

Probably shouldn't be building content in code if you really want to get down to it.

2

u/ryan_the_leach Feb 08 '15

it's probably generated.

2

u/MrDosu Feb 13 '15 edited Feb 13 '15

Tbh one would need to know on what platform/compiler this was built, but why on earth would I ever want to allocate a buffer that large for the array when all I need is a single stack variable at a time?

Ofc this looks ugly, but it is kinda easy to dismiss without knowing the full story.

TL;DR: If you refactor this for aesthetic reasons and I later find out I am now getting a ton of cache misses that did not happen before, you are getting fired.

1

u/bluehands Feb 07 '15

So bad my brain refused to see what he was trying to do....

"But there must be some reason that....I mean...well...OW!"

1

u/robhol Feb 08 '15

MTA? Wow. That takes me back.

1

u/jceyes Feb 08 '15

Is this coffeescript?

2

u/HeyThereCharlie Feb 12 '15 edited Feb 12 '15

Lua (I think)

1

u/UnspeakableEvil Feb 08 '15

I went to my manager to ask about arrays; he told me to wait until the new financial year.

0

u/slow_as_light Feb 08 '15

Is this the sloppiest possible tail call optimization, or an honest attempt to do a thing?

0

u/mhome9 Feb 10 '15

This is exactly why XNA doesn't exist anymore, and good riddance.