I'm developing an application for Windows platform using Phobos library "core.sys.windows.windows".
Then I feel that the current libraries are not "D style".
Firstly, the official sample code [https://wiki.dlang.org/D_for_Win32] is shown below.
---
1| import core.runtime;
2| import core.sys.windows.windows;
3| import std.string;
4|
5| extern(Windows)
6| int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
7| int result;
8|
9| try{
10| Runtime.initialize();
11| result= myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
12| Runtime.terminate();
13| }
14| catch(Throwable e){
15| MessageBoxA(null, e.toString().toStringz(), null, MB_ICONEXCLAMATION);
16| result= 0; // failed
17| }
18|
19| return result;
20| }
21|
22| int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
23| // ... insert user code here ...
24| return 0;
25| }
---
Considering the above, I have two opinions.
(I) Functions name should be camelCased[https://dlang.org/dstyle.html].
I think almost all win32API functions are named with starts capital letter at first
For example, at line 6, "WinMain" should be "winMain".
Likewise, at line 15, "MessageBoxA" to "messageBoxA".
(II) Usage of enums with classification
At line 15, the last argument of the function is a manifest constant "MB_ICONEXCLAMATION".
This value is defined at line 851 in "core.sys.windows.winuser" as follows.
---
enum{
MB_OK= 0,
MB_OKCANCEL,
...
MB_ICONEXCLAMATION= 0x00000030,
...
}
---
I think these manifest constants are defined with a clasification as follows.
---
enum MessageBoxStyle: uint{
Ok= 0u,
OkCancel,
...
IconExclamation= 0x0000_0030u,
...
}
---
If you agree to my opinions, please solve these issues.
Comment #1 by destructionator — 2018-11-07T06:08:33Z
I'm gonna close this as won't fix because these are not D libraries - they are direct access to the underlying operating system functions. Changing the name is impossible... and even if it were possible (like through aliases or wrappers), I wouldn't do it since it would disconnect from the underlying reality.