-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style question: bracket notation vs dot notation #9
Comments
It looks performance characteristics are about the same on many platforms, with a notable speed improvement on Safari: http://jsperf.com/dot-notation-vs-bracket-notation/2 This amount of speed increase for safari may be in the noise compared to more expensive steps like drawing. |
The most upvoted answer in Stack Overflow's "JavaScript property access: dot notation vs. brackets?" question concludes: Dot notation is faster to write and clearer to read. http://stackoverflow.com/questions/4968406/javascript-property-access-dot-notation-vs-brackets |
I agree that dot notation is more readable, so I would like to see us standardize on it and only use bracket notation when it is necessary to do so. |
Your jsperf didn't include the string concatenations (and thus JIT dynamic lookups that in the jsperf can be compiled to static references) that are going in in the above code. I think the dot notation will be faster in that specific case, and I prefer the dot notation style. |
+1 for dot notation. I especially don't like the style of bracket notation that uses string concatenation. |
In gravity and orbits code, I am seeing several instances that use the bracket notation for property access:
instead of the dot notation, here is the above rewritten with dot notation:
The latter (dot notation) is more consistent with the style we use throughout the rest of our code base, and it seems to me a bit easier to read. Is there a good reason to use the bracket notation? Should the sim be converted to use dot notation?
The text was updated successfully, but these errors were encountered: