|
Archives
D Programming
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger
D.gnu
D
C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows
digitalmars.empire
digitalmars.DMDScript
electronics
|
digitalmars.D - Fractal
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.
Oh... I have swapped the user name with the subject :)
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=
For example:
Stdout("message").newline // Stdout is a function, or a global variable o=
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=
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 =
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=
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 =
T base classes.
For example it solves many GC design problems with IDisposable. Then when=
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=
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=
I apologize if this sounds offensive... Only I want is that D will be a b=
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=
mething like this:
scope auto fileStream =3D new FileStream("file.dat"w, FileAccess.Discard,=
// creates an empty file, and the magic number 1024 is the stream buffer =
scope auto output =3D new BinaryOutput(fileStream);
// this filter can write binary data, and swap bytes for little endian an=
struct 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=
Please, two libraries are enough. No m=E1s.
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
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,
bearophile
Thanks bearophile for your response... please tell me what you think about a
new API
Fractal
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 :)
Fractal wrote:
Jarrett Billingsley Wrote:
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?
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.
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.
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).
Frits van Bommel wrote:
Fractal wrote:
Jarrett Billingsley Wrote:
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?
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.
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.
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).
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.
Frits van Bommel, el 9 de junio a las 02:28 me escribiste:
Fractal wrote:
Jarrett Billingsley Wrote:
Because those are the three string encodings D supports, and only
supporting one is a dumb idea.
one type to other in each part of the program. Why three when one is suffice?
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.
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.
Exception on the two APIs uses char[]. I want Inernationalized programs.
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).
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 mano
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".
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.
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
|
|