[M3devel] text inefficiency? good mutable string type? arrays?
Jay
jayk123 at hotmail.com
Wed Feb 27 00:57:59 CET 2008
Right that arrays of chars/widechars make good strings, however you run into the problem of what is the ubiquitous type that is good to have around because any other code can deal with it. It's often nice to have fewer types and therefore more easier interoperability among code -- avoid any thick translation layer or conversion of data back and forth. It's tough though of course, since not one size (type) fits all.
It seems annoying and wasteful, but also plain ok, for everyone to have their own string, array, list, etc. types.
My "crazy" view though is that it is better to have one string class per programmer than any programmer with no string type to use. Fewer types/libraries would be preferable, but the alternative of anyone having none is worse.
It is easy enough to write these things for yourself if there really is no acceptable existing option. (though the ease with which folks dismiss existing alternatives is also bad)
Some people claim they need to leave the writing of string/array/list to the super-skilled library developers, but I don't think so. The line between library producer and library consumer is not always so clear. I may not be capable of whipping together a windowing system or a threading library or compiler, but string and growable array are plenty easy enough. :)
Sometimes the library writers aren't even so good.. I remember reading, if I interpreted it correctly, how the Python developers were so proud of their growable arrays that are so efficient because they grow in chunks of constant size larger than 1...except that's not actually how you write an efficient growable array, you have to grow exponentially -- by a factor greater than 1, such as 2 or 3 or 1.5. This is for the scenario of folks adding one element at a time.
I also found Modula-3 arrays to be a little disappointing so far. Could be me at this point.
I'd like to be able to change their length and possibly remove elements from the start without a copy.
I suppose that involves a dreaded "interior pointer" and gc problems.
I know SOME about SUBARRAYS but so far, it seems SUBARRAY can only be passed as parameters or use in "surprisingly powerful" assignment: subarray(a, offset, length) := subarray(b, offset, length). It seems I cannot assign, like, a subarray to a reference. a: array [0..9] of integer, b : ref array [8..9] of integer := subarray(a, 8) ? I'll have to look into that too..
Really I was going to try to shut up today at Randy's request but folks responded.. :)
- Jay
> Date: Tue, 26 Feb 2008 17:14:31 -0600> From: rodney.bates at wichita.edu> To: m3devel at elegosoft.com> Subject: Re: [M3devel] text inefficiency? good mutable string type? arrays?> > Mutating the Text implementations certainly could subvert the expected> semantics of TEXT, for other TEXT values you might not expect to have> any relation to what you are doing.> > But in my view, the much more important point is that ARRAY OF CHAR/> WIDECHAR, where you create your own values, are the mutable strings> in Modula-3. You can pretty much do anything you want with this,> including writing your own string abstraction, with different internal> representation. In fact, I have done so, highly tailored to an> application with specific, known performance characteristics and> usage patterns.> > Jay wrote:> > Is that legal or is that subverting things?> > It depends on the context?> > Can the pointers be to read only memory in the code?> > > > - Jay> > > > > > ------------------------------------------------------------------------> > > > > From: hosking at cs.purdue.edu> > > To: mika at async.caltech.edu> > > Date: Tue, 26 Feb 2008 15:16:47 -0500> > > CC: m3devel at elegosoft.com> > > Subject: Re: [M3devel] text inefficiency? good mutable string type? > > arrays?> > >> > > ARRAY OF CHAR/WIDECHAR?> > >> > > These are available in the various Text implementations. For exampe,> > > Text8.T.contents. One can freely mutate these at leisure and the> > > higher-level text will appear to change!> > >> > > On Feb 26, 2008, at 2:22 PM, Mika Nystrom wrote:> > >> > > > Olaf Wagner writes:> > > >> Quoting Jay <jayk123 at hotmail.com>:> > > >>> > > >>> I know this area has been brewing under the surface a while.> > > >>> I'll bring it up. :)> > > >>>> > > >>> I assume texts are read only?> > > >>> > > >> Yes.> > > >>> > > >>> I know lots of systems have read only strings.> > > >>> There are pluses and minus to them. They can be single-instanced.> > > >>> Some systems with read only strings have another type, such as> > > >>> "StringBuilder" or "StringBuffer".> > > >>> So -- I don't have a specific question, but maybe a mutable string> > > >>> "class" aka "type" is needed?Not necessarily in the language but in> > > >>> m3core or libm3?> > > >>> Maybe it's already there?> > > >> > > > CharSeq.T?> > >> > > > > > ------------------------------------------------------------------------> > Climb to the top of the charts! Play the word scramble challenge with > > star power. Play now! > > <http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan>> > -- > -------------------------------------------------------------> Rodney M. Bates, retired assistant professor> Dept. of Computer Science, Wichita State University> Wichita, KS 67260-0083> 316-978-3922> rodney.bates at wichita.edu
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080226/3a4ecc24/attachment-0002.html>
More information about the M3devel
mailing list