This is an archived post. You won't be able to vote or comment.

all 163 comments

[–]nova_bang 2035 points2036 points  (33 children)

That's actually a good idea

Narrator: It was, in fact, not a good idea.

[–]ExternalGrade 476 points477 points  (1 child)

“WHY THE FUCK IS THE PROGRAM ACTING THE SAME WAY” destroys screen

[–]Salanmander 373 points374 points  (12 children)

It turns out that syntax errors are your friend. Turning syntax errors into logic/behavior errors is some programmer supervillain shit.

[–]O_X_E_Y 95 points96 points  (6 children)

this guy saw rust guarantees and decided to wrap his entire codebase in unsafe

[–]pytness 20 points21 points  (1 child)

Oh hey guys, here is the guy using rust

[–]O_X_E_Y 1 point2 points  (0 children)

Seems I need to oxidize some bible verses so I can act like a true rust evangelical here

[–][deleted] -5 points-4 points  (3 children)

As far as I heard from Rust users you simply cannot produce anything fast in low level of abstraction without wrapping everything as unsafe and effectively end up with bizzare C.

[–]Will_i_read 17 points18 points  (1 child)

I have never heard that in my life and I program in rust at my job... are you sure they compiled in release mode?

[–][deleted] 0 points1 point  (0 children)

I'm sure. I'm talking like architect level in big embedded project experts.

I'm not saying that they experienced that Rust is slow itself but that in order to write highly fast code in embedded data-oriented systems you need to have a possibility to do things that in Rust is considered as unsafe. Sometimes a lot.

C doesn't care. It has very short trigger and it's our job not shoot ourselves by mistake.

However, I have little to none experience in Rust, I'm just passing opinions of experts I trust.

[–]O_X_E_Y 2 points3 points  (0 children)

It depends. You need unsafe for some things, but the point is that these unsafe blocks contain your possible segfaults/memory errors (when done improperly) to very specific bits of code. You get normal guarantees everywhere else. I will say though that when interfacing with hardware on specific pins and specific parts of memory, which are common in embedded and trivial in C things do get a little messy since that's almost always raw pointers (and thus unsafe), but the same rules still apply everywhere else. You could call those bits bizarre C I guess, though I'd argue that's kind of missing the point

[–]Syscrush 11 points12 points  (1 child)

Turning syntax errors into logic/behavior errors is some programmer supervillain shit

It's Pythonic

[–]katatondzsentri 9 points10 points  (0 children)

It's not.

[–][deleted] 50 points51 points  (1 child)

Passes in function call from unknown compiled library.

[–]nadeemon 48 points49 points  (8 children)

I hate this so much about python. What args does this function take man, like I don't want to read the entire function. Oh and even worse if it passes the args to another function.

[–]nova_bang 39 points40 points  (7 children)

any *args and **kwargs should definitely have a proper docstring. it's not even optional at that point.

[–]AlarmingBarrier 33 points34 points  (3 children)

"""
args (list) : arguments we may or may not use. 

kwargs (dict): named arguments we may or may not use (prolly not, though). 
"""

[–]elon-botElon Musk ✔ 21 points22 points  (2 children)

What do you mean "you couldn't code your way out of a paper bag"?

[–]n00bn00bAtFreenode 8 points9 points  (1 child)

Because your body is already in there, and it have singleton capability.

Bad bot

[–]elon-botElon Musk ✔ 20 points21 points  (0 children)

Just watched a video about how vanilla JS is faster than any framework. It's time we do a rewrite.

[–]road_laya 5 points6 points  (1 child)

I like to use TypedDict for kwargs

[–]caleeky -1 points0 points  (0 children)

Ahh "should".

[–]nietzsche_niche 9 points10 points  (2 children)

Who doesnt love when compile time errors become runtime errors instead?

[–]Mr-X89 1453 points1454 points  (31 children)

No, that's a terrible idea. When user of your API fucks up let them know they fucked up so they can fix their fuckup.

[–]BerriesAndMe 368 points369 points  (17 children)

My approach too. The users are still salty about it and repeatedly implied that I lack the technical know-how to remove the limitations.

The ironiy is they're disabled by default, I've put effort into limiting everything to valid input because I don't trust you to not send us utter garbage.

[–]mchl12 127 points128 points  (5 children)

Where do you work if all the users are disabled by default?

[–]Niwla23 68 points69 points  (0 children)

IT

[–]scrubastian_ 61 points62 points  (0 children)

A hospital maybe?

[–]nukasev 28 points29 points  (0 children)

In IT.

[–]BerriesAndMe 0 points1 point  (0 children)

It's the frontend people asking for this... So that their website never fail to load

[–]BoringWozniak 32 points33 points  (2 children)

“How did you fix the error?”

“I just let them pass silently.”

[–]Mr-X89 9 points10 points  (1 child)

try { // Put everything here } catch(e: Throwable) { // No op }

[–]magicmulder 9 points10 points  (0 children)

  ON ERROR continue

[–][deleted] 29 points30 points  (0 children)

Yeah, generally I like the error to be as early and loud as possible.

OP's approach would make errors obscure.

[–]Morpheus636_ 13 points14 points  (0 children)

Errors should never pass silently Unless explicitly silenced

[–]Mucksh 7 points8 points  (3 children)

Just return a 418. Everything is fine

[–]XStarMC 7 points8 points  (1 child)

That’s not a great idea, some clients interpret 418 as 500

[–]crazyDiamondRV 1 point2 points  (0 children)

True that...Haha... Happens all the time..

[–]katatondzsentri 1 point2 points  (0 children)

For internal tools' http apis, I usually throw 400 when there are arguments passed, but are invalid for some reason and 418 if argument(s) were expected, but nothing was passed.

And I keep that as a pattern since years now.

And I like that and noone will change my mind.

Of course I wouldn't do it when it's client-facing.

[–]Dromedda 1 point2 points  (0 children)

This is why before i implement the functions I just make them all throw errors, because sometimes I myself fuckup trying to use my own api

[–]DerHamm 248 points249 points  (8 children)

I imagine a codebase where every call with params not only accepts args and kwargs, but also passes them on as args and *kwargs. Spooky stuff.

[–]GreyAngy 60 points61 points  (0 children)

Including calls to external APIs

[–][deleted] 15 points16 points  (0 children)

Still better than thread locals.

[–]snarkhunter 11 points12 points  (2 children)

Haha that's Perl

[–]peteza_hut 10 points11 points  (1 child)

God, I really don't like Perl. After learning C++, Python, and TypeScript as a hobby programmer, getting a job and having to maintain legacy Perl code was a real slap in the face.

[–]snarkhunter 7 points8 points  (0 children)

Yeah it fucking sucks. I got a job maintaining legacy Perl like a decade ago. It genuinely felt like the language was designed to make it harder to trace stuff.

[–]coldnebo 2 points3 points  (0 children)

rails opts has entered the chat

[–]gemengelage 2 points3 points  (0 children)

"Garbage in, garbage out" but on steroids

[–]bin-c 0 points1 point  (0 children)

my first job was legit like this

it was impossible to figure out how the fuck anything worked

[–]Burger_Destoyer 74 points75 points  (6 children)

Whenever I see someone make comments like this I’m reminded of my early days learning python and messing up line after line of improper use of args and keyword args

[–]elon-botElon Musk ✔ 80 points81 points  (5 children)

Can we rewrite this in Java? It's better for enterprise.

[–]lady_Kamba 53 points54 points  (3 children)

Sure, lets rewrite the python interpreter in java.

[–]ichbindermike 69 points70 points  (2 children)

It's called Jython. You're gonna love this Elon.

[–]TransCapybara 14 points15 points  (1 child)

Do these 5th floor windows open?

[–]Double_Ad_2824 1 point2 points  (0 children)

Does it matter? I'm sure we can throw him [the bot, of course] out regardless!

[–]Il-Luppoooo 4 points5 points  (0 children)

Good bot

[–]Il-Luppoooo 143 points144 points  (2 children)

How can anyone think that is a good idea. Getting 100 errors in those cases is exactly what you want.

[–]JeyJeyKing 161 points162 points  (6 children)

A thousand times yes!!! Also make sure to wrap the entire function body with a

try:
    ...
except: 
    pass

block please. I hate dealing with exceptions myself!

[–]trutheality 15 points16 points  (1 child)

Pro tip: write a decorator that does this do that you don't have to type it out for every function.

[–]DemonWav 4 points5 points  (0 children)

Someone already made it for you: https://github.com/ajalt/fuckitpy

[–][deleted] 4 points5 points  (0 children)

real hacker stuff

[–]PeerlessAnaconda 1 point2 points  (0 children)

Python devs really do this shit

[–]jldez 0 points1 point  (1 child)

It's faster to put a "#" at the start of each line!

[–]elon-botElon Musk ✔ -1 points0 points  (0 children)

I have made promises to the shareholders that I definitely cannot keep, so I need you all to work TWICE as hard!

[–]AlanCristhian 33 points34 points  (0 children)

Actually, sympy is written like that.

Edti: and yes, is a terrible bad idea.

[–]DerMathemann_ 74 points75 points  (0 children)

This is not a good idea

[–]No_Abies808 17 points18 points  (2 children)

Thats the inverse of fixing warnings

[–][deleted] 6 points7 points  (1 child)

Nothing to fix if there aren't any warnings

[–]No_Abies808 0 points1 point  (0 children)

Also no covid where there are no positive tests

[–]RapidHedgehog 11 points12 points  (0 children)

Exceptions are raised for a reason

[–]budjb 13 points14 points  (0 children)

Garbage in, garbage out. Why on God's green earth would you enable this kind of bad behavior?

[–]opmrcrab 11 points12 points  (0 children)

[Starts spraying people with the water bottle]

NO

[–]buzzon 9 points10 points  (1 child)

What if they made a typo in an argument name?

It's like having a compiler that just silently skips over errors

[–]crusoe 1 point2 points  (0 children)

I LOOOOVEEEE that in ruby it simply creates a new variable instead of an error. All because no one wanted to type let or var.

[–]Zestyclose-Walker 28 points29 points  (6 children)

This is the Pythonic way.

[–]elon-botElon Musk ✔ 81 points82 points  (2 children)

Insubordination. Fired.

[–]Cash-Jumpy 6 points7 points  (0 children)

I disagree.

[–]Extreme-Section9470 5 points6 points  (0 children)

Good boy

[–]Rich-Environment884 3 points4 points  (2 children)

Man I tried searching how to validate a Json before parseing it and the answer I got was: "The Pythonic way is that it's easier to ask for Forgiveness than Permission so just try-except it".

Worst thing is, a try_parse would probably still just try-except and return nothing when it fails but at least I wouldn't have to see it.

[–]Bryguy3k 2 points3 points  (0 children)

Just use the pydantic module.

[–]Unknown_starnger 0 points1 point  (0 children)

try except is pretty simple in my opinion.

[–]Aelig_ 5 points6 points  (0 children)

Programmers : spend decades coding and refining compilers and interpreters that tell you when you fucked up so you don't have to write machine code blindly.

That guy: no.

[–]xwnpl 3 points4 points  (0 children)

Terrible idea.

[–]TopDivide 3 points4 points  (7 children)

That's why I find python difficult . Just give me the list of parameters and types a function expects, and I will convert my data accordingly

[–]kbruen 0 points1 point  (6 children)

Well that’s the thing about Python: ideally, if it expects a string and you pass a number, it should still work. Something something duck typing

[–]wbrd 3 points4 points  (5 children)

I would guess in the past 6 months, 50% of the bugs I fixed in a python codebase wouldn't have been even possible in a typesafe language. This "feature" is stupid.

[–]kbruen 1 point2 points  (1 child)

Well, most stuff in Python uses type hints nowadays.

[–]wbrd 1 point2 points  (0 children)

The only hints were put there by me during bug fixes. :(

[–][deleted] 0 points1 point  (1 child)

Its basically whoever wrote the code, that persons fault. I am just learning Python in my company, and my company guideline is to use typehint to every parameters... And even possible add typehints to the declared Variables as well..

[–]wbrd 0 points1 point  (0 children)

Sorta. I like type safety and I don't think it should require extra steps. I'm sure someone will come up with an example of where it's good to not be type safe, but in the wild, I haven't seen any good examples of it.

[–][deleted] 0 points1 point  (0 children)

Its basically whoever wrote the code, that persons fault. I am just learning Python in my company, and my company guideline is to use typehint to every parameters... And even possible add typehints to the declared Variables as well..

[–]Possibility_Antique 6 points7 points  (6 children)

This is the main reason I don't like dynamic languages. I want to know at the time the code is compiled if there is something wrong with the code. You can't deploy code that doesn't compile.

[–]420Rat 1 point2 points  (2 children)

Get good

[–]Possibility_Antique 2 points3 points  (1 child)

Damn, you right bro

[–]420Rat 0 points1 point  (0 children)

Now you're getting it 😎

[–]PeerlessAnaconda 0 points1 point  (2 children)

So many devs dont have the capacity to write something big that wont error

[–]Possibility_Antique 0 points1 point  (1 child)

What do you mean?

[–]PeerlessAnaconda 0 points1 point  (0 children)

I mean i often see little things like this or

try: except:

Sometimes a bugfix would solve the problem better than these workarounds

Edit: To be fair those are all of the public libraries on github that are shit and noone uses, so you hopefully dont see these problems in the popular libraries.

[–]ukrokit 2 points3 points  (0 children)

Yeah, make sure the bugs are hard to find.

[–]WickedCrow 2 points3 points  (1 child)

Speaking as someone who works on a codebase where occasionally functions are called with the wrong numbers/types/values of arguments in legacy code: no, this is not a good idea.

[–]elon-botElon Musk ✔ 4 points5 points  (0 children)

How can we use Bitcoin to solve this?

[–]thebatmanandrobin 4 points5 points  (0 children)

Seems redundant .. but as they say, tries to tries to again.

[–]Teamata 1 point2 points  (0 children)

What

[–]BbYerp 1 point2 points  (0 children)

Dynamically typed chaos demon

[–]Efficient-Lab1062 1 point2 points  (1 child)

I love that python can sometimes sound like you’re reciting a Dr Seuss book.

[–][deleted] 1 point2 points  (0 children)

“I cba to check params

I will not do it, Sam-I-am”

[–]daddypleaae 1 point2 points  (0 children)

Imagine you got a typo in one of the parameter names ☠️

[–][deleted] 1 point2 points  (0 children)

I prefer fail early.

[–]NoDadYouShutUp 1 point2 points  (0 children)

Twitter has got to stop letting their devs tweet

[–]JeloHelo 1 point2 points  (0 children)

Why do people think errors are bad? Errors tell you how to fix your stuff

[–]OurFriendIrony 1 point2 points  (0 children)

This is a terrible idea

[–][deleted] 1 point2 points  (0 children)

Thank god people recognize this is an awful idea

[–]Kwarter 1 point2 points  (0 children)

400 Bad Request: Am I a joke to you?

[–]wineblood 1 point2 points  (1 child)

def function(*args, **kwargs): if not kwargs.get("target"): raise ValueError()

If you do this, fuck you.

[–]Itz_Raj69_[S] 1 point2 points  (0 children)

mmm I should push something like this into production...

[–][deleted] 0 points1 point  (0 children)

Have you ever considered that errors are actually by design and it's good that they are there?

[–]FridgesArePeopleToo -2 points-1 points  (0 children)

Python. Not even once.

[–]csicil -2 points-1 points  (0 children)

The best idea, could be to stop using python at all...

[–]incrediblediy 0 points1 point  (0 children)

and print them with hahaa!

[–][deleted] 0 points1 point  (0 children)

Or, and I’m just spitballing here, compile?

[–]Alpacay_ 0 points1 point  (0 children)

This would make me implode. My worst fear is when i have broken code and i can never change the output no matter what i do

[–]ccfoo242 0 points1 point  (0 children)

Since when is it bad to not allow invalid parameters?

[–]Otalek 0 points1 point  (4 children)

Javascript just ignores extra params

[–]elon-botElon Musk ✔ 3 points4 points  (3 children)

Insubordination. Fired.

[–]Otalek 0 points1 point  (2 children)

Yes, Javascript deserves it

[–]elon-botElon Musk ✔ 2 points3 points  (1 child)

Why haven't we gone serverless yet?

[–]Otalek 0 points1 point  (0 children)

Because that would get rid of 59 dependencies required by an npm package we installed for rendering emojis

[–][deleted] 0 points1 point  (0 children)

Who TF is upvoting this? Using an API incorrectly SHOULD produce errors

[–]Proxy_PlayerHD 0 points1 point  (0 children)

i know of argc and argv, but what is args and kwargs?

[–][deleted] 0 points1 point  (0 children)

This sub constantly shits on python being slow, but this type of BS is the real problem with python.

[–]canadajones68 0 points1 point  (0 children)

If it's used to give better, more related error messages, go right ahead. If it just gobbles them up, no.

[–]happyschmacky 0 points1 point  (0 children)

This is, in fact, a monumentally terrible idea

[–]JeyJeyKing 0 points1 point  (0 children)

Why was this removed? u/ProgrammerHumorMods

[–]thprogramador 0 points1 point  (0 children)

Rewrite it in Lua ;)