I know about Turing equivalence and all (my name is literally Turing!) and computers are very fast these days, but it still shocks me to see someone talking about building a falling sand game, something that involves thousands of pixels being tracked i...
-
correction: it's a mutable array. Both arrays are mutable. but they throw one of them away every frame, rather than alternating them like double buffering
-
look it's important to ensure your garbage collector doesn't get bored, so you need to generate a bunch of interlinked objects every frame, if not in your inner loop
-
I've discovered that watching live-programming videos can give me the same secondhand embarrassment as watching people failing at puzzle games, because I can often see their bugs as they type them, and I'm like "that's not gonna work" but it takes them a few minutes to find out
-
@xris I guess!
I tend to assume anyone who is a programmer knows several languages. like everyone knows python + js + c + java/C#, right?
-
AHHH YOUR HSV RAINBOW IS DISCONTINUOUS BECAUSE YOU RESET VALUES >360 TO 1
-
remember children, if in your inner loop you need to refer to your array[y][x] multiple times, just type it out like that each time. array lookups are free! especially in a dynamic language like JS!
-
I know programmers who assign reused array lookups to temporaries and they're all cowards
-
I think other people trust their compilers a lot more than me.
I think I spend too much time looking at badly compiled code to assume my compiler is smart enough to know it should automatically grab array[y][x] to an implicit temporary
-
@foone A properly groomed compiler will do the right thing here, not just common subexpression elimination, but also down to replacing the multiplication for array index aslculation by an addition for monotonically increasing indices.
I'd write that in whatever way brings the most clarity to the human reader.
-
@andreasdotorg A well groomed compiler, sure, but JS? especially when it can't even be sure the array is sensible, since it's actually an array of array pointers, and who knows how those are laid out in memory?
-
Aren't you off by one? What is this, BASIC?
-
@tomjennings no, I'm not, they are!
-
@foone I'm cowards.
However, it's not always to help the compiler (though there is a ton of stuff that I do explicitly for this reason), but also just to help myself, by making the code more readable/writable.
-
@lunarood yeah that's the thing, I still do this when I'm pretty sure the compiler will inline/make a temporary. I just don't want to have to type array[y][x] multiple times when "tile" will do