Feature request: one-statement functions without brackets

Georg Wrede georg at nospam.org
Tue Apr 3 06:41:28 PDT 2007


eao197 wrote:
> I understand that transforming IfStatement/SwitchStatement from a  
> statement to an expression may be very hard. And optional 
> ReturnStatement  may be very hard to implement too. It would be great, 
> but if not it won't  be a tragedy. But I hope that optional semicolons 
> is much easier to  implement. And such trifle can make D much more 
> expressive (the Scala  history shows this).

Well, you might want to give it a try. It shouldn't bee all too hard to 
write a "D++ to D" filter, that simply adds semicolons at the end of 
every line, except for a few situations, which could be found out using 
regular (probably multi-line) expressions.

This first try at it would of course be limited, as taking care of every 
situation might be more work, but the result could already be informative.


Quite another thing is, the semicolons bring redundancy to the code that 
_humans_ need more than the compiler. Readability, clarity of meaning, 
and the possbility to split an expression to several lines, they all 
bring time savings when reading and understanding the code at a glance.

Also many people have to use C, C++ or Java, and the semicolon behaving 
in a familiar way does reduce the mental burden of switching between 
these languages.

All that outweighs the drag of one more key press on most of the lines. 
Besides, the actual "time savings" when writing code aren't all that 
massive. For example object.d (my version is DMD 0.163, and I admit this 
is an arbitrary file, ;-) but still) contains 620 lines, and only 193 of 
them contain a semicolon. That's less than a third.



More information about the Digitalmars-d mailing list