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.
Romance language word order noun_descriptor is the right way.
We just call those Smurf names.
Be php, mix and match
let the chaos reign
I know I’m late to this but here’s my (probably insane?) take. We use Subject-Verb-Object in English right? So, hear me out:
dialog_create_tab(...) dialog_open_file(...) dialog_close_file(...)
Yes.
Where’s
file_dialogue_open
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
Heathen! You must alphabetize all the things!
Like seriously. It makes scanning code much easier.
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.
That’s because they are romance languages. They come from Latin where word order is irrelevant as each “word” has a different form for the specific use.
Yes, that’s what I said. My native language is a romance language too. And after speaking it her whole life, my wife has trouble getting the grasp of how in English swapping two words completely changes the meaning of what she’s saying (especially when it’s two nouns, like e.g. “parent council”)
literally spanish lol
We’re all trying our best to ignore the Americans and you bring up m/d/y… why!
To be fair, it’s also missing
open_dialog_file
,dialog_open_file
and most cruciallyfile_open_dialog
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.
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.
First of all, it’s spelled dialogue
OP’s username is in German, so it’s probably half-German-English code
Germans learn UK English
Dialogue is UK English. But I just looked it up and apparently ‘dialog’ is a computer term, but should not be used on its own but rather in combination, such as ‘dialog box’.
Americans sadly got there first and defined all the computer terms, that’s why it’s a TV programme but a computer program. I can deal with that though, helps distinguish computer things from real things!
Two wars can exist simultaneously.
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
I don’t know and that’s the problem :(
I keep asking myself what to choose, only for changing it a day after cursing myself to choose a stupid name.
Big endiant is great for intellisense to quickly browse possibilities, since it groups it all in the same place. But that’s also a detriment when you know what you want. You can start typing without the prefix but you’ll have to go through the better suggestions of intellisense first.
Little endiant is the same thing, but in reverse. Great when needed, but bad for browsing.
Although I do have some fix I’m starting to use. But it’s not applicable everywhere, and not in every language.
What I do is use module as prefix. Instead of
dialogue_file_open
, I create afile_open
in thedialogue
module, allowing either directly callingfile_open
, ordialogue::file_open
. Using intellisense on the module allow for easy browsing too!Although in OP’s post I’d rather have
file_open_dialogue
as it convey the more significant meaning, being to open a file, first. Then “dialogue” is just the flavour on topVariety is the spice of life.
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.
Create a file handler class to avoid the issue
Eww, that’s OOP
Meh, a class is just a
struct
of function pointers.
FileDialogFactory
A third option there is
A fourth there option is
sjajvxuwjdofgwu
AjsgGhS77bndugxg
gehshagfahcdvwjdvwjd
AjsgGhS77bndugxg (2)
A fifth option there is
New file
New file (2)
New file (3)
New file (4)
open_dialog_file
ordialog_open_file
?