digitalmars.D - Trailing comma in variable declaration
- Ky-Anh Huynh (16/16) Jul 28 2018 Hi,
- Jonathan M Davis (16/32) Jul 29 2018 Well, most folks would just make those separate statements, in which cas...
- Ky-Anh Huynh (6/24) Jul 30 2018 Thanks a lot for your explantion, Jonathan.
- PaperBoy (11/27) Jul 29 2018 This is the syntax sometimes seen with language that don't have
- Ky-Anh Huynh (4/19) Jul 30 2018 This is smart:) It's not very natural I think; in English, comma
Hi, is it nice to have a trailing comma in variable declaration: [code] bool verbose = false, download_only = false, no_confirm = false, show_help = false, show_version = false, list_ops = false, ; [/code] As trailing comma is possible (and it's great) for arrays, enum,... I wonder why we don't have this fancy thing for variables declaration. Thanks for your reading.
Jul 28 2018
On Saturday, July 28, 2018 11:32:15 PM MDT Ky-Anh Huynh via Digitalmars-d wrote:Hi, is it nice to have a trailing comma in variable declaration: [code] bool verbose = false, download_only = false, no_confirm = false, show_help = false, show_version = false, list_ops = false, ; [/code] As trailing comma is possible (and it's great) for arrays, enum,... I wonder why we don't have this fancy thing for variables declaration. Thanks for your reading.Well, most folks would just make those separate statements, in which case, there would be no commas at all. Some folks do put multiple variable declarations on a single line, but if you do that, a trailing comma looks terrible. I doubt that using a single statement to declare multiple variables but putting it on multiple lines was even a use case that was really considered. Also, a quick test with a C++ compiler shows that it's not legal there, so the rules we have with regard to this probably just came from C++. AFAIK, the only significant change that D has from C/C++ with regards to declaring multiple variables in a single statement is that the * is considered part of the type and thus int* a, b, c; declares three variables of type int* in D, whereas in C/C++, it would declare a single variable of type int* and two of type int. - Jonathan M Davis
Jul 29 2018
On Sunday, 29 July 2018 at 10:46:12 UTC, Jonathan M Davis wrote:Well, most folks would just make those separate statements, in which case, there would be no commas at all. Some folks do put multiple variable declarations on a single line, but if you do that, a trailing comma looks terrible. I doubt that using a single statement to declare multiple variables but putting it on multiple lines was even a use case that was really considered. Also, a quick test with a C++ compiler shows that it's not legal there, so the rules we have with regard to this probably just came from C++. AFAIK, the only significant change that D has from C/C++ with regards to declaring multiple variables in a single statement is that the * is considered part of the type and thus int* a, b, c; declares three variables of type int* in D, whereas in C/C++, it would declare a single variable of type int* and two of type int. - Jonathan M DavisThanks a lot for your explantion, Jonathan. I understand the idea is to minimize the differences between C/C++ and D (FIXME.) Anyway the missing feature suprised me; I thought variable declaration is simply a (compile time) list, and as an array, leading comma was acceptable :)
Jul 30 2018
On Sunday, 29 July 2018 at 05:32:15 UTC, Ky-Anh Huynh wrote:Hi, is it nice to have a trailing comma in variable declaration: [code] bool verbose = false, download_only = false, no_confirm = false, show_help = false, show_version = false, list_ops = false, ; [/code] As trailing comma is possible (and it's great) for arrays, enum,... I wonder why we don't have this fancy thing for variables declaration. Thanks for your reading.This is the syntax sometimes seen with language that don't have trailling comma at all. bool verbose = false , download_only = false , no_confirm = false , show_help = false , show_version = false , list_ops = false ;
Jul 29 2018
On Sunday, 29 July 2018 at 14:47:59 UTC, PaperBoy wrote:This is smart:) It's not very natural I think; in English, comma and punctuation would be closed to the last character (e.g., the dot in this sentence.)As trailing comma is possible (and it's great) for arrays, enum,... I wonder why we don't have this fancy thing for variables declaration. Thanks for your reading.This is the syntax sometimes seen with language that don't have trailling comma at all. bool verbose = false , download_only = false , no_confirm = false , show_help = false , show_version = false , list_ops = false ;
Jul 30 2018