practicalli / practicalli/clojure
naming unpure / side effect functions
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 117
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
using ! as a suffix on function names is a convention to show that the function has side effects (and is therefore not pure)
Slack discusion
hendore 15:00
I’ve noticed a convention of adding a ! suffix to function names that have side effects, so I have a few functions that insert/update a database such as create-account! add-booking! etc… This got me thinking, functions that query the database are also not pure functions as the result may be different (if someone was to edit the database) so should functions such as get-booking also share the same convention?
Also, if create-account! is called from a register function, should I also suffix the register function with ! as it has side effects?
I understand it makes no difference at all but would just like to get into good habits whilst learning
danielneal 15:25
Yep, when I’ve seen this convention, only the side-effecting functions tend be indicated by the !, rather than all impure functions. So get-booking wouldn’t have a ! but register! probably would. (edited)
hendore 15:34
Sweet 👍
dharrigan 15:38
I mostly use ! for things that my program modifies, i.e., writing to file, writing to a database, sending data across the wire. Things which I consume, I don't suffix with ! (unless I then modify and write out, external to my application)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named; start by locating the project's guidance on Clojure naming conventions. Define whether the ! suffix applies to database reads, writes, and functions that call side-effecting functions, then document the decided convention and verify it against existing examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100