digitalmars.D - Fractal
- Standard library (31/31) Jun 08 2009 Hello
- Fractal (1/1) Jun 08 2009 Oh... I have swapped the user name with the subject :)
- Jarrett Billingsley (36/67) Jun 08 2009 ML) ... but they do not have the design I'm looking for
- bearophile (8/9) Jun 08 2009 The printing functions of Tango are nearly trash for me, I don't like ho...
- Fractal (3/14) Jun 08 2009 Thanks bearophile for your response... please tell me what you think abo...
- Fractal (8/16) Jun 08 2009 Me... but if I use another API, it can create one indirectly.
- Frits van Bommel (8/18) Jun 08 2009 IIRC, Chinese characters can't be represented by a single wchar. However...
- Robert Fraser (4/35) Jun 08 2009 I'd recommend using char[] for everything (unless you're calling Windows...
- Leandro Lucarella (13/32) Jun 08 2009 I recommend this small but very enlightening article if you know nothing
- grauzone (11/12) Jun 09 2009 In case this wasn't already clear enough: char[] _is_ a Unicode string.
- Walter Bright (3/5) Jun 09 2009 Being not required in C makes it pretty much a disaster to use UTF-8.
- Fractal (3/25) Jun 08 2009 Thanks for the correction... then adding a String struct to simplify it?
- Robert Fraser (8/11) Jun 08 2009 Why? char[] _is_ a string. wchar[] and dchar[] are basically there for
- Fractal (3/4) Jun 08 2009 Because I want the same string handling that any modern language has, fo...
- Fractal (2/24) Jun 08 2009 Thanks for the correction... Maybe adding a String struct?
- Fractal (13/13) Jun 08 2009 Some things that i want for a Standard Library are:
Hello Phobos or Tango? In fact, both have the functionality that I need (except Phobos has not XML) ... but they do not have the design I'm looking for For example: Stdout("message").newline // Stdout is a function, or a global variable of a class? opCall is an operator for functions? or for printing? In addition, the Tango IO only caused problems to me. Also there are many unnecessary global class instances (like stdout and Trace... why not only Trace?)... All programs will have many instances Format! (wchar) in memory, only because theyr functions arent static. Also why use many templates for char, wchar, and dchar? instead use only wchar. I cant print an exception in Spanish (my language), because Exception msg is char[] and not wchar[]. What I'm looking for, is an API that more than running fast, have design and elegance. I like the idea of mixing the power of D with an API like .NET base classes. For example it solves many GC design problems with IDisposable. Then when writing code, do a simple look if an object implements that interface, and call that method when the object is no longer necessary (to clean everything that is done with a C API). It has its big and unique problems, (like the streams Close method and Dispose), but they can be solved while translating it to D, but also they can be redesigned and enhanced. Power, Speed and Native + Portable and Elegance. PD: currently I dont use .NET because it is only for Windows. At the same time I finded D, and Mono, but I prefer D. I apologize if this sounds offensive... Only I want is that D will be a better alternative for the peopple that was passed years translating code from one to other platform because a "little" design problem, makes the write operation of a big program, an inelegant and difficult to read code. At the time, while I used Tango, I writed a little IO API, that was taked some design from .NET and Tango. With it, write a file can be done with something like this: scope auto fileStream = new FileStream("file.dat"w, FileAccess.Discard, 256); // creates an empty file, and the magic number 1024 is the stream buffer size, if it is skipped is 1024 by default (can be zero). scope auto output = new BinaryOutput(fileStream); // this filter can write binary data, and swap bytes for little endian and big endian struct SampleData { int a; wchar[] b; int c; Color d; // an other struct } output.put(SampleData(0, "hello world"w, 2, Color.White)); // this gets the struct tuple and writes each element recursively. fileStream.dispose(); // flush buffered contents and close the file I think that this little library can be expanded to a complete Standard Library for D. What do you think? Thank, and sorry for my bad english.
Jun 08 2009
Oh... I have swapped the user name with the subject :)
Jun 08 2009
On Mon, Jun 8, 2009 at 6:14 PM, Standard library<happyprogramming server.com> wrote:Hello Phobos or Tango? In fact, both have the functionality that I need (except Phobos has not X=ML) ... but they do not have the design I'm looking forFor example: Stdout("message").newline // Stdout is a function, or a global variable o=f a class? opCall is an operator for functions? or for printing? It works, doesn't it? How is "Console.WriteLine(...)" any better?In addition, the Tango IO only caused problems to me. Also there are many=unnecessary global class instances =A0(like stdout and Trace... why not on= ly Trace?)... All programs will have many instances Format! (wchar) in memo= ry, only because theyr functions arent static. If you create a single instance of Format!(wchar), you won't have that prob= lem.Also why use many templates for char, wchar, and dchar? instead use only =wchar. Because those are the three string encodings D supports, and only supporting one is a dumb idea.I cant print an exception in Spanish (my language), because Exception msg=is char[] and not wchar[]. You can throw an exception in Spanish. char[], wchar[], and dchar[] are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.What I'm looking for, is an API that more than running fast, have design =and elegance. I like the idea of mixing the power of D with an API like .NE= T base classes.For example it solves many GC design problems with IDisposable. Then when=writing code, do a simple look if an object implements that interface, and= call that method when the object is no longer necessary (to clean everythi= ng that is done with a C API).It has its big and unique problems, (like the streams Close method and Di=spose), but they can be solved while translating it to D, but also =A0they = can be redesigned and enhanced.Power, Speed and Native + Portable and Elegance. PD: currently I dont use .NET because it is only for Windows. At the same=time I finded D, and Mono, but I prefer D.I apologize if this sounds offensive... Only I want is that D will be a b=etter alternative for the peopple that was passed years translating code fr= om one to other platform because a "little" design problem, makes the write= operation of a big program, an inelegant and difficult to read code.At the time, while I used Tango, I writed a little IO API, that was taked=some design from .NET and Tango. With it, write a file can be done with so= mething like this:scope auto fileStream =3D new FileStream("file.dat"w, FileAccess.Discard,=256);// creates an empty file, and the magic number 1024 is the stream buffer =size, if it is skipped is 1024 by default (can be zero).scope auto output =3D new BinaryOutput(fileStream); // this filter can write binary data, and swap bytes for little endian an=d big endianstruct SampleData { =A0 =A0 int a; =A0 =A0 wchar[] b; =A0 =A0 int c; =A0 =A0 Color d; // an other struct } output.put(SampleData(0, "hello world"w, 2, Color.White)); // this gets the struct tuple and writes each element recursively. fileStream.dispose(); // flush buffered contents and close the file I think that this little library can be expanded to a complete Standard L=ibrary for D. What do you think? Please, two libraries are enough. No m=E1s.
Jun 08 2009
Jarrett Billingsley:It works, doesn't it? How is "Console.WriteLine(...)" any better?<The printing functions of Tango are nearly trash for me, I don't like how they are imported, the structure of the hierarchy where they are collocated in modules/packages, their duplication, their name, their API and usage. They are also unsafe. (C std.c.stdio.printf is better, cleaner, simpler, and it seems about equally unsafe, but it's much faster and produces smaller exes). The printing functions used by Phobos2 are a bit better, but they print very *badly* a wide variety of things, and so far Walter&Co have shown no/little interest in improving them a LOT. Its name (writefln, writef, write, writeln) is much long still, and in the beginning for me it was easy to write "writelnf" instead of "writefln". I have shown here both the many faults/limits of those writefln-like functions (and I can show again about 20-30 groups of situations where they print in an ugly or wrong way), and I have offered a (partial and probably far from perfect = it has bugs) implementation of put/putr that look quite better, despite being ignored. I think the current situation of printing functions in D is a mess. The only tiny improvement I have seen so far in this topic is the introduction of write/writeln in Phobos2, that help avoid a bad bug that happens in D1 (it has actually happened to me two times) if for mistake the first argument of writefln is a string that contains a % that you didn't know about. On the other hand I think the printing of AAs in Phobos2 is worsened compared to D1, I don't remember if this bug was fixed in the meantime. Saying that printing is not important is wrong, because when you print something even just for debugging you want a clear, nice, readable and as little ambiguous output as possible. Most of the programs I write print data on the console or in textual files, and I usually can't use the writefln/writef, because they have too many problems. Bye and sorry for being a bit nervous about this topic, bearophile
Jun 08 2009
bearophile Wrote:The printing functions of Tango are nearly trash for me, I don't like how they are imported, the structure of the hierarchy where they are collocated in modules/packages, their duplication, their name, their API and usage. They are also unsafe. (C std.c.stdio.printf is better, cleaner, simpler, and it seems about equally unsafe, but it's much faster and produces smaller exes). The printing functions used by Phobos2 are a bit better, but they print very *badly* a wide variety of things, and so far Walter&Co have shown no/little interest in improving them a LOT. Its name (writefln, writef, write, writeln) is much long still, and in the beginning for me it was easy to write "writelnf" instead of "writefln". I have shown here both the many faults/limits of those writefln-like functions (and I can show again about 20-30 groups of situations where they print in an ugly or wrong way), and I have offered a (partial and probably far from perfect = it has bugs) implementation of put/putr that look quite better, despite being ignored. I think the current situation of printing functions in D is a mess. The only tiny improvement I have seen so far in this topic is the introduction of write/writeln in Phobos2, that help avoid a bad bug that happens in D1 (it has actually happened to me two times) if for mistake the first argument of writefln is a string that contains a % that you didn't know about. On the other hand I think the printing of AAs in Phobos2 is worsened compared to D1, I don't remember if this bug was fixed in the meantime. Saying that printing is not important is wrong, because when you print something even just for debugging you want a clear, nice, readable and as little ambiguous output as possible. Most of the programs I write print data on the console or in textual files, and I usually can't use the writefln/writef, because they have too many problems. Bye and sorry for being a bit nervous about this topic, bearophileThanks bearophile for your response... please tell me what you think about a new API Fractal
Jun 08 2009
Jarrett Billingsley Wrote:It works, doesn't it? How is "Console.WriteLine(...)" any better?Yes it works... but it uses the opCall... why not use + for concatenation? :)If you create a single instance of Format!(wchar), you won't have that problem.Me... but if I use another API, it can create one indirectly.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.Please, two libraries are enough. No más.yes it is true... two librarians is a big number... but I need to write functional programs... not programs with bugs. And... thanks again for your opinion :)
Jun 08 2009
Fractal wrote:Jarrett Billingsley Wrote:IIRC, Chinese characters can't be represented by a single wchar. However, that's not a problem since all three string types support full Unicode.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?char[] supports any language that wchar[] and dchar[] support. It's just that with char and wchar you need more than one of them for some characters. You may want to read http://prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD and http://en.wikipedia.org/wiki/Unicode (or one of its many translations if your English is not so good).are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.
Jun 08 2009
Frits van Bommel wrote:Fractal wrote:I'd recommend using char[] for everything (unless you're calling Windows API functions, then wchar[] is better). All three can support all characters, so just pick one and roll with it.Jarrett Billingsley Wrote:IIRC, Chinese characters can't be represented by a single wchar. However, that's not a problem since all three string types support full Unicode.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?char[] supports any language that wchar[] and dchar[] support. It's just that with char and wchar you need more than one of them for some characters. You may want to read http://prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD and http://en.wikipedia.org/wiki/Unicode (or one of its many translations if your English is not so good).are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.
Jun 08 2009
Frits van Bommel, el 9 de junio a las 02:28 me escribiste:Fractal wrote:I recommend this small but very enlightening article if you know nothing about Unicode: http://www.joelonsoftware.com/articles/Unicode.html -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Hay manos capaces de fabricar herramientas con las que se hacen máquinas para hacer ordenadores que a su vez diseñan máquinas que hacen herramientas para que las use la manoJarrett Billingsley Wrote:IIRC, Chinese characters can't be represented by a single wchar. However, that's not a problem since all three string types support full Unicode.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?char[] supports any language that wchar[] and dchar[] support. It's just that with char and wchar you need more than one of them for some characters. You may want to read http://prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD and http://en.wikipedia.org/wiki/Unicode (or one of its many translations if your English is not so good).are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.
Jun 08 2009
Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.In case this wasn't already clear enough: char[] _is_ a Unicode string. Unicode should be able to handle all languages of the world. (Or rather, all characters used by various writing systems used by humans. Or whatever Unicode calls them.) char is only 1 byte big, but the D language specification defines, that char[] contains UTF-8 encoded text. Which means char[] can represent exactly the same content as wchar[]. char[] and wchar[] have both pros and cons, but I think char[] is the best choice. Note that even in C, char arrays can be UTF-8 encoded text. Unlike in D, that's not a "must".
Jun 09 2009
grauzone wrote:Note that even in C, char arrays can be UTF-8 encoded text. Unlike in D, that's not a "must".Being not required in C makes it pretty much a disaster to use UTF-8. It's so bad that C++0x introduced new basic types to support UTF.
Jun 09 2009
Frits van Bommel Wrote:Fractal wrote:Thanks for the correction... then adding a String struct to simplify it? FractalJarrett Billingsley Wrote:IIRC, Chinese characters can't be represented by a single wchar. However, that's not a problem since all three string types support full Unicode.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?char[] supports any language that wchar[] and dchar[] support. It's just that with char and wchar you need more than one of them for some characters. You may want to read http://prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD and http://en.wikipedia.org/wiki/Unicode (or one of its many translations if your English is not so good).are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.
Jun 08 2009
Fractal wrote:Thanks for the correction... then adding a String struct to simplify it? FractalWhy? char[] _is_ a string. wchar[] and dchar[] are basically there for compatibility with libraries that want them. That being said, tango.text.Text is a "string struct" of a sort, although it's designed more for representing a large block of text in an editor rather than a single string. There's also mtext ( http://www.dprogramming.com/mtext.php ), though it's unlikely to compile without modification since it's rather old.
Jun 08 2009
Robert Fraser Wrote:Why?Because I want the same string handling that any modern language has, for every part of the program. just using String, not char[]. Then mystring[1] will return a dchar, and not something that cannot be understanded. Fractal
Jun 08 2009
Frits van Bommel Wrote:Fractal wrote:Thanks for the correction... Maybe adding a String struct?Jarrett Billingsley Wrote:IIRC, Chinese characters can't be represented by a single wchar. However, that's not a problem since all three string types support full Unicode.Because those are the three string encodings D supports, and only supporting one is a dumb idea.Why? wchar is full compatible with all languages (if it is not please tell me)... also when I have many strings in different types, I need to convert it from one type to other in each part of the program. Why three when one is suffice?char[] supports any language that wchar[] and dchar[] support. It's just that with char and wchar you need more than one of them for some characters. You may want to read http://prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD and http://en.wikipedia.org/wiki/Unicode (or one of its many translations if your English is not so good).are all Unicode, just different encodings. However, even if you can throw an exception in Spanish, it might not print out correctly on Windows unless you have your console configured correctly.Oh... I will take a look for that (console configuration)... but the char type dont supports some languages, because it only supports latin... Im wrong? The Exception on the two APIs uses char[]. I want Inernationalized programs.
Jun 08 2009
Some things that i want for a Standard Library are: - XML: Tango has XML but I need to write much lines for a simple task (like it hasnt a function to get an attribute as an int) - simple IO that "works" - String structure for easy string handling - A global dynamic string table (loaded at start up from a XLIFF) to has everything internationalised, like: void main() { // before anything Locale.load("locale/en.xml"); } - A common way to store resources in a single compressed file - Load application configuration in one go like: auto cfg = new ApplicationSettings("app.xml"); - Integrated and simple GUI
Jun 08 2009