-
Notifications
You must be signed in to change notification settings - Fork 38
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
We need a named constant for 9223372036854775808 #79
Comments
9223372036854775807 is NSNotFound, a constant that Apple’s APIs are frequently using to indicate that there is no normal value (since in Objective-C ints, points, etc. cannot be |
Thanks, that’s interesting. This means:
That’s not satisfying, is it? |
Where are you getting 9223372036854775808? |
Now, that’s confusing. It took me a while to solve that puzzle: • Can’t be? Yes, it can. The reason is – as far as I figured out – that To me, this shows how hacky and fragile the current solution is. I feel uncomfortable working like this. |
The workaround is to check whether a value is equal to or less than |
Comparing floats is always a bit tricky. That's why I picked a (random) big (but smaller than NSNotFound) number as a threshold in the python code. As far as I understand, kerning values are stored as Int16, so the max value is 0x7FFF. So any value between that and NSNotFound is fine as threshold. |
Thanks for the explanations. I wouldn’t say comparing floats is always tricky, though. It would have been easy to define a large integer value (one that can be represented by a 32-bit float) as a named constant, let’s say NO_KERNING_VALUE or UNSPECIFIED_VALUE, then all code could safely check for equality instead of using a random threshold. This would make the code robust and readable. |
It might be better wrap the relevant methods so that they return But we can add a constant like |
It seems Glyph internally uses
9223372036854775808
, orLLONG_MAX
as ObjC calls it, in certain scenarios to indicate “no value” or similar. I believe it would be much cleaner to have a named constant for this, and proper documentation.For example, in my ObjC code, I am checking the return value of
kerningForFontMasterID:LeftKey:RightKey:direction:
againstLLONG_MAX
to determine whether a kerning pair exists. This has always felt like a dirty hack as it is undocumented and doesn’t use a clearly named constant. The Python wrapper simply usesif value > 1000000:
. That’s even worse IMHO, as if the value came from an unreliable external source, and needs a sanity check.The unit tests check some values against
9223372036854775807
(that’s a 7 at the end, i.e.LLONG_MAX-1
). Why is this? What is the meaning?Can I kindly ask to solve this in a cleaner, less hacky way by simply providing a named constant (in ObjC as well as Python). Thanks! – Tim
The text was updated successfully, but these errors were encountered: