Last active
April 23, 2017 10:38
-
-
Save voluntas/ffecba72ed2fc8b54e8e16f1230d2ef9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% module の前のコメントは % は 3 つ | |
%%% インデントはスペース 4 | |
-module(ei). | |
%% 同じ関数名でアリティが違うだけの場合は改行なしで、アリティの数値でソートして欲しい | |
-export([egg/0, egg/1, egg/2]). | |
%% export の中身でで改行してたりしなかったりは書かれているのを尊重してほしい | |
%% export と export の間で改行があった場合はそのままにしてほしい | |
%% export と export で改行がなかった場合はそのままにしてほしい | |
-export([ham/0, | |
bacon/1]). | |
-export([egg/1, spam/2]). | |
%% export_type は export お同じ方針でお願いしたい | |
-export_type([spam/0]). | |
%% import は export と同じ改行方針で | |
-import(egg, [ham/0]). | |
%% export_type と include_lib は改行 1 つ | |
%% include_lib も改行なしで、順番はそのまま | |
-include_lib("eunit/include/eunit.hrl"). | |
-include_lib("file/include/file.hrl"). | |
%% include は改行なしで | |
-include("spam.hrl"). | |
-include("egg.hrl"). | |
%% include と -define の間は改行 1 つ | |
-define(?SPAM_HAM_EGG, spam_ham_egg). | |
-type spam() :: atom(). | |
%% -record と -define の間は改行 1 つ | |
%% レコードの場合はこのインデント方式で | |
-record(spam_spam_spam, { | |
ham :: binary() | ?SPAM_HAM_EGG, | |
egg :: atom() % ラインコメントは % を 1 つで、値に対してスペース 2、ただしこれはスペース 1 と悩む | |
}). | |
%% 同一関数名でアリティが異なる場合は改行は 1 つのみ | |
egg() -> | |
a. | |
%% 同一関数名、同一 Arity は改行なし | |
egg(x) -> | |
x; | |
egg(b) -> | |
c. | |
egg(d, e) -> | |
f. | |
%% 関数名が異なる場合は改行は 2 つ | |
ham() -> | |
egg. | |
%% -spec は 関数名とくっつける | |
-spec bacon(a) -> ham. | |
bacon(a) -> | |
ham. | |
%% 改行のタイミングは書いてる人を尊重する | |
function_name(a, b, c, | |
e, f, c, e) -> | |
%% case つかって代入するときは A = case にインデントを会わせる | |
A = case spam of | |
ham -> | |
egg; | |
a -> | |
b | |
end, | |
%% レコードのパターンマッチの改行は開発者を優先する | |
#spam{ham = Ham} = Spam, | |
#spam{ham = Ham, | |
egg = Spam, bacon = Bacon} = Spam, | |
%% Map の場合 key => value はかならずスペースを入れる | |
Map = #{a => b, c => b}, | |
%% 無名関数内部はスペース 8 | |
F = fun() -> | |
a; | |
() -> | |
b | |
end, | |
%% リストは内側だけスペース | |
ok = lists:foreach(F, [1, 2, 3]), | |
%% 無名関数の後に改行するかどうかは書いた人を優先で | |
ok = lists:foreach(fun(N) -> | |
N | |
end, abc), | |
%% まずはどちらも許容してみる、こちらは OCaml 方式 | |
ok = lists:foreach(fun(N) -> | |
N | |
end, | |
abc), | |
%% リストの端はスペースあり | |
X = [ N * N || N <- Spam, N =:= 10 ], | |
Y = << <<N:8>> || <<N:8>> <= Spam, N =:= 10 >>, | |
ok. | |
%% リストパターンマッチはスペースを入れない | |
%% タプルはスペース一つ | |
bacon([{a, b}, {c, d}|Rest], Acc) -> | |
ok. | |
%% レコードパターンマッチは = の間にスペースを入れる | |
ham(#spam{egg = Spam, | |
ham = Spam}) -> | |
ok. | |
%% マップのパターンマッチはレコードと同様 | |
spam(#{spam := Spam, | |
ham := Spam}) -> | |
ok. | |
%% ガードはお尻の方に andalso, orelse や , ; を利用する | |
spam(A, B, C) when (is_binary(A) andalso is_integer(B)) andalso | |
is_pid(C) orelse | |
is_integer(C) -> | |
ok; | |
spam(A, B, C) when (is_binary(A), is_integer(B)), | |
is_pid(C); | |
is_integer(C) -> | |
ok. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment