FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String Interface

 
Post new topic   Reply to topic     Forum Index -> Ares
View previous topic :: View next topic  
Author Message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Sat Dec 25, 2004 1:50 am    Post subject: String Interface Reply with quote

Regardless of whether or not you like the idea of a String class, I think one must agree that for those who want to use a String class, it's imperative that there be either one common String class, or a decent String interface. I think the latter is the way to go. As such, I've put together a very basic interface, IString. I'd like to revise it here, then present it to Walter and ask him to include it with Phobos, so people can standardize on it.

Code:
interface IString
{
   uint toHash();
   int opCmp(Object object);
   int opEquals(Object o);
   char opIndex(uint index);
   IString opCat(IString other);
   IString opCat(char[] other);
   IString opSlice(int start, int end);

   char[] toString();
   char* toCString();

   uint length();
   char charAt();

   IString dup();
   IString substring(uint start, uint end);
   IString substring(uint start);
   IString trim();
   IString toLower();
   IString toUpper();
   IString[] split(char sep);


   int compare(IString other);
   int compareIgnoreCase(IString other);
   int find(IString other, uint start=0);
   int rfind(IString other, uint start=uint.max);
   int indexOf(char c, uint start=0);
   int lastIndexOf(char c, uint start=uint.max);

   bit startsWith(IString other);
   bit endsWitch(IString other);
   bit contains(IString other);
}


It's just what I came up with in a few minutes. It also assumes that one wants to work with chars... there's probably a better (probably template based) way to deal with this, but I don't know how the template-interface stuff works (if at all).

What'cha y'all think?

John
Back to top
View user's profile Send private message Send e-mail AIM Address
andy



Joined: 15 Mar 2004
Posts: 71

PostPosted: Tue Dec 28, 2004 10:37 pm    Post subject: Reply with quote

I think it's a bad idea: the D standard library contains classes and functions for dealing with D concepts.

A string class/interface is not a D concept. Trying to cram it in is about as straightforward and elegant as writing C-styled code in Java.

(whether or not it should be so is subject to debate, but the odds of winning such a debate when it counts are rather slim Wink)
_________________
"Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Dec 29, 2004 12:35 am    Post subject: Reply with quote

I agree with Andy's perspective.

To get such an Interface adopted you (a) have to make it worthwhile, and (b) apply OO efforts toward a library other than Phobos.

Mango.icu.String leverages the vast Unicode ICU library in an attempt to get some traction (though I don't know of even one person using it), and an Interface around that has been discussed before. Mango.icu has also been offered to the Ares library for consideration.

Phobos is, uhhh ... interesting. Anyone with an eye for OOP will have to look elsewhere.
Back to top
View user's profile Send private message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Wed Dec 29, 2004 1:41 am    Post subject: Reply with quote

So without some sort of standard interface for strings in the standard library, how does one prevent issues with different libraries using different string classes? I'll soon be running into this issue with Mango and Dui. Dui uses it's own String class, and the mango.icu stuff uses UString. If both implement the interface, and have constructors that use the interface, then it makes everything a whole lot easier for me.
Back to top
View user's profile Send private message Send e-mail AIM Address
andy



Joined: 15 Mar 2004
Posts: 71

PostPosted: Wed Dec 29, 2004 2:34 am    Post subject: Reply with quote

The only thing I can suggest is to use char[] (or wchar[] or dchar[]) everywhere and only construct UString/dool.Strings when forced to at gunpoint, as it were.

I vaguely recall non-OO ICU bindings being worked on at some point. Working with them would probably be nicer, especially given the funny thing D does with functions that recieve an array as their first argument.

Code:
// The first argument of this function is an array, so
void foo(T[] x, char[] y) { ... }

T[] t = ...;
char[] s = ...;

// we can either use it like this
foo(t, s);

// or this (!!)
t.foo(s);

_________________
"Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Dec 29, 2004 11:12 am    Post subject: Reply with quote

teqDruid wrote:
So without some sort of standard interface for strings in the standard library, how does one prevent issues with different libraries using different string classes? I'll soon be running into this issue with Mango and Dui. Dui uses it's own String class, and the mango.icu stuff uses UString. If both implement the interface, and have constructors that use the interface, then it makes everything a whole lot easier for me.

Ant and I talked about making our stuff compatable via an interface. Currently, I understand that the ball is in Ant's court ... he's been pretty busy with other stuff though.

I agree that something needs to be done, and soon.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Dec 29, 2004 11:16 am    Post subject: Reply with quote

andy wrote:
I vaguely recall non-OO ICU bindings being worked on at some point. Working with them would probably be nicer, especially given the funny thing D does with functions that recieve an array as their first argument.

I'm confused, Andy ... can you provide examples whereby the application of OO is detrimental (or otherwise unwarranted) where something like ICU is concerned? My experience is otherwise.
Back to top
View user's profile Send private message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Wed Dec 29, 2004 11:19 am    Post subject: Reply with quote

Quote:
Ant and I talked about making our stuff compatable via an interface.


Good news for DUI and Mango users, but you can't hope to collaborate with all the string class writers should the community grow much more.
Back to top
View user's profile Send private message Send e-mail AIM Address
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Wed Dec 29, 2004 10:13 pm    Post subject: Reply with quote

teqDruid wrote:
Quote:
Ant and I talked about making our stuff compatable via an interface.


Good news for DUI and Mango users, but you can't hope to collaborate with all the string class writers should the community grow much more.
IMO, it's not good news yet for DUI/Mango users until Ant and Kris actually reach a compromise. Confused
Back to top
View user's profile Send private message AIM Address
andy



Joined: 15 Mar 2004
Posts: 71

PostPosted: Fri Dec 31, 2004 4:04 pm    Post subject: Reply with quote

kris wrote:
andy wrote:
I vaguely recall non-OO ICU bindings being worked on at some point. Working with them would probably be nicer, especially given the funny thing D does with functions that recieve an array as their first argument.

I'm confused, Andy ... can you provide examples whereby the application of OO is detrimental (or otherwise unwarranted) where something like ICU is concerned? My experience is otherwise.
The application of OO itself isn't detrimental at all so much as the fact that D's lack of implicit conversion places severe limits on the ways differing data types can interact.

Those limitations effectively doom any string interface to being clunky at best: all conversions to and from have to be explicit, which can lead to an awful lot of noise that doesn't actually convey any meaning, but is required regardless. C++ still suffers all kinds of silly issues revolving around this, despite the fact that it does allow implicit conversions.

Preferring the 'plain-old-data' string types over interfaces leads to fewer fights with the language, and, perhaps most importantly, a single, simple unified string. (except not, because of D's handling of ?char[] overloads with respect to string literals, but that's a fight for another day.....)
_________________
"Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Fri Dec 31, 2004 5:26 pm    Post subject: Reply with quote

andy wrote:
The application of OO itself isn't detrimental at all so much as the fact that D's lack of implicit conversion places severe limits on the ways differing data types can interact

It is a bit finicky. Sticking with, say, wchar[] as the internal format does tend to eliminate a lot of the noise you speak of (the ICU wrappers have minimal toX() conversions and/or constructors), but then induces limitations in other ways. There's unlikely to be ever a perfect solution in such cases, which is sad.

On the other hand, using a String class rather than just an array permits the addition of useful meta-data; such as COW controls. Oh well ... I guess we have to live with D as it is.

Cheers!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Ares All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group