Closed pczarn2 closed 11 months ago
@pczarn2 Do you know why Adobe recommends using floor instead of int? It would be useful to know the reason, for example does it support larger numbers than int?
@pfreitag I do not know the reason, all I saw on their page is a note that they discourage using it.
I think instead of "new applications", it should specify CF2016+.
Thanks @pczarn2 - I am going to post this on the CFML slack to see if anyone has any thoughts on it. I don't want to mark something discouraged without having a good reason for it.
@pfreitag I found below article today. Does this give a good reason? Would this be a good description?
"discouraged": "In new applications, use the Floor function instead of the Int function. int() should just return the integer part of a number, but instead it performs a rounding exercise instead. This means with negative numbers, it gets the answer wrong (https://blog.adamcameron.me/2016/02/coldfusion-2016-floor.html)."
@pfreitag And just a note I tried cffildle code below (reference: https://blog.adamcameron.me/2015/08/cfml-how-should-int-behave.html), results are -38 for int() (incorrect answer) and correct answer -37 for fix(), so maybe the description should be:
"discouraged": "In new applications, use the Fix function instead of the Int function. int() should just return the integer part of a number, but instead it performs a rounding exercise instead. This means with negative numbers, it gets the answer wrong (https://blog.adamcameron.me/2016/02/coldfusion-2016-floor.html)."
I am going to close this one, I don't feel that int()
should be marked as discouraged because I think discouraged should be for places where the developer should really consider rewriting the code. In the case of int, it is doing exactly what it is documented to do, Calculates the closest integer that is smaller than number.
so int(-3.4)
correctly returns -4
. Yes, there is now a better named alias floor
, and yes it should be used instead since it is more clear what it is doing, but if you are already using int()
I think that is fine.
I feel that adding discouraged is a strong warning, and I don't feel this case merits such a strong warning. Adobe / Lucee will never remove the int()
function, there are mountains of code that use it.
If people feel I am way off base here, I am happy to re-open and reconsider.
Added note about discouraged use of this function. Source: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-in-k/int.html