Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
hukl
hukl
@hukl@chaos.social  ·  activity timestamp 4 hours ago

In Erlang, you rarely see people using `if`. It's kind of considered bad style and 99% of the time `case` is used in its place - why? Well have a read: https://learnyousomeerlang.com/syntax-in-functions#what-the-if

Anyway, in Elixir of course the people coming from other languages want to use `if` all the time because that's what they are used to. As a former Erlang dev I never use `if` in Elixir.

Turns out in Elixir, `if` is actually a macro that uses `case` under the hood.

So you might as well just use case statements ;)

Syntax in functions | Learn You Some Erlang for Great Good!

Erlang functions: their syntax, pattern matching with multiple heads, clauses and guards. Also visits the 'if' and 'case ... of' conditional expressions.
screenshot of the code that implements the if macro with a case expression
screenshot of the code that implements the if macro with a case expression
screenshot of the code that implements the if macro with a case expression
  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-beta.26 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct