matt-savvy
I see some people adopt this convention when naming fields or variables where the value is a boolean. I personally see this as an antipattern, curious what the group here thinks. E.g.
online? = user.status == :online
Should a boolean variable or field be named with a trailing question mark?
- nope, only functions that return bool values should end with
? - yes
- I’m not sure, I see it both ways
0
voters
Trending in Polls
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
I think it would help to explain why you see it as an anti-pattern. I personally really like it for variables, not so much for fields because it can cause issues with serialization (even though thanks to LiveView/OTP I haven’t had to work on a project that has a web API in a quite a while).
Perhaps I’m reading too much into your use of “should” here but my answer is that there is no “should” about it, it’s a question of style on a per-project basis.
matt-savvy
I guess I mean “do you consider this a language idiom”
dimitarvp
It honestly does not matter, if your functions get so long that a
?suffix on variables inside them actually matters then you have much bigger problems to worry about, and you should address those first.As for function suffixes, why not. It helps express intent a little bit.
Nope.
D4no0
IMO it’s a nice pattern that the language allows. You go to other languages codebases and you can always notice patterns like
is_activeall the time.For values I would say I use it half the time, however I always use this pattern for functions, really helps to distinct them between simple functions and bang functions.
sodapopcan
In that case I still don’t like any of the poll options, lol. No, it’s not an idiom and no, it’s not an anti-pattern. There is certainly no harm in it beyond personal preference. I personally really like the extra clarity and avoiding
is_,has_etc. And I don’t have an example off the top off my head but there are times where it’s awkward to come up with the correct English prefix or the correct one reads strangely. If I think of one I’ll post back.LostKobrakai
Trailing ? is certainly not just a pattern for functions. E.g. ecto uses
changeset.valid?.sodapopcan
Oh ya, that is an example of keys using it that I like.
thiagomajesk
For those who responded with “yes,” I have a question for you: Would you name your boolean database columns with a trailing question mark as well? I’m just curious to know the extent to which you would keep this naming convention in your apps.
PS.: I’m thinking in terms of keeping consistency with Ecto schemas (you can always specify the column source, but the mismatch might not be desirable)
dimitarvp
Absolutely not, DB booleans will always be
is_this_or_thaton my watch. I have zero desire fighting with edge cases. Sticking to good old alpha-numeric strings for these things.benwilson512
Notably you can have your cake and eat it too if you want by naming the database column via the is_ pattern and the Ecto schema via ? by using the source option.