matt-savvy

matt-savvy

Do you think names for bool values should end with a question mark?

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

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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.

sodapopcan

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.

dimitarvp

dimitarvp

Absolutely not, DB booleans will always be is_this_or_that on my watch. I have zero desire fighting with edge cases. Sticking to good old alpha-numeric strings for these things.

jswanner

jswanner

I do also name my database columns with a trailing ?, it does mean needing to quote the field when writing SQL by hand (like in psql).

LostKobrakai

LostKobrakai

Trailing ? is certainly not just a pattern for functions. E.g. ecto uses changeset.valid?.

Where Next?

Popular in Polls Top

arcanemachine
This was the first question on my mind when I saw this other thread by @AstonJ. I’m curious how many Phoenix users actually like using T...
New
AstonJ
Curious whether you’re using wired or wireless to connect to your main working machine to the internet - if you have any specific reasons...
New
New
AstonJ
Curious how much people are paying for hosting of their Elixir (or other BEAM lang) apps :smiley: The poll is anonymous so if you can ge...
New
AstonJ
We last posted a poll like this in 2017 - here’s an updated version for 2022 - this one is slightly different.. You can select up to 3 -...
New
AstonJ
What is your primary dev OS? And is there any software you’d like to recommend that could make development easier? (Apart from the code e...
New
ryanswapp
I think it would be interesting to see how most people are using Phoenix in production. Do you use it as an API backend for a SPA? Or do ...
New
hst337
Do you use hot-reload/recompilation in production? Please note that this poll is only about BEAM’s internal features of runtime upgrades ...
New
AstonJ
How often do you buy a new dev machine? poll If there is any particular reason why you’ve settled on the frequency you have, please shar...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement