Skip to content

Commit

Permalink
All missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
elbrujohalcon committed Sep 5, 2014
1 parent 5fd1315 commit 1534cb6
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/col_width.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(col_width).

-record(rec, {field1, field2, field3}).

-export([bad/2, good/2]).

%$ @doc too wide
bad([#rec{field1 = FF1, field2 = FF2, field3 = FF3}, #rec{field1 = BF1, field2 = BF2, field3 = BF3} | Rest], Arg2) ->
other_module:bad(FF1, FF2, FF3, BF1, BF2, BF3, bad(Rest, Arg2)).

%% @doc good (< 80 chars)
good([Foo, Bar | Rest], Arg2) ->
#rec{field1 = FF1, field2 = FF2, field3 = FF3} = Foo,
#rec{field1 = BF1, field2 = BF2, field3 = BF3} = Bar,
other_module:good(FF1, FF2, FF3, BF1, BF2, BF3, good(Rest, Arg2)).
24 changes: 24 additions & 0 deletions src/existing_style.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-module(existing_style).

-export([bad/0, good/0]).

bad() ->
% existing code
List = [ {elem1, 1}
, {elem2, 2}
% new code (not respecting the format)
, {elem3, 3}, {elem4, 4},
{elem5, 5}
],
other_module:call(List).

good() ->
% existing code
List = [ {elem1, 1}
, {elem2, 2}
% new code (respecting the format)
, {elem3, 3}
, {elem4, 4}
, {elem5, 5}
],
other_module:call(List).
14 changes: 14 additions & 0 deletions src/grouping_functions/bad.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%%% @doc Mixing priv and public functions
-module(bad).

-export([public1/0, public2/0]).

public1() -> private3(atom1).

private1() -> atom2.

public2() -> private2(private1()).

private2(Atom) -> private3(Atom).

private3(Atom) -> Atom.
19 changes: 19 additions & 0 deletions src/grouping_functions/better.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%%% @doc associated functions are closer
-module(better).

-export([public1/0, public2/0]).

public1() ->
case application:get_env(atom_for_public_1) of
{ok, X} -> public1(X);
_ -> throw(cant_do)
end.
public1(X) -> private3(X). % This is a private function but it's obviously related just to the one before

public2() -> private2(private1()).

private1() -> atom2.

private2(Atom) -> private3(Atom).

private3(Atom) -> Atom.
19 changes: 19 additions & 0 deletions src/grouping_functions/good.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-module(good).

-export([public1/0, public2/0]).

public1() ->
case application:get_env(atom_for_public_1) of
{ok, X} -> private3(X);
_ -> throw(cant_do)
end.

public2() -> private2(private1()).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PRIVATE FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private1() -> atom2.

private2(Atom) -> private3(Atom).

private3(Atom) -> Atom.
29 changes: 29 additions & 0 deletions src/indent.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-module(indent).

-export([bad/0, better/0, good/0]).

%% @doc inconsistent
bad() ->
try
ThisBlock = is:indented(with, two, spaces),
that:is_good(ThisBlock)
catch
_:_ ->
this_block:is_indented(with, four, spaces)
end.

%% @doc consistent, but with 4 spaces
better() ->
receive
{this, block} -> is:indented(with, four, spaces);
_That -> is:not_good()
after 100 ->
but:at_least(it, is, consistent)
end.

%% @doc good
good() ->
case indentation:block() of
{2, spaces} -> me:gusta();
{_, _} -> not_sure:if_gusta()
end.
36 changes: 36 additions & 0 deletions src/nesting.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-module(nesting).

-export([bad/0, good/0]).

bad() ->
case this:function() of
has ->
try too:much() of
nested ->
receive
structures ->
it:should_be(refactored);
into ->
several:other(functions)
end
catch
_:_ ->
dont:you("think?")
end;
_ ->
i:do()
end.

good() ->
case this:function() of
calls ->
other:functions();
that ->
try do:the(internal, parts) of
what ->
was:done(in)
catch
_:the ->
previous:example()
end
end.
31 changes: 31 additions & 0 deletions src/smaller_functions.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-module(smaller_functions).

-export([bad/0, bad/1, good/0, good/1]).

%% @doc function with just a case
bad(Arg) ->
case Arg of
this_one -> should:be(a, function, clause);
and_this_one -> should:be(another, function, clause)
end.

%% @doc usage of pattern matching
good(this_one) -> is:a(function, clause);
good(and_this_one) -> is:another(function, clause).


%% @doc function with an internal case
bad() ->
InitialArg = some:initial_arg(),
InternalResult =
case InitialArg of
this_one -> should:be(a, function, clause);
and_this_one -> should:be(another, function, clause)
end,
some:modification(InternalResult).

%% @doc usage of function clauses instead of an internal case
good() ->
InitialArg = some:initial_arg(),
InternalResult = good(InitialArg),
some:modification(InternalResult).

0 comments on commit 1534cb6

Please sign in to comment.