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.

Where Next?

Popular in Polls Top

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
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
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
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
arcanemachine
Now that the results are in from the Tailwind-only poll, what do you think of the combination of Tailwind and daisyUI? poll
New
spicychickensauce
There are many v0 libraries in the elixir echo system, where at least officially, semantic versioning means nothing. However, it seems t...
New
AstonJ
The stereotype for ‘geeks’ is multiple monitors! But let’s see… poll
New
josefrichter
There are two polls and a third question… 1) Displays poll 2) Orientation poll 3) Configuration Please let us know how you are using you...
New

Other popular topics Top

AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
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

We're in Beta

About us Mission Statement