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
101 points

I tend to add is to booleans toreally differentiate between a method name and a status.

def open_file_dialog(self):
    self.dialog_file_is_open = True
    pass

That way, it’s easier for my dumb brain to spot which is which at a glance.

permalink
report
parent
reply
114 points

is_dialog_file_open

fite me

permalink
report
parent
reply
58 points

No fiting. IS always goes at the start of names for booleans you are correct

permalink
report
parent
reply
2 points
*

that works for 2 word names eg is_open or is_file, but in this case is_dialog_file_open is structured like a question, while dialog_file_is_open is structured like a statement

permalink
report
parent
reply
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

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