Skip to main content
11 events
when toggle format what by license comment
Nov 3, 2015 at 12:01 history edited Tobias Beuving CC BY-SA 3.0
added link to article explaining technique in detail
Nov 3, 2015 at 11:11 comment added Tobias Beuving It's a matter of taste I am affraid. Don't get me wrong, I am all 100% for readability! But with high performance canvas drawing applications I stick to this approach (after doing it the way you're suggesting for a while).
Nov 3, 2015 at 11:04 comment added Dan s/loop/loop iteration
Nov 3, 2015 at 10:57 comment added Dan in short: player.dead player.x and player.y is significantly more legible than array[index].dead, array[index].x and array[index].y
Nov 3, 2015 at 10:56 comment added Dan Well, one of the principles of Law of Demeter is that a function may only ever access a.b or a.c, but never a.b.c. Ideally, the loop should be in a separate function for testing purposes which passes the function a.b, and then that function accesses b.c. Further, OP is reusing the variable array[index]. In my opinion, it makes more sense to assign that to a temporary variable to avoid extra lookups (even if they are O(1)) and to DRY up the code.
Nov 3, 2015 at 10:53 comment added Tobias Beuving If you like, you can suggest how I should rephrase my words and I will gladly update it. :)
Nov 3, 2015 at 10:51 comment added Tobias Beuving I say that in a short function like this, where performance is of the most importance, code should be concise as possible and prevail over readability. I understand that player.blabla reads nicer than playersToDraw[z].blabla, but there is just no need to make a copy of that variable (that references to the same value indeed)
Nov 3, 2015 at 10:45 history edited Tobias Beuving CC BY-SA 3.0
added link to explanation of the drawImage function
Nov 3, 2015 at 10:39 comment added Dan @ your point about copying the variable; objects are copied by reference. The difference between array[index].value and const host = array[index]; host.value are for legibility's sake only.
Nov 3, 2015 at 10:29 review First posts
Nov 3, 2015 at 10:32
Nov 3, 2015 at 10:28 history answered Tobias Beuving CC BY-SA 3.0