this post was submitted on 27 May 2024
711 points (97.8% liked)

Programmer Humor

18947 readers
239 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] onlinepersona@programming.dev 19 points 2 months ago (1 children)

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

I agree with you especially on the definition order of functions. I, too, define main() first.