this post was submitted on 28 May 2025
633 points (96.3% liked)

Programmer Humor

23527 readers
2874 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 2 years ago
MODERATORS
 

Also, do y'all call main() in the if block or do you just put the code you want to run in the if block?

top 50 comments
sorted by: hot top controversial new old
[–] dariusj18@lemmy.world 3 points 2 hours ago

The if block is where my arg parser goes

[–] driving_crooner@lemmy.eco.br 6 points 10 hours ago

Does everyone call the function of the script main? I never use main(), just call the function what the program is supposed to do, this program calculates the IBNR? The function is called calculate_IBNR(), then at the end of the script if name = 'main': calculate_IBNR(test_params) to test de script, then is imported into a tkinter script to be converter to an exe with pyinstaller

[–] JATtho@lemmy.world 12 points 13 hours ago (1 children)

I would put my code in a def main(), so that the local names don't escape into the module scope:

if __name__ == '__main__':
    def main():
        print('/s')
    main()

(I didn't see this one yet here.)

[–] YourShadowDani@lemm.ee 3 points 13 hours ago (1 children)

I'm a little new to Python standards. Is this better or worse than putting the def main(): outside the if statement (but calling main() inside it)

[–] JATtho@lemmy.world 2 points 11 hours ago

I intended this an sarcastic example; I think it's worse than putting the main outside of the branch because of the extra indent-level. It does have an upside that the main() doesn't exist if you try import this as an module.

[–] barsoap@lemm.ee 9 points 14 hours ago
[–] laurelraven@lemmy.zip 36 points 20 hours ago (2 children)

One thing I really dislike about Python is the double underscore thing, just really looks ugly to me and feels excessive. Just give me my flow control characters that aren't whitespace

[–] atx_aquarian@lemmy.world 3 points 12 hours ago

I'm at peace with balanced underscores (like "dunder name equals dunder main") and the internal ones for snake case, but in the unbalanced ones (prefixing unders and dunders for pseudo-private) still bug me. But at least, conventionally, it's visually the same idea as Hungarian notation.

load more comments (1 replies)
[–] MTK@lemmy.world 20 points 19 hours ago* (last edited 19 hours ago) (3 children)

It really doesn't. It's a scripting language, functions are there but at it's core it runs a script. The issue is that it was so easy to start with that people started doing everything in it, even though it sucks for anything past complex scripts

It is the excel of databases.

[–] frezik@midwest.social 11 points 15 hours ago (15 children)

What's the difference between a "scripting" language and a "real" one?

[–] JackbyDev@programming.dev 1 points 4 hours ago

Scripting languages are real. Generally people consider dynamic languages scripting languages but it's not that simple.

load more comments (14 replies)
[–] Anomalocaris@lemm.ee 5 points 13 hours ago (4 children)

compared with other languages at the time, the ease of access and readability makes it worth it. plus, the heavy duty stuff is usually handled by more optimised code line numpy or sklearn...

load more comments (4 replies)
[–] the_crotch@sh.itjust.works 8 points 15 hours ago

Excel recently added the ability to run python code lol

[–] d_k_bo@feddit.org 29 points 21 hours ago* (last edited 21 hours ago) (1 children)

Still better than having to create a new class just to implement

public static void main(String[] args) {}

Relevant Fireship video: https://youtu.be/m4-HM_sCvtQ

[–] Damarus@feddit.org 17 points 20 hours ago (3 children)
[–] frezik@midwest.social 14 points 15 hours ago

Only took 27 years to make the Java "Hello, world!" kinda sane.

load more comments (2 replies)
load more comments
view more: next ›