geteilt von: https://lemmit.online/post/3018791

This is an automated archive made by the Lemmit Bot.

The original was posted on /r/ProgrammerHumor by /u/polytopelover on 2024-05-26 21:23:20+00:00.

You are viewing a single thread.
View all comments View context
18 points

In Elixir, we mark statuses by using a question mark at the end of the variable name. Something like this:

authorized? = user |> get_something() |> ensure_authorized?()

I like this better than the is_ prefix

permalink
report
parent
reply
9 points
*

does ‘?’ have type definition in elixir or this is generally agreed design pattern?

permalink
report
parent
reply
8 points

If it’s like Lisp, then ? is just part of the symbol and doesn’t have any special syntatic meaning. In different Lisps it’s also convention to end predicate names with a ? or with P (p for predicate)

permalink
report
parent
reply
4 points

jealously weeps in ruby

permalink
report
parent
reply
2 points

We do this in Ruby all the time, we just prefer methods over variables, usually.

def authorized?
  current_user&.authorized?
end
permalink
report
parent
reply
2 points

I’m a principal backend engineer routinely writing Ruby for my day job, so I’m familiar, lol. But you can’t do it for local variables and that just sucks. Definitely a +1 for Elixir.

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 2.9K

    Monthly active users

  • 1K

    Posts

  • 38K

    Comments