I have so many questions (mainly because I lack understanding and context)
Whatās even going on here? Whatās the goal?
Just⦠what? Are those lists even used? What would they be used for?
Like, I have many more questions like āwhy make everything a list?ā But it really all depends on what the goal even is here.
I could imagine something like this for parsing data input from some sort of file or something⦠but even then, Iām confused why youād set up lists like this.
Edit: wait, wait, Iāve actually turned my brain on a little bit ( I was just browsing Reddit for animalsBeingDerps, ya know). So, instead of just⦠a list of references to object stamps, references to objects to edit, and position stamps, they separated everything out explicitly like this?
The lists are used for storing either the time (Stamps), Object Name (ObjectToEdit), And special behaviors (fade, position, rotation, etc.)
Yes and they were getting hard to remember and read so I just made a normal class for storing each type of list (timestamp, objectEdit, position, and all of thr other types of special behavior).
I should've known Unity C# is literally just C# i don't know why I acted like non-monobehavioural classes don't exist in Unity c#
Is the code that unreadable? I honestly don't think it is that much of an issue to have a few more lists. Plus classes have overheads and C# is not exactly known for its speed.
an ungodly amount of lists. There's a lot of the same list, (etc. Pos_ObjectToEdit, Rot_ObjectToEdit) can just be put into another public class with no MonoBehavior, with:
public List<string>ObjectToEdit = new List<string>();, and then create different instances of that class. It'd be much easier to track things and keep my code readable with that.
Plus, If i kept that, like, right now I'm thinking of adding Dimensions too from my Assembly, so the amount of lists will be even more chonky. I need to input an alternate way of streamlining the list amount/readability of this scrip
Classes have overhead. Besides, you will have the same amount of classes needed to be created, which is also slow. Sometimes ugly code is the fastest. Having lots of variables is not bad code
Maybe not bad but I guess you could have a class that takes just one from the list each or have lists in itself depending on how the variables are used. Doesn't change much more than readability but that's important too
Well you could have a Class "ObjectStamp" with all the variables like colour and size or what they were then you could have a list of ObjectStamp. Since I can't see the other code it's hard to tell what the code actually does
It would not make a big impact on the performance. And if performance is the issue a LinkedList could be marginally faster depending on how the list is used. Again it depends a lot on how the code is used that we don't see.
Google array of structures vs structure of arrays. The former is human friendly, the latter is cpu friendly. Above code is a bad example of the latter.
In computing, array of structures (AoS), structure of arrays (SoA) and array of structures of arrays (AoSoA) refer to contrasting ways to arrange a sequence of records in memory, with regard to interleaving, and are of interest in SIMD and SIMT programming.
I'll have you know an object of lists is preferrable to a list of objects in data oriented programming due to cache friendliness when iterating over a few properties of objects which happens often in simulations and games. (Jai (used to?) do this with all object types behind the scenes afaik).
42
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 31 '22
Image Transcription: Code
[The image shows code displayed in a file named
JSONBeatmapLoader.cs. The visible code reads as follows:]I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
25
u/Foo_Bar_Factory221 Dec 31 '22 edited Dec 31 '22
I have so many questions (mainly because I lack understanding and context)
Like, I have many more questions like āwhy make everything a list?ā But it really all depends on what the goal even is here.
I could imagine something like this for parsing data input from some sort of file or something⦠but even then, Iām confused why youād set up lists like this.
Edit: wait, wait, Iāve actually turned my brain on a little bit ( I was just browsing Reddit for animalsBeingDerps, ya know). So, instead of just⦠a list of references to object stamps, references to objects to edit, and position stamps, they separated everything out explicitly like this?
55
u/ProfCrumpets Jan 01 '23
If there needs to be 80 lists then there should be 80 lists, nothing wrong with that, really depends on the problem youāre solving.
7
u/zickige_zicke Jan 01 '23
Why is this bad code ?
25
u/miran248 Jan 01 '23
Google
array of structuresvsstructure of arrays. The former is human friendly, the latter is cpu friendly. Above code is a bad example of the latter.7
u/Miuzu Jan 01 '23
This actually isnāt such a bad idea. Although you could likely group these in a super structure with enum indexing. See the following:
https://en.wikipedia.org/wiki/AoS_and_SoA
6
u/Jimmy_cracked_corn Jan 01 '23
What is MonoBehavior? Iām not new to C#, but Iām also not a veteran and still learning
4
u/TTachyon Jan 01 '23
Welcome to data orienting programming. Just because it's harder to read doesn't mean it's bad.
1
u/seattleJJFish Jan 01 '23
Why stop at lists? Make them all maps!!
3
u/RomanRiesen Jan 01 '23
I'll have you know an object of lists is preferrable to a list of objects in data oriented programming due to cache friendliness when iterating over a few properties of objects which happens often in simulations and games. (Jai (used to?) do this with all object types behind the scenes afaik).
-3
u/F54280 Jan 01 '23
/r/inelegantcode