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

Mutable constants in question.js file #232

Open
BrianHCombes opened this issue Apr 30, 2018 · 3 comments
Open

Mutable constants in question.js file #232

BrianHCombes opened this issue Apr 30, 2018 · 3 comments

Comments

@BrianHCombes
Copy link
Contributor

By all appearances the declared variables at the top of file question.js are intended to be CONSTANTS but are currently mutable. Recommend configuring them as immutable.
Below is the observed code:
`var CHOICE_IS_CORRECT_AND_CHOSEN = 1;
var CHOICE_IS_CORRECT_BUT_NOT_CHOSEN = 2;
var CHOICE_IS_INCORRECT_AND_CHOSEN = 3;
var CHOICE_IS_INCORRECT_AND_SEQUENCE = 4;
var CHOICE_IS_PHRASE_AND_WE_CANT_TELL_YET = 5;
var CHOICE_IS_FROM_QUESTION_TYPE_SET = 6;
var CHOICE_IS_INDETERMINEDLY_ANSWERED = -1;

var QUESTION_TYPE_SINGLE = 1;
var QUESTION_TYPE_MULTIPLE = 2;
var QUESTION_TYPE_PHRASE = 3;
var QUESTION_TYPE_SEQUENCE = 4;
var QUESTION_TYPE_SET = 5;

var UI_ID_Generator = (function() {
var my = {};

my.getNewId = function() {
	return (Math.floor(Math.random() * 9999) + 1) + '';
};

return my;

}());`

@haxwell
Copy link
Owner

haxwell commented May 3, 2018

So, a common paradigm you will run into in all code, is that if a variable name is in CAPS, its a constant. Sometimes, as in this case, you could assign a value to it, and therefore mutate it, change its value. But then the stuff after it wouldn't necessarily work. So we don't do that.

Did you know you can change the value of undefined to something other than undefined? Its true.. Javascript lets you.. look it up. :)

But why would you do that?

I do agree with this issue in principle, and once we move to ES6, we can start doing it in practice, by using the const keyword. Till then, just avoid the temptation; don't change them. :)

@BrianHCombes
Copy link
Contributor Author

Confirmed we keep as is. Yup, that's the way I've typically looked at CONSTANT declarations and have known it's a chosen syntactical format to capitalize them. Yes, if my recollection is proper, declaring a variable like var myVar; is declared but undefined until it's assigned a value like myVar = "myValue"; and also knowing it can be assigned any value like: string, num, object, array, etc. Thanks for the discussion!

@BrianHCombes
Copy link
Contributor Author

Oh, yes, that was in Javascript of course.

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

2 participants