Inside, compilers usually break your code into a representation called "Single Static Assignment", where only one value is assigned to this variable, and all the operators are as simple as possible (compound elements are separated on different lines). A second example follows this approach.
Programmers sometimes write like that. It is considered the clearest way of writing code, since you can write all statements as basic tuples: the operator A = B C. But it is usually considered too verbose for code that is “obvious”, so it is an unusual style (outside of situations where you trying to make a very cryptic code understandable).
Generally speaking, programmers will not be embarrassed by your first example, and this is considered acceptable if you no longer need the original fileName . However, many Obj-C programmers encourage the following style:
NSString *fileName = [@"image" stringByAppendingString:@".png"]; NSLog(@"TEST : %@", fileName);
or even (depending on the horizontal space on the line):
NSLog(@"TEST : %@", [@"image" stringByAppendingString:@".png"]);
i.e. if you use only one variable once, do not name it (just use it in place).
However, if you adhere to the Single Static Assigment approach, you should not use tempName as the name of the variable, since it does not explain the role of the variable - instead, you should use something like fileNameWithExtension . In a broader sense, I usually avoid using “temp” as a prefix, since it's too easy to start calling all “temp” (all local variables are temporary, so it makes little sense).
Matt gallagher
source share