DEV Community

Ankit Beniwal
Ankit Beniwal

Posted on

Scare me with your one liner

My favourite one being

sudo rm -rf /*

What is your preferred scariest one liner code?

Top comments (12)

deciduously profile image
Ben Lovy • Edited

The classic fork bomb is pretty terrifying:

:(){ :|:& };:

The function is called :. Call it scaryFunc instead:

scaryFunc() {
    scaryFunc() | scaryFunc() &
}; scaryFunc

This function recursively calls itself, then pipes it to another call of itself that gets put in the background with &, meaning the child will not die and just continually recursively call itself, blocking everything else, until it's maxed out your system resources and you crash. It's even multiple-recursive, for extra oomph. After defining the function, we call it.

Don't do this.

ankitbeniwal profile image
Ankit Beniwal

I won't do it. Pretty Scary. 😱😱

codemouse92 profile image
Jason C. McDonald • Edited

The following is the Python form of one of the most insidious anti-patterns in all of programming. The scary one-liner is the third line.

except: pass

Mike Pirnat aptly calls that the "Diaper Anti-Pattern". It's horrific because it silences all errors, expected and otherwise, leaving your program in an unresolved exceptional state with few, if any, clues as to what's wrong.

Always, always explicitly catch and handle (or at least log) your exceptions. Unhandled exceptions should always crash your program. Period.

From the Zen of Python:

Errors should never pass silently.
Unless explicitly silenced.

If you're using anything resembling the diaper anti-pattern in any language, go fix it now. Seriously. Right now. Don't make me call your mother.

Here's a runner up from Python 2...

True, False = False, True

Thankfully, that one is no longer possible in Python 3.

daniel13rady profile image
Daniel Brady

The boolean-swapping allowed by Python 2 is a great one πŸ‘ I remember when I first discovered that True and False were just builtin, mutable, global variables 😬

mutantkeyboard profile image
Antonio Nesic

I agree with Ben Lovy... typical forkbomb like this one in C

#include int main(void) { while(1) fork(); }

But even scarier is

DROP FROM Users; WHERE id = 1

or something like deleting the column from table in production database like:

ALTER TABLE Users DROP username;

ankitbeniwal profile image
Ankit Beniwal

deleting usernames is awesome. πŸ˜‚

lexlohr profile image
Alex Lohr

Watch out, a JS ghost...

jrop profile image
Jonathan Apodaca

Ha! Made me smile

weeb profile image
Patrik Kiss • Edited

Sorry, my one liner is so scary even I'm too scared of writing it down.

gadse profile image
Peter • Edited

Something I actually did. On production. But luckily before going live with a new service.

DELETE FROM products;

Since that day, I always BEGIN and either ABORT or COMMIT after triple-checking.

franksierra profile image
Frank Sierra
adnanbabakan profile image
Adnan Babakan (he/him)
rm -rf /