We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Understanding the Notation Variance in Elixir Type Specifications
70
clicks
Source: reddit.com
In Elixir, when defining types within a module, developers can use two notations, `t` and `t()`. It's common to encounter both forms in various examples, including the Elixir standard library, which might use `String.t` or `String.t()`. This inconsistency has left some developers pondering about the preferred convention or if there's a difference between the two. According to a community member's comment by Sentreen, both notations are effectively the same, as they refer to invoking the `t/0` type function of the module. The parentheses in Elixir function calls are optional; however, trends within the Elixir community have shifted towards using explicit parentheses for clarity. This rise in explicit syntax is supported by the `mix format` command, which adjusts the code to use parentheses by default. Therefore, `t()` is now the more accepted form, suggesting that a shift towards explicitness has occurred as the language evolved.
Related posts
© HashMerge 2024