Re: Strongly recommend the D language to support new feature of “compile time char type identification”

Yigal Chripun yigal100 at gmail.com
Thu Oct 25 04:36:09 PDT 2007


Forrest wrote:
> Strongly recommend  the D language to support new feature of “compile time char type identification”
> 
> D is a new language it has lot of advantages over C/C++. 
> But it has some obvious disadvantages
> 1.	It’s main function only accepts char[][] args but wchar[][] and dchar[][] args.  As a result if user pass Unicode args to it, it may get a wrong result.
> 2.	Developer have to write lots of similar functions to handle all char types
> For example a developer written a class
> class Foo
> {
> 	char[][] name;
> 	void setNamea(char[] name){}
> 	void setNamew(wchar[] name){}
> 	void setNamed(dchar[] name){}
> 	
> }
> It is very ugly, and I hate to write this code. 
> 
> What I wish is only write the simple and natural code like this
> class Foo
> {
> 	char[][] name;
> 	void setName(char[] name){}
> }
> 
> The char[] can stands for achar/wchar/dchar, and developer can specify the type in the package.ini file.  With the ini file the develop can build Asicll, Unicode or UTF-32 versions libraries/applications. 
> 
> How to approach the goal.
> 1.	Introduce a new key work achar stands for Asicll chars 
> 2.	Add a ini file to the package. The ini file is optional. If no such a file all “char” in the source file will be treat as wchar, if there is a ini file treat the char as specified type. So all developers in the world can possibly use  D language without concern the char type. Unicode is the future.
> 3.	String in source code now has three suffix. For example “this is achar”c, “this is wchar”w, and “this is dchar”d explicitly indicate they are of achar[], wchar[] and dchar[]. If the user do not add such a suffix the string type may possibly mean the string is achar[], wchar[] or dchar[] depends on the specification of the ini file. If no ini file the string will be treated as wchar[].
> 4.	Compiler of DMD provide ability to read the ini file and determines the type char and no suffix string.
> 5.	The format ini file can be a plan text file or XML file. Advise to use XML, it is more extensible.
> 6.	The ini file can be placed on different folder. Source code use the ini file which is in the same folder. 
> 7.	
> Risk and possibility.
> 1.	D language is new, we still has the opportunity to change it.
> 2.	The migration from old D to the new D will be relatively easer. User can specify the char to stand for certain type to minimize their risk. 
> 3.	D should be more friendly to developer, it is worth doing the change.
> 
> What advantages we get?
> 1.	The D code will be more readable and natural.
> 2.	Use the same code to generate different versions by only change ini file.
> 3.	Developer can still use the achar/dchar/dchar explicitly tell the compiler they want to use a special char type. That is to say explicit char type will hide the specification of ini file.
> 
> Any one is interested on it?

You got it wrong. D uses only UTF (don't forget that ASCII is a subset 
of UTF-8). the different char types are different UTF encodings:
char  = utf-8
wchar = utf-16
dchar = utf-32
If you use a modern OS that supports Unicode than you can pass arguments 
in what ever language you want - even Klingon!
If you need a more abstract type, there's a String class on - 
http://www.descent.org, or you could look in Tango for a similar module.
IMH, most of the time you don't need anything fancier than those 
primitive types.



More information about the Digitalmars-d mailing list