this post was submitted on 08 Jan 2025
878 points (100.0% liked)

Programmer Humor

22262 readers
81 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
 
all 49 comments
sorted by: hot top controversial new old
[–] Diplomjodler3@lemmy.world 134 points 3 months ago (4 children)

For our American friends: the Opel Corsa is a car.

[–] plunged_ewe@lemmy.world 62 points 3 months ago (1 children)

For the Brits, it's a Vauxhall Corsa.

[–] M33@lemmy.sdf.org 40 points 3 months ago (1 children)

For everyone : it’s a sh’tbox (never again)

[–] passiveaggressivesonar@lemmy.world 12 points 3 months ago (1 children)

Ok now how do you cast the spell "float" on it

[–] Anivia@feddit.org 7 points 2 months ago

Calling it a car may be an exaggeration

[–] mindbleach@sh.itjust.works 2 points 2 months ago
[–] Kushan@lemmy.world 116 points 3 months ago (2 children)

Rust is completely correct to be a dick about it as well. Type safety is there for a reason.

[–] frezik@midwest.social 7 points 2 months ago* (last edited 2 months ago) (1 children)

Edit: for any possible future readers, there is a sensible default that I hadn't found yet during this work in progress. It's just in a different struct: SaltString::generate().

I'd like it better if things were designed to work together better.

Right now, I'm working on a password storage system using the password_hash crate. You need to provide the salt yourself; this is already a bit silly for not providing a simple default that just gives you 16 bytes from a CSPRNG, but let's continue.

You read the Salt struct documentation, and it talks about UUIDs being pretty good salts (well, using v4, anyway). So that pushes you toward the uuid crate, right? Except no. That crate doesn't produce formats that the functions on the Salt struct will accept, like base64. So maybe the uuid_b64 crate will do it? I don't think so, because that crate uses a URL-safe version of base64, and it's not clear Salt will take that, either.

You're now forced to use a cumbersome interface from the rand crate to make your salt. I'm still working through some of the "size not known at compile time" errors from this approach.

All of which would work better if there was a little thought into connecting the pieces together, or just providing a default salt generator that's going to do the right thing 90% of the time.

Don't get me started on how Actix hasn't thought through how automated testing is supposed to work.

[–] Kushan@lemmy.world 3 points 2 months ago* (last edited 2 months ago) (1 children)

Am I correct in saying that you're used to languages that aren't type safe? Or at least not as strict about it.

Everything you're describing sounds more like you're struggling with type safety in general and I wouldn't say any of those packages are at fault, in fact I'd even go further and say they're like that by design.

The reason you don't actually want any of those separate packages to be more interoperable out of the box is because that would couple them together. That would mean dependencies on those packages, it would mean if it wanted to use something else then you'd be a bit stuck.

Like I'd question using a uuid as a salt, like it's fine and I get why they're suggesting it, but you can use anything as a salt so why couple yourself to a specific uuid library? Why couple yourself to uuids at all.

Side note: I'm guessing the reason the crate expects you to supply your own salt is because you need to also store the salt next to the password hash, if it generated the salt for you there's a chance you might ignore the salt and suddenly not be able to validate passwords.

Anyway....

The only way you could make these separate packages work dramatically together and without coupling them would be to use a universal type - probably a byte array - and at that point you lose most of the benefits of a strong type system. What are currently compile errors become runtime errors, which are much worse and harder to diagnose.

My suggestion to you would be to reframe your thinking a little, think less about how you can make different crates speak to each other and more about how you convert from one type to another - once you crack that, all of these integration problems will go away.

[–] frezik@midwest.social 2 points 2 months ago* (last edited 2 months ago)

None of this has much to do with type safety at all. A dynamically typed language might have a Salt object that has a constructor that takes a base64 string. If its common uuid library doesn't output base64, then you can't use it directly.

Nor does a specific uuid library matter much. It just needs to be able to output base64 strings, which is an uncommon uuid encoding, but it's out there.

Nor does type safety prevent providing a sensible default implementation.

The crate uses phc strings, which store the salt together with the hashed password, so no, it can handle it all on its own.

There was just no thought into how components work together.

[–] Ephera@lemmy.ml 6 points 3 months ago

Yeah, gotta newtype it up to make it even more relentless.

[–] DannyBoy@sh.itjust.works 116 points 3 months ago (2 children)

You wouldn't typecast a car.

[–] mogranja@lemmy.world 13 points 2 months ago

What about typecasting to a car?

[–] qarbone@lemmy.world 9 points 2 months ago

I may be on the wrong side of history but I can't see what other role a car could get in the film industry except vehicle.

[–] Limonene@lemmy.world 77 points 3 months ago (2 children)

C when I cast a char * * to a char * * const: ok

C when I cast a char * * to a char * const *: ok

C when I cast a char * * to a char const * *: WTF

C when I cast a char * * to a char const * const *: ok

[–] xep@fedia.io 43 points 3 months ago

The WTF case isn't allowed because it would allow modification of the const. From https://en.cppreference.com/w/cpp/language/implicit_conversion

int main() { const char c = 'c'; char* pc; char** ppc = &pc; const char** pcc = ppc; // Error: not the same as cv-unqualified char**, no implicit conversion. *pcc = &c; *pc = 'C'; // If the erroneous assignment above is allowed, the const object “c” may be modified. }

[–] SaharaMaleikuhm@feddit.org 24 points 3 months ago

Please stop, I have CPTSD.

[–] mlg@lemmy.world 73 points 3 months ago (2 children)

Hey at least it's not JavaScript which is perpetually high on crack with Object object

[–] bleistift2@sopuli.xyz 16 points 3 months ago (1 children)

Well, that happens when you don’t override the toString method. Not worse than Java’s 0xf00cu

[–] anton@lemmy.blahaj.zone 4 points 2 months ago

Hey, javas default toString gives you two informations:

  • type, not that the class names in many java projects are informative
  • identity, while the pointers are gibberish you can see if they are the same gibberish
[–] UnfortunateShort@lemmy.world 48 points 2 months ago* (last edited 2 months ago) (2 children)

In bigger projects, you tend to miss type safety really bad, really fast. Rust has it built in, Python can have it bolted on. That's simply one of the many aspects to consider when choosing your programming language.

But don't worry about it too much. If one thing's for sure, it's that you will regret that choice in any case.

[–] myxi@toast.ooo 3 points 2 months ago* (last edited 2 months ago)

Yeah I usually love Python but right now I'm working on a paid project where I need to deal with tasks that are critical to mostly work on first try. Now, if it would be a different matter if my code was just completely idiotic and still worked but Python doesn't error even when there is obvious typo that any statically compiled language could've picked up on a breeze at compile time.

I am scared to even implement a better logging system in my program because sometimes I forget to sanitize the arguments and my program fucking crashes at runtime because I added a new fucking logging statement.

I so fucking wish I had static type checking right now. The libraries I am using doesn't have types (via annotations) so unless I spend days fixing their shit, I will have to continue with these shitty runtime crashes for the shittiest small mistakes. I also can't trust these annotations because even if they are "wrong" their code coul perfectly work fine and they could even ship the wrong types. I would have the burden of dealing with their shitty annotations if that happens.

[–] rumba@lemmy.zip 3 points 2 months ago* (last edited 2 months ago) (1 children)

It's like learning Perl back in the day, then needing to learn use strict;

[–] mindbleach@sh.itjust.works 4 points 2 months ago (1 children)

Perl is a write-only language.

[–] rumba@lemmy.zip 4 points 2 months ago (1 children)

I used to love it, it could look a lot like c, or you could do crap like

$_=<<'';y;\r\n;;d;$_=pack'b*',$_;$_=eval;$@&&die$@;$_

Admittedly, they're trying to obfuscate it, but even unpacking it a bit, it looks alien.

[–] mindbleach@sh.itjust.works 5 points 2 months ago (1 children)
[–] rumba@lemmy.zip 2 points 2 months ago

Yes! That was the other thing I wanted to include, but I couldn't remember the name or search for it, so I wrote it off as a fever dream!

[–] HK65@sopuli.xyz 43 points 3 months ago (2 children)

You don't even need to cast in Python, a reference is a reference.

[–] elvith@feddit.org 35 points 3 months ago

If it's loud, moving, can chase you and honks at you, then it's ~~an obnoxious goose~~ a car

[–] samus12345@lemm.ee 31 points 2 months ago* (last edited 2 months ago)

You know, I always wondered what the original image looked like, and even trusty Know Your Meme doesn't show it. It looked like this:

[–] HexesofVexes@lemmy.world 31 points 2 months ago

It works and is a pile of jank - Python

It doesn't work and is a pile of jank - C++

You violated gods laws with how bad your code is and it still runs (right through the wall) - C

[–] TomasEkeli@programming.dev 30 points 2 months ago

a compile-time error is highly preferable to a run-time error

[–] KindaABigDyl@programming.dev 24 points 3 months ago (1 children)

And that's why I don't use Python for anything more than simple scripts

[–] Juice@midwest.social 6 points 2 months ago

Look at mister "Sometimes I write programs that have more than a single niche function" over here

This is a post about growing disappointment with Python

[–] neidu3@sh.itjust.works 15 points 3 months ago (1 children)

Perl when I iterate over an object and treat the result as a hash reference: "fine, whatever. Fuck you, tho"

[–] frezik@midwest.social 1 points 2 months ago

Just wait until you come across an XS library that uses a scalar reference for its objects (like LibXML).

[–] peoplebeproblems@midwest.social 12 points 3 months ago

Yeah this was a good one to wake up to.

[–] Moc@lemmy.world 10 points 2 months ago

Do we need any more proof Python is superior?

^(^I'm ^joking, ^I ^love ^Rust)

[–] lime@feddit.nu 8 points 3 months ago

as long as you can shift it

[–] Stizzah@lemmygrad.ml 2 points 2 months ago

And that's why I love python.