this post was submitted on 27 May 2024
714 points (97.9% liked)

Programmer Humor

19623 readers
28 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.

top 50 comments
sorted by: hot top controversial new old
[–] alexdeathway@programming.dev 201 points 5 months ago* (last edited 5 months ago) (3 children)

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 101 points 5 months ago (2 children)

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.

[–] db0@lemmy.dbzer0.com 114 points 5 months ago (1 children)

is_dialog_file_open

fite me

[–] TheSlad@sh.itjust.works 58 points 5 months ago (3 children)

No fiting. IS always goes at the start of names for booleans you are correct

load more comments (3 replies)
[–] fourwd@programming.dev 18 points 5 months ago (4 children)

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

[–] alexdeathway@programming.dev 9 points 5 months ago* (last edited 5 months ago) (1 children)

does '?' have type definition in elixir or this is generally agreed design pattern?

[–] Faresh@lemmy.ml 8 points 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)

load more comments (3 replies)
[–] Yondoza@sh.itjust.works 25 points 5 months ago* (last edited 5 months ago)

This is the way.

Command statement = an action

Question statement = a status

load more comments (1 replies)
[–] redcalcium@lemmy.institute 70 points 5 months ago (2 children)

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.

[–] And009@lemmynsfw.com 18 points 5 months ago (1 children)

Not a programmer, but I'd prefer right naming convention because sorting

[–] Lightfire228@pawb.social 13 points 5 months ago (1 children)

I am a programmer, and i also like the naming scheme on the right

Especially for things like filenames

[–] bitwolf@lemmy.one 9 points 5 months ago* (last edited 5 months ago)

Also a programmer and think method names would be conducive using little endian.

TopicGet()
TopicCreate()
TopicDelete()

Writing this I realize we do this implicitly in some instances.

http.Get() -> httpGet()
http.Post() -> httpPost()
[–] kunaltyagi@programming.dev 15 points 5 months ago (3 children)

We need a new framework, one that allows universal lookup, and makes life easier

x = _.dialog.file.open
y = _.open.file.dialog
z = _.file.open.dialog
a = _.file.dialog.open

Once done, the formatter simply changes everything to _.open.file.dialog

Let's get this done JS peeps

\s

[–] Ziglin@lemmy.world 8 points 5 months ago

Aahh you can't just make this problem object oriented!

C programmers don't like that.

load more comments (2 replies)
[–] rekabis@lemmy.ca 69 points 5 months ago (3 children)

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 25 points 5 months ago* (last edited 5 months ago) (4 children)

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.

load more comments (4 replies)
load more comments (2 replies)
[–] morrowind@lemmy.ml 63 points 5 months ago (3 children)

Where's file_dialogue_open

[–] xmunk@sh.itjust.works 37 points 5 months ago

We're all trying our best to ignore the Americans and you bring up m/d/y... why!

[–] verstra@programming.dev 27 points 5 months ago* (last edited 5 months ago) (7 children)

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

[–] MonkCanatella@sh.itjust.works 9 points 5 months ago

literally spanish lol

load more comments (6 replies)
[–] janAkali@lemmy.one 11 points 5 months ago

To be fair, it's also missing open_dialog_file, dialog_open_file and most crucially file_open_dialog

[–] olafurp@lemmy.world 47 points 5 months ago* (last edited 5 months ago) (2 children)

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

load more comments (2 replies)
[–] evatronic@lemm.ee 47 points 5 months ago (2 children)

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

[–] livingcoder@programming.dev 36 points 5 months ago (3 children)

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 20 points 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.

load more comments (2 replies)
load more comments (1 replies)
[–] Fish@midwest.social 23 points 5 months ago

Variety is the spice of life.

[–] todd_bonzalez@lemm.ee 22 points 5 months ago

Mmmmmmmm... Lexicographical Endianness.

[–] onlinepersona@programming.dev 19 points 5 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

load more comments (1 replies)
[–] cupcakezealot@lemmy.blahaj.zone 18 points 5 months ago (3 children)

the people who chose the first one...who hurt you?

[–] habl@lemmy.world 25 points 5 months ago
[–] MechanicalJester@lemm.ee 11 points 5 months ago (2 children)

No one, it just makes sense.

You must be one of those "Throw your mother downstairs, the box of tissues" types.

Yoda sounded normal to you I bet.

[–] loudWaterEnjoyer@lemmy.dbzer0.com 10 points 5 months ago (1 children)

It makes sense until you write 30 methods to manipulate the data layer.

load more comments (1 replies)
load more comments (1 replies)
load more comments (1 replies)
[–] dariusj18@lemmy.world 18 points 5 months ago (1 children)
load more comments (1 replies)
[–] jjjalljs@ttrpg.network 17 points 5 months ago (2 children)

I worked at a place where all the DB column names were like id_user, id_project. I hated it.

load more comments (2 replies)
[–] roon@lemmy.ml 16 points 5 months ago

Powershell has a lint warning for functions that don't follow Verb-Noun format, and verbs here are a list of approved verbs lol

[–] Goodie@lemmy.world 15 points 5 months ago

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.

[–] nikaaa@lemmy.world 15 points 5 months ago

I personally prefer dialogs.FileDialog.open()

[–] Agent641@lemmy.world 14 points 5 months ago (1 children)

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.

load more comments (1 replies)
[–] MrOxiMoron@lemmy.world 13 points 5 months ago (3 children)
[–] PenisWenisGenius@lemmynsfw.com 30 points 5 months ago* (last edited 5 months ago)

New file

New file (2)

New file (3)

New file (4)

[–] mexicancartel@lemmy.dbzer0.com 10 points 5 months ago (2 children)
load more comments (2 replies)
load more comments (1 replies)
[–] devfuuu@lemmy.world 12 points 5 months ago
[–] jarfil@beehaw.org 12 points 5 months ago* (last edited 5 months ago)

Both:

dialog_error = Dialog_plain.create_modal(error_text)

Variable and class names go from more general to more particular, functions begin with a verb.

Global functions are either "main", or start with one of "debug", "todo", or "shit".

[–] crispy_kilt@feddit.de 11 points 5 months ago (5 children)

First of all, it's spelled dialogue

[–] Sotuanduso@lemm.ee 14 points 5 months ago

Two wars can exist simultaneously.

load more comments (4 replies)
[–] Matty_r@programming.dev 9 points 5 months ago* (last edited 5 months ago) (1 children)

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)

[–] locuester@lemmy.zip 8 points 5 months ago

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

load more comments
view more: next ›