• @[email protected]
    link
    fedilink
    9
    edit-2
    1 year ago

    The object/class/thing would normally be its own class file, the action would be a method/function of said class.

    Ie:

    fileDialog.open()

    fileDialog = Class (Dialog), Subclass (FileDialog)

    • @[email protected]
      link
      fedilink
      English
      71 year ago

      It’s referring to variable names. For example, you have a variable named fileDialog. I would prefer to have that named dialogFile.

  • @[email protected]
    link
    fedilink
    201
    edit-2
    1 year ago

    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.

    • @[email protected]
      link
      fedilink
      1011 year ago

      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.

          • @[email protected]
            link
            fedilink
            4
            edit-2
            1 year ago

            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

            • redfellow
              link
              fedilink
              31 year ago

              It still works. is_this_thing_some_thingy. Is is just a prefix for if the suffix returns true/false.

            • @[email protected]
              link
              fedilink
              81 year ago

              Doesn’t matter, the point is that, if it starts with “is” then you automatically know it’s a boolean.

      • 4wd
        link
        fedilink
        201 year ago

        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

          • @[email protected]
            link
            fedilink
            English
            81 year ago

            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)

          • @[email protected]
            link
            fedilink
            21 year ago

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

            def authorized?
              current_user&.authorized?
            end
            
            • @[email protected]
              link
              fedilink
              21 year ago

              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.

        • @[email protected]
          link
          fedilink
          31 year ago

          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’.

          • @[email protected]
            link
            fedilink
            English
            31 year ago

            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!

  • @[email protected]
    link
    fedilink
    English
    201 year ago

    I used to like the action followed by direct 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 too button.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, because main 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.

    Anti Commercial-AI license

  • Caveman
    link
    fedilink
    48
    edit-2
    1 year ago

    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 or dialog.create_file or even dialog.file.create

    • Bruno Finger
      link
      fedilink
      41 year ago

      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.

    • @[email protected]
      link
      fedilink
      51 year ago

      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

    • Terrasque
      link
      fedilink
      11 year ago

      I worked on one where the columns were datanasename_tablename_column

      They said it makes things “less confusing”

  • @[email protected]
    link
    fedilink
    3
    edit-2
    1 year ago

    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(...)
    
  • @[email protected]
    link
    fedilink
    141 year ago

    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.

  • @[email protected]
    link
    fedilink
    Cymraeg
    3
    edit-2
    1 year ago

    in general, adjectives and verbs after nouns because it’s more organized/easier to search/filter. as god intended.

  • @[email protected]
    link
    fedilink
    281 year ago

    Can’t remember which is which but if it’s organized in a top-down way (broad category first) that’s just easier to look at and find stuff in the file system. I don’t want to have to actually read and mentally process the names of every single file to figure out if it’s the one I need. Sure, the “human readable” names are fine and good when you don’t have hundreds of them you’re trying to look through, but big projects I find are way easier to parse with the category naming.

    • @[email protected]
      link
      fedilink
      English
      221 year ago

      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.

    • BlanketsWithSmallpox
      link
      fedilink
      English
      71 year ago

      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?