Feature Request List /
Compile Time Char Type Identification
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
- 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.
- Developer have to write lots of similar functions to handle all char types
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.
- Introduce a new key work achar stands for Asicll chars
- 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.
- 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[].
- Compiler of DMD provide ability to read the ini file and determines the type char and no suffix string.
- The format ini file can be a plan text file or XML file. Advise to use XML, it is more extensible.
- The ini file can be placed on different folder. Source code use the ini file which is in the same folder.
- D language is new, we still has the opportunity to change it.
- 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.
- D should be more friendly to developer, it is worth doing the change.
- The D code will be more readable and natural.
- Use the same code to generate different versions by only change ini file.
- 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.