Text in D article

Daniel Keep daniel.keep.lists at gmail.com
Sat Nov 18 17:00:37 PST 2006



Max Samuha wrote:
> On Sun, 19 Nov 2006 02:43:10 +1100, Daniel Keep
> <daniel.keep.lists at gmail.com> wrote:
> 
>>
>> Max Samuha wrote:
>>> On Sat, 18 Nov 2006 15:59:33 +0100, Alexander Panek
>>> <a.panek at brainsware.org> wrote:
>>>
>>>> PDF would be great, too.
>>>>
>>>> Tydr Schnubbis wrote:
>>>>> Daniel Keep wrote:
>>>>>> Here's a draft of an article which, hopefully, will explain some of the
>>>>>> details of how text in D works.  Any constructive criticism is welcomed,
>>>>>> along with edits or corrections.
>>>>>>
>>>>> Any chance of an .rtf, .doc, or even .txt? :)
>>> For those who is still on Windows :), thiere is a free and compact doc
>>> viewer that supports the open office format
>>> http://www.officeviewers.com/ 
>> Hey, *I'm* still on Windows :P
>>
>> 	-- Daniel
> 
> Daniel, I didn't intend to offend you, really. Sorry, if I did.

None taken at all.  Hence the ":P" -- OpenOffice.org *does* work on
Windows quite nicely :)

> The article is great and useful. I would add a note for those coming
> from C# (and Java?) that D strings are mutable and doing the following
> is a bad idea:
> 
> class BlackBox
> {
> 	private char[] _text;
> 	
> 	this()
> 	{
> 		_text = "object state";		
> 	}
> 
> 	char[] text()
> 	{
> 		return _text; // should be 'return _text.dup' if you
> don't want the user of the object to change the internal _text;
> 	}	
> }
> 
> Or something like that.  

Perhaps.  This was basically written to be a quick look at all the
things people expect to work, but don't.  To be honest, I've never had
this problem since strings are arrays and arrays are passed by reference
and thus can be mutated.  But then, maybe not everyone catches that
first time :P

I'll definitely give it some thought.

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list