• onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    21
    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