Skip to content
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

JavaScript Language worksheet: Bad coding practices in given code #10

Open
JoseUusitalo opened this issue Nov 4, 2015 · 0 comments
Open

Comments

@JoseUusitalo
Copy link

I believe in the function_returns_object.html the various randomly generated array indices in the makeCar() function use bad coding practices in the naming of the variables. The variables are named "rand1, "rand2", and so on. They are ambiguous because refer to an index of a specific array, not just any random number.

This does not cause a problem in the code at the moment as all of the arrays are the same length, but it could cause problems later if some of the arrays had different lengths. Because of the ambiguity it would be an easy mistake to use rand3 as the randomly selected color index and with arrays of differing lengths it would eventually cause undefined objects. It also takes unnecessary time to check which array each "rand" variable refers to.

Of course this is just a small and simple programming exercise but I believe it is still good to promote proper coding practices, especially in pre-written example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant