[erlang-questions] please never make spec required

Zvi exta7@REDACTED
Wed Feb 18 16:53:19 CET 2009

Steve Davis-5 wrote:
> Please, please *never* make spec a required part of Erlang.
> How can a spec be justified when a spec can be both longer and harder
> to read than the code. e.g.: from lists...
> -spec(append/2 :: ([T],[T]) -> [T]).
> append(L1, L2) -> L1 ++ L2.

In Erlang arguments got duplicated 4 times (edoc, spec, arguments
list/patterns and guards). Overtiem, it's guaranteed, that they will be out
of sync:

%% @doc Concatenates two lists
%% @spec append(list(),list()) -> list()
%% @end 
-spec(append/2 :: ([T],[T]) -> [T]).
append(L1, L2) when
      is_list(L1), is_list(L2)
      -> L1 ++ L2.

Compare this with C++ and Doxygen (arguments specified only once, thanks for
type declarations and special doxygen syntax):

* returns list, which is concatenations of two input lists
template<typename T> 
list<T> append( const list<T> &L1,          /**< list of elements of type T
                      const list<T> &L2) const /**< list of elements of type
T */
   list<T> L(L1);
   L.insert(L.end(), L2.begin(), L2.end());
   return L;

View this message in context: http://www.nabble.com/please-never-make-spec-required-tp22079518p22081703.html
Sent from the Erlang Questions mailing list archive at Nabble.com.

More information about the erlang-questions mailing list