FROM : Thomas Davie
DATE : Tue Dec 07 23:01:43 2004
On 7 Dec 2004, at 20:56, j o a r wrote:
>
> On 2004-12-07, at 19.25, Thomas Davie wrote:
>
>> I don't see why stringWithFormat is considered to be better than
>> stringByAppendingString...
>
> Only because I did in one line what you did in two. Just a little bit
> more readable (IMO), nothing more.
>
>> [NSString stringWithFormat:@"0123456789mc/\" %@", [[NSUserDefaults
>> standardUserDefaults] objectForKey:NSDecimalSeparator];
>> and
>> [@"0123456789mc/\" " stringByAppendingString:[[NSUserDefaults
>> standardUserDefaults] objectForKey];
>> are pretty much as readable as each other. In fact the second one
>> could be considered clearer because the reader doesn't have to scan
>> along the string to find the %@. They are equally efficient (they
>> both have to create and free two string objects). Is there a reason
>> to chose one over the other... Other than that the second is more
>> readable.
>
> That was my only point. And I agree, in the end the result would be
> the same - and it's of course also subject to personal preference.
>
> It might even be better to append the string, as you would avoid the
> pitfalls of having to think about what you pass as a format string
> (it's bad if it contains unexpected "%" characters...).
>
> I consider readability (and hence maintainability) to be very
> important, and something to really try to strive for - so it's worth
> thinking about.
I absolutely agree, I was really wondering if I had missed some subtle
semantic difference between the two, or if there was an argument
against the readability of stringByAppendingString.
Thanks a lot
Tom Davie
--
Computer Science is as much about computers as astronomy is about
telescopes -- Edsgar Dijkstra
DATE : Tue Dec 07 23:01:43 2004
On 7 Dec 2004, at 20:56, j o a r wrote:
>
> On 2004-12-07, at 19.25, Thomas Davie wrote:
>
>> I don't see why stringWithFormat is considered to be better than
>> stringByAppendingString...
>
> Only because I did in one line what you did in two. Just a little bit
> more readable (IMO), nothing more.
>
>> [NSString stringWithFormat:@"0123456789mc/\" %@", [[NSUserDefaults
>> standardUserDefaults] objectForKey:NSDecimalSeparator];
>> and
>> [@"0123456789mc/\" " stringByAppendingString:[[NSUserDefaults
>> standardUserDefaults] objectForKey];
>> are pretty much as readable as each other. In fact the second one
>> could be considered clearer because the reader doesn't have to scan
>> along the string to find the %@. They are equally efficient (they
>> both have to create and free two string objects). Is there a reason
>> to chose one over the other... Other than that the second is more
>> readable.
>
> That was my only point. And I agree, in the end the result would be
> the same - and it's of course also subject to personal preference.
>
> It might even be better to append the string, as you would avoid the
> pitfalls of having to think about what you pass as a format string
> (it's bad if it contains unexpected "%" characters...).
>
> I consider readability (and hence maintainability) to be very
> important, and something to really try to strive for - so it's worth
> thinking about.
I absolutely agree, I was really wondering if I had missed some subtle
semantic difference between the two, or if there was an argument
against the readability of stringByAppendingString.
Thanks a lot
Tom Davie
--
Computer Science is as much about computers as astronomy is about
telescopes -- Edsgar Dijkstra
| Related mails | Author | Date |
|---|---|---|
| Mark Dawson | Dec 7, 02:35 | |
| Byron Wright | Dec 7, 03:17 | |
| mark | Dec 7, 03:32 | |
| Sherm Pendley | Dec 7, 06:20 | |
| Thomas Davie | Dec 7, 12:55 | |
| j o a r | Dec 7, 13:27 | |
| Thomas Davie | Dec 7, 19:25 | |
| j o a r | Dec 7, 21:56 | |
| Thomas Davie | Dec 7, 23:01 |






Cocoa mail archive

