www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Body of Programming

reply Robert V. Abrams III <Robert_member pathlink.com> writes:
I have a suggestion that will drastically improve the look of D. Instead of
using brackets to begin and terminate functions and definitions, use some sort
of an end statement for to designate the termination of functions, control
structures, and class definitions. C++'s failure to do this has resulted in the
confusion of many a programmer as to where a function\class definition\control
structure would begin and end. 

For example:  for (int i = 0; i <= 20; i++) {
// perform actions 
int value = 0;
for (int k = 0; k = 4; k++) {
doSomething(value)
switch (value) {
//cases
}
}
}

Would confuse someone when looking for where the loops and switches begin and
end. Plus if someone were to practice good programming style, they would have to
// end for or // end switch at every end bracket, which is nerve wrecking. 

What I propose is to have D do this:

for (int i = 0; i <= 20; i++) : 
// perform actions 
int value = 0;
for (int k = 0; k = 4; k++) :
doSomething(value)
switch (value) : 
//cases
:end switch
:end for
:end for

Notice the difference? I clearly delineated the beginning and the ending of each
control structure and function. This also brings the language closer to human
language, making it more understandable. I base my findings directly on the
languages of Perl and PHP, as they have adopted the same conventions that not
only encourage good programming practices, but also is easier to follow.



Robert Vincent Abrams III
May 07 2004
next sibling parent "Ivan 'Killer927' Cebola" <andromeda hl2dev.net> writes:
I'm sorry to say but that idea would be actually bad, just see why VB is
hated by many: it's way too verbose, this would increase the verbosity of D
in a large amount.

Ivan "Killer927" Cebola
May 06 2004
prev sibling next sibling parent reply "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
Robert V. Abrams III wrote:

 For example:  for (int i = 0; i <= 20; i++) {
 // perform actions 
 int value = 0;
 for (int k = 0; k = 4; k++) {
 doSomething(value)
 switch (value) {
 //cases
 }
 }
 }
You're just excusing spaghetti code.... that's the problem I'm seeing... I would write it as: for (int i = 0; i <= 20; i++) { int value = 0; // Perform actions. for (int k = 0; k = 4; k++) { doSomething(value); switch (value) { // Cases here. } } } Looks totally clear to me when written up properly. Conversely, using endwhile etc. (things that are DEPRECATED in PHP...) only makes the code ugly and makes it more excusable to use spaghetti code... -[Unknown]
May 07 2004
parent "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
Unknown W. Brackets wrote:
         for (int k = 0; k = 4; k++)
Not my mistake, but this should be: for (int k = 0; k <= 4; k++) Or: for (int k = 0; k != 4; k++) See what you find when you indent properly? -[Unknown]
May 07 2004
prev sibling next sibling parent reply Andy Friesen <andy ikagames.com> writes:
Robert V. Abrams III wrote:
 Would confuse someone when looking for where the loops and switches begin and
 end. Plus if someone were to practice good programming style, they would have
to
 // end for or // end switch at every end bracket, which is nerve wrecking. 
The only place where I would think this necessary is when using syntactic contortions like the venerable Duff's device, which nobody in their right mind should be using anyway. Maybe it would be sensible if the body of the loop doesn't fit onscreen, but you have other, far more pressing problems to worry about if that's the case.
 What I propose is to have D do this:
 
 for (int i = 0; i <= 20; i++) : 
 // perform actions 
 int value = 0;
 for (int k = 0; k = 4; k++) :
 doSomething(value)
 switch (value) : 
 //cases
 :end switch
 :end for
 :end for
 
 Notice the difference?
Nope. It's still a big opaque mess. Even worse, it's more cluttery even if formatted correctly. It's excessive, verbose syntax for something that's completely self-evident to any sane human being. (ie anyone who indents their code properly) -- andy
May 07 2004
parent clayasaurus <clayasaurus_member pathlink.com> writes:
 What I propose is to have D do this:
 
 for (int i = 0; i <= 20; i++) : 
 // perform actions 
 int value = 0;
 for (int k = 0; k = 4; k++) :
 doSomething(value)
 switch (value) : 
 //cases
 :end switch
 :end for
 :end for
 
 Notice the difference?
I'm not a fan of that, however i see what you mean. This problem can easily be solved if someone take time to comment their loops like switch() { for () { if () { } // end if } // end for } // end switch() being able to use the tab helps a lot. i kind of see what you mean, but if there was built in language support for this is should use better syntax like switch() { for () { if () { } end if } end for } end switch() or people should be able to comment that part in themselves.
May 07 2004
prev sibling parent reply Brad Anderson <brad sankaty.dot.com> writes:
I guess what you can take from these responses, in a word, is :  "indent"

Indent your code clearly, and things begin to make sense.  Try Jalopy 
for Java code:  http://jalopy.sourceforge.net/

Better yet, re-write this utility in D.  It will clearly delineate your 
code, no matter if you receive it like the big opaque block you 
proposed.  Send it through your Dalopy utility (hosted at dsource.org, 
of course) and you'd see the code clear as day.

BA

Robert V. Abrams III wrote:

 I have a suggestion that will drastically improve the look of D. Instead of
 using brackets to begin and terminate functions and definitions, use some sort
 of an end statement for to designate the termination of functions, control
 structures, and class definitions. C++'s failure to do this has resulted in the
 confusion of many a programmer as to where a function\class definition\control
 structure would begin and end. 
 
 For example:  for (int i = 0; i <= 20; i++) {
 // perform actions 
 int value = 0;
 for (int k = 0; k = 4; k++) {
 doSomething(value)
 switch (value) {
 //cases
 }
 }
 }
 
 Would confuse someone when looking for where the loops and switches begin and
 end. Plus if someone were to practice good programming style, they would have
to
 // end for or // end switch at every end bracket, which is nerve wrecking. 
 
 What I propose is to have D do this:
 
 for (int i = 0; i <= 20; i++) : 
 // perform actions 
 int value = 0;
 for (int k = 0; k = 4; k++) :
 doSomething(value)
 switch (value) : 
 //cases
 :end switch
 :end for
 :end for
 
 Notice the difference? I clearly delineated the beginning and the ending of
each
 control structure and function. This also brings the language closer to human
 language, making it more understandable. I base my findings directly on the
 languages of Perl and PHP, as they have adopted the same conventions that not
 only encourage good programming practices, but also is easier to follow.
 
 
 
 Robert Vincent Abrams III
May 07 2004
parent Mark T <Mark_member pathlink.com> writes:
In article <c7hnlh$2n15$3 digitaldaemon.com>, Brad Anderson says...
I guess what you can take from these responses, in a word, is :  "indent"

Indent your code clearly, and things begin to make sense.  Try Jalopy 
for Java code:  http://jalopy.sourceforge.net/

Better yet, re-write this utility in D
Artistic Style would probably do this already (I haven't tried yet) and would probably much easier to add D capability. http://astyle.sourceforge.net/
May 08 2004