• alexdeathway@programming.dev
    link
    fedilink
    arrow-up
    191
    arrow-down
    1
    ·
    edit-2
    5 months 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.

    • Croquette@sh.itjust.works
      link
      fedilink
      arrow-up
      98
      ·
      5 months 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.

          • sus@programming.dev
            link
            fedilink
            arrow-up
            3
            arrow-down
            2
            ·
            edit-2
            5 months 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

            • Rinox@feddit.it
              link
              fedilink
              arrow-up
              8
              ·
              5 months ago

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

            • redfellow@sopuli.xyz
              link
              fedilink
              arrow-up
              3
              ·
              5 months ago

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

      • 4wd@programming.dev
        link
        fedilink
        arrow-up
        20
        arrow-down
        1
        ·
        5 months 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

          • Faresh@lemmy.ml
            link
            fedilink
            English
            arrow-up
            8
            ·
            5 months 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)

  • rekabis@lemmy.ca
    link
    fedilink
    arrow-up
    74
    arrow-down
    7
    ·
    5 months ago

    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.

    • deadbeef79000@lemmy.nz
      link
      fedilink
      arrow-up
      25
      ·
      edit-2
      5 months ago

      That’s actually filtering not sorting.

      That being said, it’s more valuable (to me) to be able to find all my things for a topic quickly rather than type.

      Foo_dialog

      Foo_action

      Foo_map

      Bar_dialog

      Bar_action

      Bar_map

      Is superior IMHO.

      • rekabis@lemmy.ca
        link
        fedilink
        arrow-up
        9
        arrow-down
        3
        ·
        5 months ago

        If you are looking for Bar, it is highly likely that you are already looking specifically for a particular functionality - say, the action - for Bar. As such, it is irrelevant which method you use, both will get you to the function you need.

        Conversely, while it is likely you will want to look up all items that implement a particular functionality, it is much less likely you are going to ever need a complete listing of all functionality that an item employs; you will be targeting only one functionality for that item and will have that one functionality as the primary and concrete focus. Ergo, functionality comes first, followed by what item has that functionality.

        • deadbeef79000@lemmy.nz
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          5 months ago

          We probably have slightly different work processes.

          I’m more likely to be making “foo” functionally complete and then making “bar” complete than I am to be making all my dialogs functional then all my tabs/whatever.

          This comes from TDD where I’m making a test pass for “foo”, once done, I’ll do the same for “bar”.

          Though it’s even more likely these are different files entirely, rendering the arguments moot.

    • Static_Rocket@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      5 months ago

      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

    • 33550336@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      5 months ago

      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.

  • redcalcium@lemmy.institute
    link
    fedilink
    arrow-up
    66
    ·
    5 months ago

    I’m truly torn with this. The first one seems sensible (action -> target) and easier to read and reason about (especially with long names), while the other one looks more organized, naturally sortable and works great with any autocompletion system.

  • Caveman@lemmy.world
    link
    fedilink
    arrow-up
    47
    arrow-down
    1
    ·
    edit-2
    5 months 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

    • sudo@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      5 months 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

    • Bruno Finger@lemm.ee
      link
      fedilink
      arrow-up
      4
      ·
      5 months 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.

  • evatronic@lemm.ee
    link
    fedilink
    English
    arrow-up
    43
    ·
    5 months ago

    I do one, the other senior dev does the other. We fight about it in pull requests.

    • livingcoder@programming.dev
      link
      fedilink
      arrow-up
      31
      ·
      5 months ago

      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.

      • evatronic@lemm.ee
        link
        fedilink
        English
        arrow-up
        17
        ·
        5 months ago

        Preachin to the choir, friend. I’d get worked up about it but I’m paid the same regardless of how upset I get.

        • locuester@lemmy.zip
          link
          fedilink
          English
          arrow-up
          2
          ·
          5 months ago

          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.

  • Hazzia@discuss.tchncs.de
    link
    fedilink
    arrow-up
    25
    ·
    5 months 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.

    • ooterness@lemmy.world
      link
      fedilink
      English
      arrow-up
      22
      ·
      5 months 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@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      5 months 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?

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    20
    arrow-down
    1
    ·
    5 months 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

  • Agent641@lemmy.world
    link
    fedilink
    arrow-up
    14
    ·
    5 months 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.