Why Strings as Classes?
Jesse Phillips
jessekphillips at gmail.com
Mon Aug 25 19:23:26 PDT 2008
On Mon, 25 Aug 2008 20:52:04 -0400, Benji Smith wrote:
> 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
On the language spec vs standard library. While the GC is implemented in
the standard library, I do not believe the spec says it has to be (though
I don't think it is possible otherwise). So the spec could state that
strings should be implemented your way, but it shouldn't.
On another note. I must say this as been quite a turn around. There have
been many posts in the past with people arguing over having a String
class, I think they have been staying out. But none the less it is
nothing new.
More information about the Digitalmars-d
mailing list