Why Two Integers Instead of One?


#1

In Tutorial 1.4 - Animate Text Labels using Spring Physics, on line 47 is a line of code that reads:

self.iPhoneLabel.center = CGPoint(x: 200, y: 90 + 200)

For “y:”, you entered “90 + 200” instead of just “290”. Is there any particular reason for entering the numbers that way?

Please advise,

Brian


#2

Doesn’t matter how you enter it. It’s only for you, so let’s say your starting value was 90, then you move it 200, so instead of 290 you can type 90+200 , so it’s clear you moved it 200…only visual…


#3

Hi ravenshore,

Thanks for the prompt reply.

So essentially it’s a “note to self” that you changed the starting value in the code.

Got it!

Brian


#4

I would agree with ravenshore that for learning purposes it doesn’t matter and is proably better to do it that way if it makes your code more clearer and easier to understand.

In your production code however, you might want to understand just how things are allocated as there are memory utilization and code generation differences between the two. In particular, in loops it is preferable to use constants where possible to avoid unnecessary computation.