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.
First one are method name, second one are status name.
def open_file_dialog(self): self.dialog_file_open = True pass
Yoda level preference war.
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.
is_dialog_file_open
fite me
No fiting. IS always goes at the start of names for booleans you are correct
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
It still works. is_this_thing_some_thingy. Is is just a prefix for if the suffix returns true/false.
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_
prefixdoes ‘?’ have type definition in elixir or this is generally agreed design pattern?
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 withP
(p for predicate)
jealously weeps in ruby
We do this in Ruby all the time, we just prefer methods over variables, usually.
def authorized? current_user&.authorized? end
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.
This is the way.
Command statement = an action
Question statement = a status
There is a reason why little endian is preferred in virtually 100% of cases: sorting. Mentally or lexicographically, having the most important piece of information first will allow the correct item be found the fastest, or allow it to be discounted/ignored the quickest.
But also, sorting big endian automatically groups elements associated with common functions making search, completions, and snippets easier (if you use them). I’m torn
I was going to write something like this. You actually wrote about semantic order, but syntactically it is as much important e.g. it is easier to sort dates such as 2024-05-27 than 27.05.2024 in chronological order.
Where’s
file_dialogue_open
We’re all trying our best to ignore the Americans and you bring up m/d/y… why!
This is the real big-endian way. So your things line-up when you have all of these:
file_dialogue_open file_dialogue_close file_dropdown_open file_rename directory_remove
If I were designing a natural language, I’d put adjectives after the nouns, so you start with the important things first:
car big red
instead of
big red car
literally spanish lol
If I were designing a natural language, I’d put adjectives after the nouns, so you start with the important things first
So - French?
The thing is that in French, Spanish, etc. it still makes sense if you put the adjective before the noun, even if it might sound weird in some cases. An adjective is an adjective and a noun is a noun.
But English is positional. Where you put a word gives it its function. So “red car” and “car red” mean different things.
And “red big car” is wrong.
Heathen! You must alphabetize all the things!
Like seriously. It makes scanning code much easier.
To be fair, it’s also missing
open_dialog_file
,dialog_open_file
and most cruciallyfile_open_dialog
I do one, the other senior dev does the other. We fight about it in pull requests.
Your team needs to have a coding standards meeting where you can describe the pros and cons of each approach. You guys shouldn’t be wasting time during PR reviews on the same argument. When that happens to me, it just feels like such a waste of time.
Preachin to the choir, friend. I’d get worked up about it but I’m paid the same regardless of how upset I get.
Or they need to kit car about stuff like this since it probably doesn’t actually matter.
Agreed. This type of fun is good for the team. Trying to stamp it out, when it impacts very little, is just a buzzkill to the team.
This sounds like the typical plot of a story from The Codeless Code.
Edit: How about this story specifically?
I prefer everything to be how you would read it as text. So
create_file_dialog
it is. Honorable mention is to have it namespaced in a class or something which I think is best.file_dialog.create
ordialog.create_file
or evendialog.file.create
I agree. I say open door so the function should be named
openDoor
.Honestly nowadays none of that matter if you’re using any remotely modern IDE with good indexing and a sensible search, you can start typing however you mind works and it will find it no matter how it’s named.
My method names are the same way but I aggressively sort things into modules etc so it comes out the other way.
But if I was staring down dozens of these methods and no way to organize them, I’d start doing the sorted names just for ease of editing. L
deleted by creator
US Army logistics catalogs are organized this way. “Cookies, oatmeal” instead of “Oatmeal cookies” because it’s a lot easier to find what you need an a giant alphabetical list.
deleted by creator
How any large organization gets away with not using YYYY-MM-DD format is beyond me.
Taking over some of my previous directors files is like chaos.
How anybody publishing entire internet memos without a date being on the first page is beyond me. Like wtf am I reading a PDF from 15 years ago or last month?
Mmmmmmmm… Lexicographical Endianness.
Be php, mix and match
let the chaos reign
I used to like the
action
followed bydirect object
format, until some time ago when trying to find methods or variables related to a specific object. If the action comes first, scanning for the object without an IDE means first reading unnecessary information about the action. That convinced me to opt for$object-$action
in situations where it makes sense.For example in CSS, I often scan for the element, then the action, so
$element-$action
makes more sense. BEM kinda follows this. When dealing with the DOM in JS, that makes sense toobutton.fileDialogOpen()
,button.fileDialogSend()
, … makes more sense when searching.Of course one has to use it sensibly and where necessary. If you are writing a code that focuses more on actions than objects, putting the action first makes sense.
A similar thing is definition order.
def main(args): result = do_something(args.input) processed = process_result(result) transformed = transform_object(processed) return transformed.field def do_something(some_input): ... def process_result(result): ... def transform_object(obj): ...
I find this much easier to follow than if
main
were defined last, becausemain
is obviously the most important method and everything else is used by it. A flattened dependency tree is how these definitions make sense to me or how I would read them as newbie to a codebase.I agree with you especially on the definition order of functions. I, too, define
main()
first.
I worked at a place where all the DB column names were like
id_user
,id_project
. I hated it.I didn’t really care about this thread until I read this comment.
I worked on one where the columns were datanasename_tablename_column
They said it makes things “less confusing”
Powershell has a lint warning for functions that don’t follow Verb-Noun format, and verbs here are a list of approved verbs lol
Whatever is more useful goes first.
For example, if this we’re a list of UI text strings, finding all of the dialogue options together might be useful.
If, instead, this is a series of variables already around one dialogue, then finding the open or close bits together would be useful.
A third option there is
A fourth there option is
open_dialog_file
ordialog_open_file
?
I just name my variables a, b, c etc. If I have more than 26 variables in any given function, I name them aa, ab, ac, etc.
you’re on a highway to hell.
Yes.