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

AstonJ
Do you have any favourites? (You can pick up to three) poll See post below for details:
New
AstonJ
We had a thread here recently that mentioned webservers in PHP, and it got me curious about the options in the BEAM world and what everyo...
New
New
thojanssens1
In an attempt to figure out what are the preferred GraphQL clients for Elixir developers, I made this poll below. If you’re using GraphQL...
New
AstonJ
poll asdf Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more Manage multiple runtime versions with a ...
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
AstonJ
Curious whether you remap your Caps Lock key.. Do you remap your Caps Lock key? poll I have no idea what Globe is btw, just seen it in t...
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
AstonJ
Polls are a great way to easily get a snapshot of things, and we’ve had some really interesting polls over the years! Here are some tips...
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

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement