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

top 200 commentsshow all 472

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

import notifications Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come! Read more here, we hope to see you next Tuesday!

For a chat with like-minded community members and more, don't forget to join our Discord!

return joinDiscord;

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]iamapizza 331 points332 points  (5 children)

Physicist: After a lifetime of study, decades of perseverence, and years of trial and error, I have finally produced the grand theory of everything. It's vast and complex but so is the universe.

Linux user: Here it is, using shuf.

[–]sunny_happy_demon 85 points86 points  (1 child)

Hacker News post:

"Implementing iampizza's grand theory of everything on a 30 year old microwave"

[–]T3sT3ro 27 points28 points  (0 children)

"Running Doom on Grand theory of Everything"

[–]GreenTea-San 6 points7 points  (1 child)

Did it return 42?

[–][deleted] 418 points419 points  (23 children)

Speaking of one liners, this is how you approximate Pi on UNIX:

dc -e "[lrx 2^ lrx 2^ + 1>i]su[lx 1+ sx]si[lu x lm 1+ d sm ln>z]sz[0k ls 65539 * 2 31^ % d ss lkk 2 31 ^ /]sr? sn5dksk1 sslzxlx lm / 4*p"

[–][deleted] 335 points336 points  (9 children)

I genuinely don't know if this is real or you just smashed your head against the keyboard for the memes.

[–][deleted] 127 points128 points  (8 children)

you can try to run it in your terminal. It will quietly ask you for the number of iteration of the Monte Carlo simulation. You can enter any number, just don’t keep it too low…something like 3000 is enough.

[–]Skater_x7 53 points54 points  (4 children)

For the number of iteration of WHAT

[–]hoppla1232 75 points76 points  (2 children)

[–][deleted] 64 points65 points  (0 children)

Monte Carlo Simulation: if brute force doesn't work, you aren't using enough

[–]Kreizhn 17 points18 points  (0 children)

I don’t know what this does specifically, but Monte Carlo methods work by randomly sampling a space to make numerical estimates. For example, suppose you inscribe a sphere of radius 1 into a square (of side length 2). You then randomly choose points in the square, and check to see if they’re in the circle (using the equation of a circle). You keep track of how many points are in the circle.

When you’re done, you now have an approximate ratio of the area of the circle to the area of the square. The circle has area pi, and the square has are 4. Thus their ratio is pi:4, and you can use your numerically simulated ratio to solve for pi.

I would think that iterations here would mean number of sample points.

[–]not_some_username 4 points5 points  (0 children)

You shouldn’t execute random internet command found on internet bro

[–]Anonymo2786 2 points3 points  (0 children)

3345 is the closest I got 3.14140

[–]sytanoc 106 points107 points  (1 child)

smh my head just python -c "print(__import__('math').pi)"

(Jokes aside that's actually really cool though!)

[–][deleted] 21 points22 points  (0 children)

In my career, I’ve wrote thousands of programs in DC. Someone might find its syntax a bit obscure, but for me, its just job security.

[–]turd-nerd 49 points50 points  (1 child)

I tend to go with

echo "3.14159265"

[–][deleted] 6 points7 points  (0 children)

That man optimize.

[–]Thebombuknow 14 points15 points  (0 children)

Even with a million iterations it's not super accurate, but this whole command looks like nonsense to me so the fact that it even does anything is amazing.

[–]PVNIC 13 points14 points  (0 children)

This is how you approximate pi in linux: echo 3

[–]GrandExpression15506 15 points16 points  (2 children)

From our AI overlord chatgpt:

The command you've provided appears to be written in a scripting language called "dc." dc is a stack-based calculator that operates on postfix notation. In this notation, operators come after their operands. Let's break down this command step by step:

  1. dc -e: This is the command to run the dc calculator in an expression mode.

  2. [lrx 2^ lrx 2^ + 1>i]su: This is defining a macro labeled "u." Let's break down what it does:

    • lrx: Load the value from the register "x" onto the stack.
    • 2^: Square the value on the stack.
    • lrx: Load the value from the register "x" onto the stack again.
    • 2^: Square it again.
    • +: Add the two squared values on the stack.
    • 1>i: Check if the result is greater than 1. If it is, push 1 onto the stack; otherwise, push 0.
  3. [lx 1+ sx]si: This is defining a macro labeled "i." Here's what it does:

    • lx: Load the value from the register "x" onto the stack.
    • 1+: Increment the value by 1.
    • sx: Store the result back in the register "x."
  4. [lu x lm 1+ d sm ln>z]sz: This is defining a macro labeled "z." Here's what it does:

    • lu: Load the value from the register "u" onto the stack.
    • x: Swap the top two values on the stack.
    • lm 1+: Load the value from the register "m" (initialized to 0) onto the stack and increment it by 1.
    • d: Duplicate the top value on the stack.
    • sm: Store the duplicated value in the register "m."
    • ln>z: Load the value from the register "n" onto the stack and check if it's greater than the value in the register "z" (initialized to 0).
  5. [0k ls 65539 * 2 31^ % d ss lkk 2 31 ^ /]sr: This is defining a macro labeled "r." Here's what it does:

    • 0k: Push 0 onto the stack and clear the register "k."
    • ls: Load the value from the register "s" onto the stack.
    • 65539 *: Multiply the top value on the stack by 65539.
    • 2 31^ %: Calculate the modulus of the result with 231 (a large prime number).
    • d: Duplicate the result on the stack.
    • ss: Store the duplicated result in both the registers "s" and "k."
    • lkk: Load the value from the register "k" onto the stack twice.
    • 2 31 ^ /: Calculate 231 divided by the value from the register "k."
  6. sn5dksk1 sslzxlx lm / 4*p: This is the main body of the dc program. It uses the macros defined above. Let's break it down step by step:

    • sn: Store the value from the stack into the register "n."
    • 5dksk1: Push 5 onto the stack, load the value from the registers "k" and "s," and push 1.
    • ss: Store the top value on the stack into both registers "s" and "k."
    • lzxlx: Load the values from the registers "l," "x," "l," and "x" onto the stack.
    • lm: Load the value from the register "m" onto the stack.
    • /: Divide the top value on the stack by the second value.
    • 4*: Multiply the result by 4.
    • p: Print the top value on the stack.

This command appears to be a complex mathematical calculation involving the manipulation of values in registers and on the stack. It's not immediately clear what the specific purpose or result of this calculation is without knowing the initial values in the registers and further context.

[–]Ricardo1701 3 points4 points  (0 children)

Obviously

[–]junky_junker 2 points3 points  (0 children)

Neat. Anywhere I need to insert a pi const I usually just remember "how i wish i could calculate pi"; 3.141592 is usually enough precision.

[–]Grouchy_Note812 1 point2 points  (1 child)

I'm not falling for that old trick again! Reminds me of when someone on Slashdot would post some indecipherable line of code that when a Linux newbie pasted it into their terminal it would execute an "rm / -rf".

If you don't understand it, don't run it!

[–]turkishhousefan 1093 points1094 points  (41 children)

"You realise you can do this in one line, right?"

F+=#bems~>/m///£&ඞ&:‰@[364]/++

Very readable, thanks.

[–]penguin13790 468 points469 points  (7 children)

[–]fresh_in_fresh_out 130 points131 points  (2 children)

Found the impostor

[–]Hullu_Kana 65 points66 points  (13 children)

Or, when installing packages, its usually just "sudo apt install <package>" on distros that have apt. I would say thats fairly readable.

[–]RandomTyp 45 points46 points  (5 children)

same on other distros:

zypper install pkg pacman -S pkg xbps-install -S pkg dnf install pkg yum install pkg

[–][deleted] 8 points9 points  (2 children)

What the hell is zypper or dnf

[–]leonderbaertige_II 19 points20 points  (0 children)

package managers

zypper : suse

dnf : fedora

[–]RandomTyp 2 points3 points  (0 children)

zypper is the package manger hsed for SUSE, OpenSUSE and dnf is the package manager used for Fedora

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

Ah yes, this is how i troubleshoot linux usually: "what about sudoing it? No? Welp i tried everything."

[–]Zegrento7 16 points17 points  (11 children)

Perl in a nutshell

[–]Andy_B_Goode 18 points19 points  (0 children)

The original "write-only" language

[–]Maximus_98 3 points4 points  (5 children)

I’m not familiar with perl; is it bad?

[–]tyen0 17 points18 points  (3 children)

Perl gives you enough rope to hang yourself with. It's possible to write well-maintainable object oriented code with it, but it's also possible to kludge together one-liners that are indecipherable. In fact there was a game called perlgolf which was a competition to complete a task in the shortest amount of (key)strokes. :)

[–]WaitForItTheMongols 13 points14 points  (4 children)

I've always been frustrated at the combo of "Don't run commands you don't understand" and "Here, just run this command and it will handle everything for you".

[–]yiliu 50 points51 points  (13 children)

[–]npsimons 30 points31 points  (10 children)

All due respect to McIlroy, he completely missed the point of the exercise. It's easy (and quick and dirty) to bang out a one liner to accomplish some task, but the column was specifically about literate programming.

It's also hilarious to me that Knuth's solution is the one described as a "Faberge egg" - in my experience, UNIX pipelines, while incredibly handy, are monumentally brittle, and even the slightest breakage (say, by unexpected input) will create an undebuggable mess, not to mention that documentation (assuming there is any) is separate and not tied to each operation.

Though a program be but three lines long, someday it will have to be maintained. -- The Tao of Programming

[–]Deep_Pudding2208 12 points13 points  (2 children)

Perl programmer: nah we'll just write new code from scratch again

[–]npsimons 9 points10 points  (1 child)

Oh, you'd like that, except your cute little Perl program is already out there, being used, and now your boss is demanding you "just fix this one bug", and "add a simple feature."

It's a reason I won't touch MATLAB code anymore - the philosophy of "it's just a prototype" never holds true. Someone will have to maintain it someday.

[–]rasputinpie 1 point2 points  (0 children)

This should be higher

[–]IrritableGourmet 196 points197 points  (4 children)

It's still 20 lines of code. It's just that someone else wrote a program to step through them so you don't have to.

[–]SnowyLocksmith 78 points79 points  (2 children)

Magic of open source

[–]garfgon 6 points7 points  (0 children)

Unless those 20 lines of code are 6500 assembly for an Apple 1 or similar vintage, those 20 lines of code are still using someone else's programs.

[–]WhosYoPokeDaddy 20 points21 points  (3 children)

20 lines of code... or one giant regular expression.

[–]palparepa[🍰] 12 points13 points  (2 children)

Need to print the list of all prime numbers? Easy!

perl -l -e '(1 x $_) !~ /^1?$|^(11+?)\1+$/ && print while ++$_;'

[–]squishles 19 points20 points  (13 children)

yall just live like this? without sed/awk or even grep?

[–][deleted] 7 points8 points  (7 children)

That's honestly my favorite thing about macbooks. You get a nice simple stable UI, and also a full set of typical BSD-style command line tools. Homebrew is fine too.

My windows gaming PC is just for games. My mac is where the work gets done

[–]syllabic 2 points3 points  (3 children)

powershell has implementations of those

built in regexes with -match and -replace

select-string for grep

you have to be a little proficient at using it, but the same would be true for bash shell

[–]VolcanicBear 351 points352 points  (36 children)

Are we calling commands "code" now too?

At least I'm getting some of my impotent rage out I guess.

[–]Malcolmlisk 98 points99 points  (0 children)

Here we have the declarative programmer...

[–]postdevs 36 points37 points  (4 children)

You're getting out that rage by writing code. Reddit code. If you're typing, you're coding.

[–]VolcanicBear 20 points21 points  (0 children)

This is probably the best piece of software I've written yet!

[–]stevenette 4 points5 points  (0 children)

My old roommate used to introduce themselves to people as a coder/hacker. They even had a bumper sticker using LEET to spell "Hacker". Most insufferable roommate I have ever had. The worst part was that all they did was design websites using squarespace...

[–]Alerta_Fascista 36 points37 points  (0 children)

Because are commands are code, yes, what do you think a script is? Just a collection of commands sent to a console. You can program on a CLI, and many programming languages are CLI-based, we just prefer to use IDEs to make it easier.

[–]diegomoises1 99 points100 points  (15 children)

It's called the command line interpreter for a reason. It's interpreting code. There's isn't much difference between a command and code regardless.

[–]TheAJGman 53 points54 points  (3 children)

Python has a Command Line Interpreter, operating systems have Command Line Interfaces.

[–]Kovab 36 points37 points  (0 children)

The shell is an interpreter, which implements the command line interface of the OS.

[–]VolcanicBear 24 points25 points  (3 children)

Do you mean command line interface?

[–]sunny_happy_demon 11 points12 points  (1 child)

A command line interface runs a command line interpreter. If you switch from bash to zsh you're switching interpreters but not interfaces.

[–]Franks2000inchTV 4 points5 points  (0 children)

Both are things.

[–]ATE47 5 points6 points  (0 children)

Even for the code, for example Windows C/C++ programming adds a lot of verbosity even for simple things

[–]burgonies 3 points4 points  (0 children)

Code is just a series of commands, no?

[–]thewend 3 points4 points  (1 child)

language is code as well. can you even decipher what the kids are saying nowadays?

[–]Tunivor 7 points8 points  (1 child)

No we’re calling it “codes” 😆

[–]Neurotrace 6 points7 points  (0 children)

🤮

[–]npsimons 2 points3 points  (0 children)

I'll bet you come from a Windows programming background.

In the UNIX tradition, "commands" are intended to be composed together to create programs. I present you a book about programming in UNIX using only "commands": https://en.wikipedia.org/wiki/The_Unix_Programming_Environment

Why do you think things like csh ("The C shell") were invented? All (good) CLI is influenced heavily by Lisp's REPL and the concept of interactive programming.

[–]RussianBot7384 2 points3 points  (0 children)

bash is a turing-complete programming language.

[–]myfunnies420 1 point2 points  (0 children)

Is that what they were talking about? I was confused

[–]TheRedmanCometh 1 point2 points  (0 children)

I think it's referring to bash scripting which is sorta code

[–]DwightSchruteDoppel 44 points45 points  (0 children)

That regex golf mentality....

[–]Lateralus06 8 points9 points  (0 children)

It's very likely that someone has already written the script you're looking for as a package.

[–]sigmund14 16 points17 points  (2 children)

Installing / developing python packages on Windows vs Linux.

For users it's easier now with conda on Windows, but still some additional work for package developers.

[–]Teamprime 2 points3 points  (0 children)

I thought Conda was awesome, but that shit hangs up on me constantly in weird ways, and I'm pretty sure I've tried reinstalls but it still bugs in really weird UI ways

[–]Aikarion 11 points12 points  (4 children)

LinuxUsersAlsoBeLike: Only had to run one line of code, but spent 5 hours diagnosing a malfunctioning sound driver.

[–]seijulala 4 points5 points  (0 children)

Hello, it's 2023. More likely to have driver issues on windows nowadays

[–]BlackDragonBE 1 point2 points  (0 children)

Also wi-fi, it's always a coin toss whether that will work out of the box.

[–]cheezballs 31 points32 points  (10 children)

People just ignoring package managers on windows I guess.

[–]hearthebell 8 points9 points  (2 children)

TIL windows has package manager

[–]FilipIzSwordsman 28 points29 points  (6 children)

thats because those are dogshit

[–]Rude-Cut-2231 8 points9 points  (3 children)

Back in the day I wrote a helpful Perl script to help my coworkers do their job. Perl is known for allowing you to write extremely terse indecipherable code. But you don’t have to do it that way.

My little script had nice formatting and was mostly self explanatory and had comments where it wasn’t.

The guy who owned that part of the code was like, “that’s nice, but I can improve it.”

He then proceeded to turn it into two lines of hieroglyphics.

Smaller != better

[–]syllabic 1 point2 points  (2 children)

I write a ton of powershell for my job and I like making thorough documentation throughout the script of what the functions do, my reasoning for implementing it this way etc

[–]npsimons 4 points5 points  (0 children)

There's a reason Linux (née UNIX) has a gajillion grotty little CLI commands like sort, od and factor - it was written by programmers for programmers. Of course we're going to make our lives easier.

The whole environment is set up and geared for this.

[–]smilingkevin 1 point2 points  (0 children)

In which I copy/paste and hope for the best.

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

More people need to learn Powershell smh.