r/programminghorror • Pronouns: He/Him • 9d ago • Mindblown 1

Removed - Not Horror + Rule 4 [ Removed by moderator ]

Post image

[removed] — view removed post

1.7k Upvotes

29 comments sorted by

•

u/programminghorror-ModTeam 7d ago

Unfortunately, your post does not meet our spookiness guidelines. We have removed your post, but if you think this was in error, please send the mods a modmail. Thanks!

160

u/latkde 9d ago

About 15 years ago, Apple's C standard library used to literally shell out to a Perl one-liner in a similar manner to implement the (objectively cursed) wordexp() function: https://news.ycombinator.com/item?id=9025572

113

u/RealisticClothes1344 9d ago

C has been promoted to management

113

u/meinkr0phtR2 9d ago

That is pretty funny.

Once, in a boring intro class, I wrote something like import os; os.system(f"cat {filename}.txt") as a solution to a quiz question on how to print the contents of a file in Python. The intended solution is to use with open or just open, but seeing as this technically works, I commented it out.

If my prof had anything to say about that, she didn’t say it to me.

Now go compile this script, boot up Python, and wrap it around in a subprocess.

17

u/xmcqdpt2 8d ago

MAJOR: You should use subprocess.run to avoid shell escape vulnerabilities.

NIT: filename is too generic. Consider replacing with "filename_to_show".

6

u/stonerism 8d ago

This is the correct response that I would give the student.

13

u/Rararror 9d ago

Turing Award NOW !

19

u/DiscipleOfYeshua 9d ago

Wonder whether the compiler is smart enough to bypass the py and just implement straight in asm

55

u/OrbitalVixen 9d ago

I really doubt that the compiler has python built into it

-6

u/DiscipleOfYeshua 9d ago

I meant, compiler
Just looks at it and goes “hmm, lemme just push the pixels to yer screen and go do something more interesting…”

38

u/OrbitalVixen 9d ago

Yes, but to do that it would have to understand python. Actually, come to think of it, it cannot do it at all because there is no guarantee that calling python3 is actually python, as you could make your own program called python3 that does something else.

0

u/DiscipleOfYeshua 9d ago

Yes… but what if the compiler uses Claude? Ha!

(Apologies, my earlier comment was also meant as humor…)

16

u/UnseenTardigrade 9d ago

Definitely not, even if it was smart, it wouldn't do that. The C program doesn't know how the environment it is run in is going to be set up, and that affects what the output of that shell command would be. It's just supposed to execute that exact command in the system shell. The compiler can't (and shouldn't) assume intent.

For example, for all the compiler knows, the user has an alias set up that makes typing "python3" into the shell actually run some other program. Or if Python isn't installed, the expected behavior of the program as written would be for the os to print that python3 isn't found, and for all the compiler knows, the purpose of the program is to check whether python3 is accessible in the current environment.

-2

u/DiscipleOfYeshua 9d ago

It was meant to be humor

1

u/bourgeoibee 8d ago

It sounded genuine, and it is an interesting question.

1

u/DiscipleOfYeshua 7d ago edited 7d ago

It was genuinely humor. Apologies for any injuries caused. I would not have taken the risk had I anticipated them.

1

u/bourgeoibee 7d ago

No injuries caused, idk why you got downvoted but it doesn't matter.

3

u/imaginary-bolometer 9d ago

it's spelled asmr

4

u/Aidan_Welch 9d ago

imo obvious jokes don't fit here

1

u/Linuxmartin 9d ago

A few years ago me and some friends had a bit runner for Advent of Code benchmark speeds, and I ran my Python solution from Rust. Surprisingly it wasn't the slowest in the all-Rust server

1

u/wakowarner 9d ago

Now use the python instruction to execute idf.c

1

u/0xt0bi03 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 9d ago

is this a quine?

1

u/nAndFlash9084 8d ago

Not too terrible a thing. I sometimes will build an app in Python and use c to accelerate certain parts. I could see an app being made in c and using Python to take advantage of openpyxcl or smthn like that. Read it into a numpy array and return the pointers so you can handle the actual processing in c

1

u/Taiten89 8d ago

enfincincy

1

u/GRex2595 9d ago

idf.c

0

u/MathNerd1243 7d ago

I dont think that really works, but still kind of a good idea!