• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to write a string to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to write a string to a file


  • Subject: Re: How to write a string to a file
  • From: Andy Lee <email@hidden>
  • Date: Tue, 19 Aug 2008 01:01:29 -0400

On Aug 18, 2008, at 11:28 PM, David wrote:
Thanks for the quick responses. Why isn't this already in NSString?I found
an old reference saying to use [filehandle writeData:[nsstring
dataUsingEncoding:...]]
This seems obtuse. I have been using Cocoa for 6 months and it is not
seeming any more consistent nor powerful than when I started.


I find Cocoa to be inconsistent with random pockets of powerful features
with many areas of spotty coverage of basic methods that I'd expect to be
present.

To a degree, I sympathize. You could certainly argue that a method like [myString appendToPath:myPath usingEncoding:NSUTF8StringEncoding] is useful and obvious enough that it should have been built into NSString in the first place. I think reasonable minds could disagree, but you could make the case (and, as Michael suggested, you can file a bug report requesting the method; I believe Apple has added convenience methods like this from time to time).


On the other hand: first, I think any API designer has to draw the line somewhere, especially with a class as widely used as a string class; when do you stop adding convenience methods? Second, as others have pointed out, Objective-C at least gives you the option to add this behavior yourself, via a category. Third, I think it's easy to find fault with any complex API that does things differently than you're used to. Sometimes this is due to a legitimately crappy API, and sometimes you just have to be a little more willing to go with the flow if you want to be successful on that platform, and while I can't promise this (I'm always reluctant to make statements like "you will see the light"), you *might* even be surprised to find it makes sense.

Cocoa isn't perfect, but it isn't just Cocoa. Back in the early 90's, I tried ParcPlace Smalltalk and was stunned a how crude the windowing APIs were -- at PARC of all places, the birthplace of the GUI. Today, as a Java programmer, I think it's odd that you need a utility class to sort an array instead of just telling the array to sort itself, and I can never remember all the combinations of Buffers, Writers, and Streams I need for various kinds of I/O. And it's been many moons since I wrote a UI in Java, but I thought it was pretty crude then too. So nobody's perfect.

That said, one of the things Cocoa developers like is actually its *consistency* -- the grammatical consistency of its naming conventions, the consistent application of a few design patterns, and so forth.

Some issues:
NSString includes lots of methods to work with paths, URLs, etc. This breaks
encapsulation.

No it doesn't. These methods do not reveal implementation details or allow other objects to muck with NSString internals.


It does not seem to be good design for NSString to have this
unique function dealing with paths. That should be in another class.

You could say the same thing about file operations.

Path operations are common enough, with enough annoying edge cases, that I'd think you'd be the first to welcome them in NSString.

I could go on, but I should stop. The method name makeKeyAndOrderFront
amazes me on NSWindow. It took me way too long to find that. It is my
current winner for least discoverable name.

The name makes perfect sense to me *now*, but if I must admit others before you have also gone hunting for that method.


--Andy


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How to write a string to a file (From: David <email@hidden>)
 >Re: How to write a string to a file (From: David <email@hidden>)

  • Prev by Date: NSView confusion
  • Next by Date: Re: NSView confusion
  • Previous by thread: Re: How to write a string to a file
  • Next by thread: Re: How to write a string to a file
  • Index(es):
    • Date
    • Thread