Why Strings as Classes?

Benji Smith dlanguage at benjismith.net
Mon Aug 25 17:52:04 PDT 2008


superdan wrote:
>> But the "small components" are the *interfaces*, not the implementation 
>> details.
> 
> quite when i thought i drove a point home... dood we need to talk. you have all core language, primitives, libraries, and app code confused.

The standard libraries are in a grey area between language the language 
spec and application code. There are all sorts implicit "interfaces" in 
exposed by the builtin types (and there's also plenty of core language 
functionality implemented in the standard lib... take the GC, for example).

You act there's no such thing as an interface for a builtin language 
feature.

With strings implemented as raw arrays, they take on the array API...

slicing: broken
indexing: busted
iterating: fucked
length: you guessed it

I don't think the internals of the string representation should be any 
different. UTF-8 arrays? Fine by me. Just don't make me look at the 
malformed, mis-sliced bytes. Provide an API (yes, implemented in the 
standard lib, but specified by the language spec) that actually makes 
sense for text data.

(Incidentally, this is the same reason I think the builtin dynamic 
arrays should be classes implementing a standard List interface, and the 
associative arrays should be classes implementing a Map interface. The 
language implementations are nice, but they're not polymorphic, and that 
makes it a pain in the ass to extend them.)

--benji



More information about the Digitalmars-d mailing list