Difference between revisions of "DIP41"

From D Wiki
Jump to: navigation, search
Line 1: Line 1:
== DIP 41: dmd command line overhaul. (still editing : don't look yet) ==
+
== DIP 41: dmd command line overhaul. (still editing : don't read yet) ==
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 28: Line 28:
  
 
== Abstract ==
 
== Abstract ==
 +
This DIP seeks to improve dmd's command line flags, to make it more consistent with other tools, more expandable, and better interact with other tools such as rdmd.
 +
 +
== -offilename vs -of=filename ==
 
Dmd currently uses 2 conventions for its flags with arguments:
 
Dmd currently uses 2 conventions for its flags with arguments:
* -version=ident
+
* type A: -offilename, -Dddocdir, -Dffilename, -Ipath (etc)
* -offilename
+
* type B: -version=ident (etc)  
 
 
The 2nd version is problematic,  
 
 
 
 
 
-Dddocdir
 
-Dffilename
 
-Ipath
 
-offilename
 
(etc...)
 
  
vs a sane way, eg the one used in ldc2 (or many other unix tools,
+
Type A, the most common in dmd, is problematic:
which have a space at least as delimiter):
+
* it doesn't scale: we can't have any new flag starting with "-I" or "-L", etc as it would create conflicts.
 +
* it's visually harder to tell from the command line the options from the arguments to these options
 +
* it's using a different (worst) convention from most other tools (including other D compilers, like gdc or ldc)
  
-Dd=docdir
+
For reference, ldc uses:
-Df=filename
+
-of=filename, -Dd=docdir, -Df=filename, -I=path etc.
-I=path
 
-of=filename
 
  
The problem is:
+
== Deprecation path ==
* dmd's flags don't scale: now we can't have any new flag starting
 
with "-I" or "-L", etc as it would create conflicts. And I know some
 
people want to keep the number of flags to a minimum but that's not a
 
good reason to restrict future expansion ability
 
* it's visually harder to tell from the command line the options from
 
the arguments to these options.
 
  
If we don't deprecate in favor of the ldc2 style (is that an option
+
We should support type B convention for all flags in a future release of dmd, and support the existing ones for some time until they become deprecated.
with a proper deprecation path?), can we at least make sure any future
 
flags will follow ldc2's convention?
 
 
 
 
 
support both the old and the new ways for now.
 
 
 
 
 
 
 
Let's agree on specifics before writing enhancement request, and
 
possibly make a single one-time breaking change instead of several
 
short-sighted ones.
 
 
 
With type A being -offilename and type B being -of=filename, how about:
 
  
 
1)
 
1)
prevent any newly created flags of type A
+
Make all future flags have type B.
  
 
2)
 
2)
migrate all A flags to B flags. Here's one possible way to achieve
+
Migrate all A flags to B flags. Here's one possible way to achieve this (say in next dmd release):
this (say in next dmd release):
 
  
dmd -offilename main.d //works but generates a warning for now, and
+
dmd -offilename main.d //works but generates a warning for now, and error in a subsequent dmd release
error after a certain time passed
 
 
dmd -old_flag -offilename main.d //works and doesn't generate a warning.
 
dmd -old_flag -offilename main.d //works and doesn't generate a warning.
dmd -new_flag -of=filename main.d //works. After a certain time
+
dmd -new_flag -of=filename main.d //works. After a certain time passed, -new_flag is implied
passed, -new_flag is implied
 
  
Note, A and B flags can't be mixed, eg: -offilename -Ddoc=dir will
+
Note, A and B flags can't be mixed, eg: -offilename -Ddoc=dir will give error, in all 3 cases above (ie for flags that are currently in the A style).
give error, in all 3 cases above (ie for flags that are currently in
 
the A style).
 
  
2b) Alternative: use a new binary name (dmd2) instead of -newflag. I
+
2b) Alternative: use a new binary name (dmd2, reminds of D2, ldc2, ldmd2) instead of -newflag. I don't like this as much somehow.
don't like this as much somehow.
 
  
 
3)
 
3)
can we deprecate the current behavior where one can pass the file name
+
can we deprecate the current behavior where one can pass the file name without extension (main vs main.d) as source? Consistency is better than avoiding to type those 2 characters. I created a pathological case with main.d is conflicting with main.d.d (with different
without extension (main vs main.d) as source? Consistency is better
 
than avoiding to type those 2 characters. I created a pathological
 
case with main.d is conflicting with main.d.d (with different
 
 
contents). Which one do you think is called when we call rdmd main.d ?
 
contents). Which one do you think is called when we call rdmd main.d ?
Note, I raised a very analogous concern here
+
Note, I raised a very analogous concern here [https://github.com/D-Programming-Language/dmd/pull/1871#issuecomment-16101987] regarding naming of object files in a flat hierarchy (see my example with dmd -c -oq foo/mod.d foo_mod.d)
https://github.com/D-Programming-Language/dmd/pull/1871#issuecomment-16101987
 
regarding naming of object files in a flat hierarchy (see my example
 
with dmd -c -oq foo/mod.d foo_mod.d)
 
  
 
4)
 
4)
The current strategy of rdmd is to treat as input arguments anything
+
The current strategy of rdmd is to treat as input arguments anything after the first source file:  
after the first source file:
+
rdmd main.d myfirstprogramarg // a bit awkward, especially with optional extension it gets hard to parse visually.
rdmd main.d myfirstprogramarg // a bit awkward, especially with
 
optional extension it gets hard to parse visually.
 
  
 
This is error prone, and inconsistent with dmd's behavior, which is:
 
This is error prone, and inconsistent with dmd's behavior, which is:
dmd src1.d -run main.d myfirstprogramarg //a bit awkward, need to
+
dmd src1.d -run main.d myfirstprogramarg //a bit awkward, need to split the source from the main file.
split the source from the main file.
 
  
I suggest instead something simpler, explicit and consistent, using
+
I suggest instead something simpler, explicit and consistent, using -args as a dmd command line argument, that would just work as well with rdmd:
-args as a dmd command line argument, that would just work as well
 
with rdmd:
 
  
 
dmd main.d src1.d -args myfirstprogramarg
 
dmd main.d src1.d -args myfirstprogramarg
 
rdmd main.d -args myfirstprogramarg
 
rdmd main.d -args myfirstprogramarg
 
  
 
5)
 
5)
currently we distinguish rdmd's arguments from dmd's arguments via
+
currently we distinguish rdmd's arguments from dmd's arguments via '--' vs '-'. A better way IMO would be to have a special flag indicating the start of dmd's (or gdc/ldc...) flags: eg  
'--' vs '-'. A better way IMO would be to have a special flag
 
indicating the start of dmd's (or gdc/ldc...) flags: eg
 
 
rdmd --chatty --dflags -version=myversion main.d
 
rdmd --chatty --dflags -version=myversion main.d
  
 
Notes:
 
Notes:
 
Has support of Walter ([http://forum.dlang.org/post/kk4ejt$1pnq$1@digitalmars.com here])
 
Has support of Walter ([http://forum.dlang.org/post/kk4ejt$1pnq$1@digitalmars.com here])

Revision as of 08:08, 21 May 2013

DIP 41: dmd command line overhaul. (still editing : don't read yet)

Title: dmd command line overhaul.
DIP: 41
Version: 1
Status: Draft
Created: 2013-05-20
Last Modified: 2013-05-20
Author: Timothee Cour
Links: dmd command line options bad design: -offilename, -Ddocdir etc.

Abstract

This DIP seeks to improve dmd's command line flags, to make it more consistent with other tools, more expandable, and better interact with other tools such as rdmd.

-offilename vs -of=filename

Dmd currently uses 2 conventions for its flags with arguments:

  • type A: -offilename, -Dddocdir, -Dffilename, -Ipath (etc)
  • type B: -version=ident (etc)

Type A, the most common in dmd, is problematic:

  • it doesn't scale: we can't have any new flag starting with "-I" or "-L", etc as it would create conflicts.
  • it's visually harder to tell from the command line the options from the arguments to these options
  • it's using a different (worst) convention from most other tools (including other D compilers, like gdc or ldc)

For reference, ldc uses: -of=filename, -Dd=docdir, -Df=filename, -I=path etc.

Deprecation path

We should support type B convention for all flags in a future release of dmd, and support the existing ones for some time until they become deprecated.

1) Make all future flags have type B.

2) Migrate all A flags to B flags. Here's one possible way to achieve this (say in next dmd release):

dmd -offilename main.d //works but generates a warning for now, and error in a subsequent dmd release dmd -old_flag -offilename main.d //works and doesn't generate a warning. dmd -new_flag -of=filename main.d //works. After a certain time passed, -new_flag is implied

Note, A and B flags can't be mixed, eg: -offilename -Ddoc=dir will give error, in all 3 cases above (ie for flags that are currently in the A style).

2b) Alternative: use a new binary name (dmd2, reminds of D2, ldc2, ldmd2) instead of -newflag. I don't like this as much somehow.

3) can we deprecate the current behavior where one can pass the file name without extension (main vs main.d) as source? Consistency is better than avoiding to type those 2 characters. I created a pathological case with main.d is conflicting with main.d.d (with different contents). Which one do you think is called when we call rdmd main.d ? Note, I raised a very analogous concern here [1] regarding naming of object files in a flat hierarchy (see my example with dmd -c -oq foo/mod.d foo_mod.d)

4) The current strategy of rdmd is to treat as input arguments anything after the first source file: rdmd main.d myfirstprogramarg // a bit awkward, especially with optional extension it gets hard to parse visually.

This is error prone, and inconsistent with dmd's behavior, which is: dmd src1.d -run main.d myfirstprogramarg //a bit awkward, need to split the source from the main file.

I suggest instead something simpler, explicit and consistent, using -args as a dmd command line argument, that would just work as well with rdmd:

dmd main.d src1.d -args myfirstprogramarg rdmd main.d -args myfirstprogramarg

5) currently we distinguish rdmd's arguments from dmd's arguments via '--' vs '-'. A better way IMO would be to have a special flag indicating the start of dmd's (or gdc/ldc...) flags: eg rdmd --chatty --dflags -version=myversion main.d

Notes: Has support of Walter (here)