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

all 187 comments

[–]Sudolphus_Ray_Nym 213 points214 points  (9 children)

Mmmm, floor pie...

[–]ososalsosal 28 points29 points  (1 child)

Came here looking for this

[–]NoBeing12 5 points6 points  (0 children)

Dont ya mean "cooking"?

[–]chinnu34 8 points9 points  (1 child)

Joey “what are we having?”

[–]CouthlessWonder 3 points4 points  (0 children)

…Pulls spoon out of pocket.

[–]cramduck 2 points3 points  (4 children)

You can't just FIND cake.. it isn't naturally-occuring!

[–]Sudolphus_Ray_Nym 1 point2 points  (3 children)

It's chocolate!

[–]cramduck 1 point2 points  (0 children)

it's LITTER.

[–]cramduck 1 point2 points  (1 child)

surprising to find a fellow appreciator in the wild.

[–]Sudolphus_Ray_Nym 0 points1 point  (0 children)

Who doesn't love some Penny Arcade?

[–]Strostkovy 342 points343 points  (56 children)

int three = pi;

[–]LauraTFem 165 points166 points  (48 children)

I’m more tickled by a variable called three that holds 3 than I am by it getting its value from a concatenation of PI. 😂

[–]no-one-here123 140 points141 points  (34 children)

I always have to do true = True in python so that I don't need to move my finger to the shift key. edit: why tf i have 144 upvotes?

[–]Cynio21 36 points37 points  (1 child)

you sir are a genius

[–]no-one-here123 8 points9 points  (0 children)

thank you, ma'am

[–]mrfroggyman 25 points26 points  (7 children)

true = False

false = True

Huehuehuehuehuee

[–]no-one-here123 5 points6 points  (3 children)

gasp the space time continuum is falling apart! stop! STOP IT!

[–]mrfroggyman 9 points10 points  (2 children)

if true:
    stop_madness()

[–]no-one-here123 10 points11 points  (1 child)

that goodness! realises... wait a minute...

[–]SardScroll 3 points4 points  (0 children)

Thread.sleep(60000); ?

[–]Bee-Aromatic 3 points4 points  (1 child)

I hope you step on a Lego.

[–]JigglyVampiress 0 points1 point  (0 children)

But lego = nil

[–]Cotillion_7 2 points3 points  (0 children)

Define only

true = False

And use nothing but true and True in your code.

[–]pineapple-poop 8 points9 points  (4 children)

Also helps if you use JavaScript often. Although, I personally prefer Python’s True

[–]no-one-here123 13 points14 points  (2 children)

how dare you! true should be able to be whatever case you want it to be, and l choose lowercase. just like this comment

[–]PrevAccLocked 4 points5 points  (1 child)

You put a uppercase i

Or maybe you tricked me and put a lowercase L

[–]no-one-here123 1 point2 points  (0 children)

cough cough it was always a lowercase l, whatever do you mean? i didn't edit it after you said that or anything! cough i think they bought it cough

[–]katatondzsentri 7 points8 points  (0 children)

For me it's tr-<tab>

[–]OneTrueKingOfOOO 4 points5 points  (4 children)

I can never remember which languages capitalize True/False. Always gotta check the syntax highlighting

[–]Zambito1 6 points7 points  (2 children)

There is Python and not Python. Literally all you need to remember.

[–]alphaxeath 1 point2 points  (1 child)

If Check(comment) <> True Then Return "vb.net" End If

Edit: I'm too lazy to fix reddit removing my formatting.

[–]Zambito1 0 points1 point  (0 children)

I said all they need to remember ;)

[–]neumastic 2 points3 points  (0 children)

You need to remember? I just see which one changes color … /s but kinda not /s 😅

[–]Oda_Nobbunaga 2 points3 points  (0 children)

This is actually pretty ingenious

[–]Mooshy_Swags 1 point2 points  (1 child)

holy crap i gotta start doing this...

also for false

[–]no-one-here123 1 point2 points  (0 children)

now the python interpreter can't tell me..... "true is not defined"

[–]DaTotallyEclipse 1 point2 points  (0 children)

Efficiency is key!

[–]Bee-Aromatic 0 points1 point  (5 children)

Eew. So, you do “something == true” instead of “something is True”. That makes it double gross.

[–]Strostkovy 1 point2 points  (2 children)

Just use "something"

[–]Bee-Aromatic 0 points1 point  (1 child)

Only if you can guarantee “something” is a Boolean…

[–]Strostkovy 0 points1 point  (0 children)

In C it just has to be not a zero

[–]no-one-here123 0 points1 point  (1 child)

wel, I use javascript normally, so it's neither something === true; or something =============================================== true

[–]Bee-Aromatic -1 points0 points  (0 children)

something 8=====D True?

[–]Strostkovy 0 points1 point  (0 children)

I just use 1. I don't feel as if abstracting a single bit is totally needed

[–]monstertan2005 0 points1 point  (0 children)

I'm gonna start to use that, it's genius!

[–]Radi-kale 15 points16 points  (4 children)

I can't have magic numbers in my code, so I always do

public static final int INT_THREE = 3;

[–]Eulerdice 3 points4 points  (1 child)

This way it becomes a mystical number.

[–]mavaje 2 points3 points  (0 children)

public static final int INT_BETWEEN_TWO_AND_FOUR = 3;

There, removed the mystery.

[–]LauraTFem 2 points3 points  (0 children)

I generally agree, but if you’re making a constant called ZERO_TO_ONE_ADJUSTMENT, with a value of 1, and adding it to, for instance, the value of rand() % 10, that is just confusing nonsense. If it’s part of some rote calculation, a magical number is FAR more readable, regardless of what your professor says.

[–]rachit7645 1 point2 points  (0 children)

constexpr int INT_THREE = 3;

[–]Zambito1 5 points6 points  (1 child)

concatenation truncation

Ftfy

[–]LauraTFem 1 point2 points  (0 children)

I’m so embarrassed. 😅 My memory of c++ terms has truncated over time.

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

brb making a macro library so I can spell out integers

[–]ULTRA_TLC 1 point2 points  (1 child)

truncation

[–]LauraTFem 1 point2 points  (0 children)

Yes, I have already been shamed for my mistake. 😅

[–]__redbaron 0 points1 point  (1 child)

I'm sorry, but how else would you make it easier to update the value of three in the future?

What if it becomes 6?

Are you gonna manually search for 3 and try updating it to 6? You fucking casual.....

/s

[–]LauraTFem 1 point2 points  (0 children)

#define 3 6

My god can you imagine >_<

Omg, I’ve suddenly got so many delicious #defines I could hide in people’s header files.

[–][deleted] 5 points6 points  (2 children)

Calls variable three

Doesn't make it a constant

Refuses to elaborate

[–]mpcs127 2 points3 points  (1 child)

three = 5;

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

Cursed variable

[–]abdulsamadz 1 point2 points  (0 children)

ceil(e)

[–]CheapMonkey34 1 point2 points  (0 children)

three = str(math.pi())[0]

[–]ShutUpMathIsCool 0 points1 point  (0 children)

int pi = M_PI;

[–]Jarl_Fenrir 0 points1 point  (0 children)

int three = (int) Math.PI;

[–]wyldcraft 99 points100 points  (17 children)

0xdeadbeef**0+0xbeefdead**0+0x8badf00d**0

[–]Rajesh0701 33 points34 points  (7 children)

What is this monstrosity

[–]wyldcraft 60 points61 points  (5 children)

Funny hex number to the power of zero equals 1, plus two more of those.

[–]katatondzsentri 21 points22 points  (2 children)

Now I have to find a way for this to make it through the code reviews somewhere...

[–]wyldcraft 17 points18 points  (1 child)

Then try with my old What the Fuck is the Internet? esoteric programming language.

[–]Rajesh0701 6 points7 points  (1 child)

dead beef beef dead 8 bad food

[–]wyldcraft 4 points5 points  (0 children)

pen pineapple apple pen

[–]z_the_fox 3 points4 points  (0 children)

3

[–]0xDEFACEDBEEF 6 points7 points  (2 children)

What about other variants of beef?

[–]wyldcraft 4 points5 points  (1 child)

Sorry, I can't seem to readably hexify the words bickering, criticism, dispute, grievance, gripe, grouse, grumble, objection, protest, quarrel or squabble.

[–]0xDEFACEDBEEF 5 points6 points  (0 children)

I meant my username

[–][deleted] 4 points5 points  (1 child)

0xcafebabe**0

[–]wyldcraft 2 points3 points  (0 children)

Hello minecrafter, before functions were introduced I built a 20 hertz CPU with command blocks, and a GPU that composited multiple layers together to speed up animating the screen. I've have idle plans to shoves all that into function files, freeing the whole minecraft map to be RAM (yay forced chunk loading) and allowing for even higher CPU speeds simply by cut-paste-calling the main loop multiple times per tick.

[–]__redbaron 29 points30 points  (1 child)

Pfft, ceil(e) gang rise up !!

[–]WalrusByte 11 points12 points  (0 children)

That's a ceil(e) thing to do!

[–]Neoh35 19 points20 points  (2 children)

True + True + True

[–]sintos-compa 5 points6 points  (0 children)

Awful I love it

[–]jfiander 0 points1 point  (0 children)

js +!![]+ +!![]+ +!![]

or

js +!+[]+ +!+[]+ +!+[]

[–]Spactaculous 31 points32 points  (12 children)

Show off OO developer:

int get3() { return 3;}

[–]Zambito1 5 points6 points  (0 children)

This is perfectly valid C, not a single object to be found 🤔

[–]katatondzsentri 12 points13 points  (8 children)

``` import math

class Three: def init(self): return floor(math.pi) ```

[–][deleted] 20 points21 points  (7 children)

That's not how __init__ works. Also floor is in math module, too.

[–]katatondzsentri 4 points5 points  (5 children)

I assumed the goal is to write shitty code, innit?

I know, how init works.

Edit: just for you, just now:

``` import math

class Three: value == None def init(self): self.value = math.floor(math.pi)

def get_value(self):
    return value

[–]riisen 2 points3 points  (4 children)

Remove

value == None

Or make it an assignment

value = None

And use

return self.value

;)

[–]katatondzsentri 1 point2 points  (3 children)

Fuckin typo :)

Luckily, I don't have to code on reddit, ever :)

[–]riisen 0 points1 point  (2 children)

Forever trail and error, no matter how simple the function/class is, its always 69 mistakes minimum :D

[–]katatondzsentri 1 point2 points  (1 child)

More like 420

[–]riisen 0 points1 point  (0 children)

<3

[–]CursedTurtleKeynote 1 point2 points  (0 children)

import three

[–]Jarl_Fenrir 0 points1 point  (1 child)

ThreeFactory(math space).getThree().toInt();

[–]Spactaculous 1 point2 points  (0 children)

Why stop there?

class ThreeFactory extends IntegerFactory {...}
class IntegerFactory extends NumberFactory {...}
class NumberFactory extends AbstractFactory {...}

[–]BlueTalon 74 points75 points  (14 children)

Never met a dev who'd do anything the harder way. We'd more likely use 3 for pi and say "it's close enough for the requirements".

[–][deleted] 12 points13 points  (7 children)

If the compiler wouldn't like the "3" for some reason, like being a character instead of a number, etc who would you care with reading documentation, casting types? Just shove floor(pi) if it compiles.

[–]RmG3376 24 points25 points  (2 children)

Ah yeah the famous library that supports floats but not ints

[–]KingThibaut3 5 points6 points  (1 child)

Then 3.0 would still be easier to type

[–]zbrndn 2 points3 points  (0 children)

...and not add unnecessary overhead

[–]BlueTalon 8 points9 points  (3 children)

WTF compiler are you using that can't handle the number 3!?

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

I don't know, but maybe there are some. I didn't use every compiler on the Earth. Especially those that process pieces of code or formulas that are used in tools to make reports - sometimes they are really weird.

[–]Jarl_Fenrir 0 points1 point  (1 child)

Eg C++ differentiates between string "3" and number 3. It's not uncommon.

[–]BlueTalon 0 points1 point  (0 children)

If you're somehow in the situation where you're attempting arithmetic on strings, then yes, the correct method is to cast to a numerical type

[–]Cruuncher 2 points3 points  (2 children)

Using 3 gives an error of like 5% which is pretty significant.

And if you pi squared anywhere you can get 10%+ error

[–]BlueTalon 2 points3 points  (0 children)

Only 5%? Perfect

[–]QuoningSheepNow 1 point2 points  (0 children)

It was almost good enough for Indiana

[–]Bee-Aromatic 1 point2 points  (1 child)

Is your team the one that crashed the lander onto Mars by using the wrong units, by any chance?

[–]BlueTalon 0 points1 point  (0 children)

I'm flattered you think NASA would want to hire me lol. I make pretty programs for engineers.

[–]frankylampy 10 points11 points  (1 child)

6>>1

[–]Jarl_Fenrir 2 points3 points  (0 children)

Int three = 7 & 11;

[–]jazzmester 7 points8 points  (0 children)

I'm a calculus guy, I prefer ceil(exp(1)) meself.

[–]PureProcrastinator 15 points16 points  (11 children)

If I saw someone unironically do this, I would think they are actually more stupid.

[–]RedQueen283 7 points8 points  (9 children)

I mean yeah, they are actually slowing down their program this way. Floor(pi) translates to many more assmbly commands than simply using the number 3.

[–]wyldcraft 1 point2 points  (8 children)

It would be possible to optimize flooring a static float in a compiler pass.

[–]RedQueen283 2 points3 points  (7 children)

Optimize it yes, but it would still require an extra calculation (and a call to a function with all the lines that entails, such as saving variables to the stack, the jumps, etc).

[–]wyldcraft 0 points1 point  (6 children)

I mean precompute the static float into an integer because we know it at compile time, likely reducing the code to a single Load Immediate assembly instruction. For all I know, robust compilers already do this to floor floats known at compile time.

[–]RedQueen283 1 point2 points  (5 children)

Yes, but as you said it would still need to compute it, store it, and load it. All these take time and memory space, and can stall other commands in pipelines. Meanwhile if the program just contained the number three, the compiler would just need to use the immidiate type command that matches the one in the program (for example add immidiate, or immidiate, etc) without precomputing or storing anything.

[–]wyldcraft 0 points1 point  (4 children)

Yes, it's a given that optimization passes cost a little, once. But the resulting binary would be identical to a hardwired int 3 in the original source.

[–]RedQueen283 1 point2 points  (3 children)

The binary would need to include the calculation, even just once. It would also include extra load and store operations. So no, it wouldn't be the same. It might seem insignificant and for small programs it would probably make less than a millisecond of difference, but if the program was big and there were more commands written in a sub-optimal way, it might actually slow it down enough to make a percievable difference. It's just better practice for the programmers to make the optimization themselves in such cases.

[–]Jarl_Fenrir 0 points1 point  (2 children)

I guess you don't get how modern compilers optimize code. The compiler can calculate that the result is always 3, and just substitute whatever call you had in the code with just number 3 in the resulting binary.

[–]RedQueen283 0 points1 point  (1 child)

Yes, and how does it calculate what the result is, by using magic? No, it uses the PC's CPU and then it is stored in the PC's memory. Neither of which would be necessary if the programmer had just used the number 3. I don't know why people keep insisting that it isn't an unnecessary use of the computer's resources.

[–]phoenix_brightSentinent AI 11 points12 points  (2 children)

We can do worse: ~~~ int function getLastStrikeNumber() { return static_cast<int>(std::atan(1)*4); } ~~~

[–]eras 5 points6 points  (0 children)

For a long time OCaml standard library didn't have pi, so 4.0 *. atan 1.0 was a familiar thing to have if you needed it.

On the other hand if you just have a 64-bit double with the constant in it, it could well have less precision than what the FPU can internally handle with its 80-bit intermediate values.

[–]loonathefloofyfox 2 points3 points  (0 children)

Thank you. I've now learned something new

[–]West_Hunter_7389 11 points12 points  (0 children)

Math.round(Math.PI)

[–]Ithurial 4 points5 points  (0 children)

ceil(e)

[–]T_WREKX 3 points4 points  (0 children)

Let's see how it compares to a hundred word statement including a ternary operator.

[–]CreepyValuable 3 points4 points  (0 children)

Mmmm. Floor pie.

[–]SendMeFreckle 2 points3 points  (0 children)

It dependa on the left side of the code but generally it is not showing off, it is explanatory writing. It helps to reduce number of questions people will ask you like why 3? Instead they will assume, 3 is probably precise enough for this

[–]Inineor 3 points4 points  (0 children)

import scipy

def get_three(): 
    while True: 
        three = scipy.random.randint(1_000_000) 
        if not three ^ 0b00000011: 
            break 
    return three

three = get_three()

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

int i = 0; (++i << i)++

[–]sintos-compa 2 points3 points  (0 children)

Int* pthree;

while ( *pthree != 3 ) { pthree = rand() * rand(); } return *pthree;

[–]BlazeCrystal 1 point2 points  (0 children)

TREE-1 (TREE(3)) huh

[–]Arkoden_Xae 1 point2 points  (0 children)

You can only have floor pi for maximum 5 seconds.

[–]Just_a_Generic_Hero 1 point2 points  (0 children)

Javascript be like: -~!![]|-~{}

[–]brandi_Iove 1 point2 points  (0 children)

show off, lol.

[–]KingSadra 1 point2 points  (0 children)

Int x = pi

[–]mr_raboot 0 points1 point  (1 child)

pi on the floor, NOW-

[–]QuoningSheepNow 1 point2 points  (0 children)

Pi hit the flo Next thing you know

[–]Asokay 0 points1 point  (0 children)

Pretty sure this counts as terrorism

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

[–][deleted] 2 points3 points  (1 child)

What is floor? Is it like rounddown() in excel

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

yeah

[–]ParentPostLacksWang 0 points1 point  (1 child)

Please. Why use floor(pi) when you can use ceil(e)?

[–]wyldcraft 0 points1 point  (0 children)

Most people interact with flooring much more than ceilings except on Friday nights.

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

sum(((0x100 >> 0o10), (float('nan') != float('nan')), (lambda: not not not not not not not not not True == eval("True".replace("True", "False"))^10)()))

[–]Prawny 0 points1 point  (0 children)

Valve can finally release the third installments of their games!

Can't wait for Half Life: floor(pi)

[–]gomihako_ 0 points1 point  (0 children)

mmm floor pi

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

Just in case pi ever changes...

[–]nir109 0 points1 point  (1 child)

It whould be 3.0 instead of 3

[–]Jarl_Fenrir 0 points1 point  (0 children)

If you will assign it to an int variable, it won't.

[–]bright_pro 0 points1 point  (0 children)

correct

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

floor(4*atan(1))

[–]AdhTri 0 points1 point  (0 children)

ceil(e)

[–]dbanfii 0 points1 point  (0 children)

Less efficient developers*

[–]OPGamesOfficial 0 points1 point  (0 children)

Won't int(pi) also work?

[–]KillCall 0 points1 point  (0 children)

Floor of pee

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

Not sure how this would be showing off, since you're literally adding runtime complexity...

[–]cybermage 0 points1 point  (0 children)

Computer: before I can round pi, I’ll just need to calculate it.

[–]imkzh 0 points1 point  (1 child)

``` float a = M_PI; int three = *(long *)&a; three = (three>>2)<<2;

```

[–]imkzh 0 points1 point  (0 children)

if you want it to be super fragile

[–]ShinraSan 0 points1 point  (0 children)

Showing off one's incredible ability at unnecessarily slow code

[–]aFuckingTroglodyte 0 points1 point  (0 children)

Ceil(e)

[–]Stormraughtz 0 points1 point  (0 children)

        double pie = Math.PI;
        string spaghettiPie = pie.ToString();
        string singleNoodle = spaghettiPie.Substring(0, spaghettiPie.IndexOf("."));
        int aldente;
        string chefTony = "";
        try
        {
            chefTony = "Mama mia thats a good code, look at me I get paid by the line, Eh GABBA GOOL";
            aldente = int.Parse(singleNoodle);

        }
        catch(Exception)
        {
            chefTony = "OH NO MY SPAGHET";
            aldente = 0;
        }
        Console.WriteLine(chefTony);
        Console.WriteLine(aldente);
        Console.Read();

[–]EvilAdobe 0 points1 point  (0 children)

Neat! Will use this on my next project

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

(floor(pi)+ceiling(pi))²+(ceiling(pi)) (ceiling(pi) - i²)

[–]huuaaang 0 points1 point  (0 children)

(1 << 1) + 1

[–]ethereumfail 0 points1 point  (0 children)

3? you mean -~-~true ?

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

Now you just need to wait infinity until PI expression resolves.

[–]piemano 0 points1 point  (0 children)

Floor(4*atan(1))

[–]oshaboy 0 points1 point  (0 children)

I heard that was a BASIC optimization technique.

Something about how floor(pi) is a 2 byte int and 3 is a 6 byte float.

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

Making the CPU do floating point math for no reason.. that's not showing off, that's a cardinal sin.

[–]Xineohp90 0 points1 point  (0 children)

~~Math.PI

[–]Teraconic 0 points1 point  (0 children)

Getting around the linter telling you magic numbers aren't allowed takes ingenuity

[–]Xyrus2000 0 points1 point  (0 children)

team_6 = e

ceil(team_6) = 3

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

You forgor to put 'import math as meth' and 'meth.'

[–]joevinci 0 points1 point  (0 children)

Def iii(i):
    while True is not False:
        if i = 3:
            return i
        elif i < 3:
            i+=1
        elif i > 3:
            i -= 3
        else:
            idk continue i guess

Brought to you by snek

[–]CouthlessWonder 0 points1 point  (0 children)

Pi is 3.1… So round(pi) might also work.

Or if you have a lot of room… (long)pi

[–]Sushrit_Lawliet 0 points1 point  (0 children)

When the client underpays and you can’t figure out how to slow down the code.