Comments (8)
Here's a rule that differs and so we should consider: always use parens for defs even if they have no arguments.
from elixir_style_guide.
@christopheradams What does it differ with? Just for reference, the same rule is in the lexmag version.
from elixir_style_guide.
@DavidAntaramian the rule in this guide says to omit parens if the def
has no arguments.
from elixir_style_guide.
@christopheradams Heh…I clicked on the link you had in your comment thinking it was to this guide. That was my confusion.
I personally always advocate the use of parentheses in named function declarations for reasons of continuity: all the other function declarations that have arguments will have parentheses. I think it also adds to the continuity argument that we also have the following recommendation:
Use parentheses for calls to functions with zero arity, so they can be distinguished from variables.
Therefore, zero-arity function declarations are the anomaly.
Notably the lexmag version has a more relaxed rule for zero-arity calls that restricts its application to local functions:
Parentheses are a must for local zero-arity function calls and definitions
As a paper tiger argument: Omitting them does not substantially change the superficial understanding of what the name means, since the def
/defp
already indicates the next term will be a function name.
from elixir_style_guide.
@DavidAntaramian @christopheradams what would be the next course of action for this one? Should we move this clause:
It's our hope that this will become a central hub for community discussion on best practices in Elixir. Feel free to open tickets or send pull requests with improvements. Thanks in advance for your help!
from the Contributing section up top, right below Elixir Style Guide
? That way it is more visible. Additionally, moving this clause up as well:
This is community style guide for the Elixir programming language. Please feel free to make pull requests and suggestions, and be a part of Elixir's vibrant community.
would make it clearer that this is community driven and it is more of a starting point.
Lastly, not sure if this is in line with your thoughts, a screenshot of the video @DavidAntaramian posted with the lines The Code is more what you call guidelines, than actual rules...
(sort of like a meme) would be helpful - but again depends on where we stand. It could be just a sort of light-hearted (but true!) way of clarifying things. I just fear people might not take it seriously though since it's in meme format?
edit shower thought: no need for images etc. Just a simple:
... the code is more what you'd call "guidelines" than actual rules.
Captain Barbossa, Pirates of the Caribbean: The Curse of the Black Pearl
from elixir_style_guide.
I'm interested in the justification/rationale idea. Here's how I think we can move this forward:
- grep all the rule links and put them on a wiki page, maybe with a checkbox
- check off all the links that have sufficient explanation/justification (for example, the zero arity rule has clear reasons)
- then we can review the list and see where the guide comes up short, and start to improve it
What do you think?
from elixir_style_guide.
Seems like a good idea. What about styles that are really just that? I mean space and indentation have been argued in all languages over and over so there's no 'proper' justification for it other than it's the preferred style of most people.
from elixir_style_guide.
I'm interested in the justification/rationale idea. Here's how I think we can move this forward:
- grep all the rule links and put them on a wiki page, maybe with a checkbox
- check off all the links that have sufficient explanation/justification (for example, the zero arity rule has clear reasons)
- then we can review the list and see where the guide comes up short, and start to improve it
What do you think?
Thats seems pretty interesting! Out of curiosity, did we had any progress in this context?
Just bringing this topic alive again because I was curious on the rationale on the naming section about why defguards with boolean checks should be prefixed with is_.
For example, the rationale about the is
prefixed on guard clause name:
defguard is_cool(var) when var == "cool"
and here although being a boolean function, is not prefixed with is
on the name. Could I name is_cool/1
here?
def cool?(var) do
String.contains?(var, "cool")
end
from elixir_style_guide.
Related Issues (20)
- camelCase vs PascalCase HOT 3
- Add preference for long args/`when` in methods? HOT 3
- Does the formatter make this obsolete? HOT 3
- Missing a section about maps HOT 5
- @module_attribute should be moved higher in Module attribute ordering HOT 1
- Establishing Guidelines for Maximizing Anonymous Function Readability in Reference to Escaped and Expanded Notations HOT 3
- Suggestion on Module Attribute Ordering HOT 1
- Thoughts on public/private function ordering HOT 4
- Deeply nested one-arity function calls? HOT 2
- new issue
- Placement of defguard? HOT 1
- using pipe with only 2 functions HOT 1
- Pipeline with single pipe operator for common cases like Enum.map/reduce/filter HOT 3
- Nested defmodule HOT 5
- Macro calls placement in a module HOT 1
- Naming: Modules HOT 1
- Clarification on multiline defs HOT 3
- cómo utilizamos?
- Racionalfor choice
- Broken Link HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixir_style_guide.