[erlang-questions] Why we need a -module() attribute?

Konstantin Vsochanov kost@REDACTED
Wed Feb 24 10:46:03 CET 2016


On 2/23/16 01:30 , Richard A. O'Keefe wrote:
> I do not recall ever seeing -module coming up here before.
> I certainly don't recall a long thread like this one.
> 

Maybe because people who stumble over -module() too shy to write to
erlang mail list?

> #!/bin/sh
> #Usage: edit module
> case "$1" in
>  */*)  echo "Module name may not contain /"   >/dev/stderr; exit 1 ;;
>  -*)   echo "Module name may not start with -">/dev/stderr; exit 1 ;;
>  *\'*) echo "Module name may not contain '"   >/dev/stderr; exit 1 ;;
>  *\\*) echo "Module name may not contain \\"  >/dev/stderr; exit 1 ;;
>  *)    ;;
> esac
> file="$1.erl" # Beware: file system may mangle name!
> if [ ! -e "$file" ]; then
>    date=`date +%Y-%m-%d`
>    case `expr "$1" : '^[a-z][a-zA-Z0-9_]*$'` in
>     0) module="'$1'" ;;
>     *) module="$1"   ;;
>    esac
>    echo "%%% File   : $file"     >"$file"
>    echo "%%% Author : $LOGNAME" >>"$file"
>    echo "%%% Created: $date"    >>"$file"
>    echo "%%% Purpose: "         >>"$file"
>    echo ""                      >>"$file"
>    echo "-module($module)."     >>"$file"
>    echo ""                      >>"$file"
>    echo "-export(["             >>"$file"
>    echo " ])."                  >>"$file"
>    echo ""                      >>"$file"
> fi
> exec ${EDITOR:-emacs} "$file"
>  
> So here's how much burden -module adds to this programmer:
> instead of
>  % emacs foobar.erl
> I have to type
>  % edit foobar
> 
> Hang on, that's LESS work.
> 

Thank you for the script, I think it will work for me. I personally
don't use emacs, but it doesn't matter.

Reading all this long thread I must agree, the -module() is not the
worst problem in Erlang.

Regarding modules, I think the flat space for module names is more
troubling. If you look at almost any Erlang library/application, you can
see, that file names are like

myapp_file1.erl
myapp_file2.erl
myapp_subsystem1_file1.erl
...

So we manually implement hierarchic module system. It's a clear sign,
that something going wrong or is missing.












More information about the erlang-questions mailing list