Using consistently auto as function return type
    bearophile 
    bearophileHUGS at lycos.com
       
    Sat Jun 16 04:58:23 PDT 2012
    
    
  
Tommi:
> Do you consider it to be good or bad style of programming to 
> use consistently auto as function return type?
In Python programming you don't specify the types of function 
arguments and return values, but while this is possible in 
Haskell too, it's good practice to write down input and output 
types for functions, and let the type inferencer work just inside 
functions.
In D I use auto often inside function, unless I want to change a 
type or unless I want to be sure a certain variable has a desired 
type. But for clarity/readability I prefer to specify 
input/output types of D functions, unless they return a complex 
range. In this case I sometimes add a static assert to be sure it 
yields a range of my desired type:
auto foo(...)
out (result) {
     static assert(ForeachType!(typeof(result)) == ushort);
}
body {
...
}
Bye,
bearophile
    
    
More information about the Digitalmars-d-learn
mailing list