I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
Certainly! But with Javascript not having an int type, it can lead to unexpected bugs.
Sometimes the space between the declared variable and the loop fills up with other code, especially in a project that's not squeaky clean to begin with.
Or the variable was passed in as an argument to a function, and eventually someone calls the function with unexpected input.
Maybe a coworker wants to loop over something in batched chunks, and naively divides x by a chunkSize.
Assuming that x in while(x--) is an integer which will hit zero isn't necessarily bad, just something to be careful with.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
It's true that it is dangerous.
I see a reason to use tools (approaches) in related situations.
Construction without zero only in the case, when you know what you do. For example, iterate through array elements from the end:
or count input value as a number. In this case, input can be any, the function must know the type and cast to it. If float – make it as int by parseInt or Math functions.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
Honestly, I don't consider it bad practice myself. I agree with your sentiment. It's just that it's only bad practice in the context of the "long arrow operator".
I'll let others answer your original question for you. I'm sure it has turned up in one of the discussions at some point.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
In 12 years of the programming, I first hear about "long arrow" operator. It confuses beginners.
But you can do the same, in easy way:
Watch out with that notation though, it's best to only use it on integers declared as a constant.
You need to know what you are doing with your code.
Certainly! But with Javascript not having an int type, it can lead to unexpected bugs.
Sometimes the space between the declared variable and the loop fills up with other code, especially in a project that's not squeaky clean to begin with.
Or the variable was passed in as an argument to a function, and eventually someone calls the function with unexpected input.
Maybe a coworker wants to loop over something in batched chunks, and naively divides
x
by a chunkSize.Assuming that
x
inwhile(x--)
is an integer which will hit zero isn't necessarily bad, just something to be careful with.It's true that it is dangerous.
I see a reason to use tools (approaches) in related situations.
Construction without zero only in the case, when you know what you do. For example, iterate through array elements from the end:
or count input value as a number. In this case, input can be any, the function must know the type and cast to it. If float – make it as
int
by parseInt orMath
functions.Yup, that's definitely true. In cases when one has to decrement until any number other than
0
, I think the long arrow "operator" has its... "uses".Nowadays decrement and increment are bad practice. Consequently operator "long arrow" will be disappeared, and it's good.
If you don’t mind me asking, why are decrement and increment considered bad practice? They seem relatively simple and straightforward.
Honestly, I don't consider it bad practice myself. I agree with your sentiment. It's just that it's only bad practice in the context of the "long arrow operator".
I'll let others answer your original question for you. I'm sure it has turned up in one of the discussions at some point.
In whole context,