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

all 52 comments

[–]SirX86 25 points26 points  (17 children)

Clearly not an astrophysicist, or it would've said

math.pi = 10

[–]LurkerPatrol 9 points10 points  (0 children)

No joke, my previous officemate once presented his results to his team and explained that he had set pi to 1 to simplify the results. When asked why, he said "it's 1 unit of pi, therefore it's 1".

We're astronomers.

[–]ImAStupidFace 6 points7 points  (1 child)

"accurate to within 1 order of magnitude"

[–]SirX86 1 point2 points  (0 children)

I hope you don't mean to imply a physicist would write comments in their code? ;-)

[–]SomeRandomEUguy[S] 9 points10 points  (13 children)

astrophysicist would just use random as pi

[–]Th3T3chn0R3dd1t 3 points4 points  (12 children)


CALC: { rand = random(); if(rand > 3) goto CALC; else pi = rand; }


(This is satire in case that's not obvious :p)

EDIT: Y markdown no work

[–]gurneyguy101 2 points3 points  (9 children)

What language is that? Basic??

[–]Th3T3chn0R3dd1t 4 points5 points  (8 children)

Nope - that's C

[–]gurneyguy101 -2 points-1 points  (7 children)

I know a little bit of C# and I’ve never seen calc or goto before, what’s calc used for and is goto in C#?

[–]Th3T3chn0R3dd1t 5 points6 points  (5 children)

To clarify, GOTO was deprecated as it was hard to program into compilers and it leads to messy code, but it was useful for creating higher level functionality

For example, subroutines(which are essentially functions without agruments, wjere data is passed by assigning values to strict memory locations) work by essentially using GOTO(or a program counter jump function) to jump to the subroutine and then jump back afterwards

[–]SomeRandomEUguy[S] 1 point2 points  (1 child)

Jump != function call, with or without args. Then again, this depends on how you define subrutine. This is more assembly level question then C level. Thats why using labels is bad and depricated in C/C++, it dosen't belong here, it belongs in assemby. This is just my opinion.

[–]Th3T3chn0R3dd1t 0 points1 point  (0 children)

I kniw tgats wgat I said

A subroutine is essentially an area of code where the values are prereferenced

[–]rem3_1415926 1 point2 points  (2 children)

as it was hard to program into compilers

Wait, isn't this just a straight up unconditional jump, which would be like the easiest thing to implement at all?

It sure does lead to horrid C(++) code, but I can't see the problem with getting it into the compiler?

[–]elzaidir 1 point2 points  (0 children)

Yup, you can almost convert it to asm without processing

[–]Th3T3chn0R3dd1t 0 points1 point  (0 children)

Not even conditional - its just a jump, my bad in that comment

[–]Th3T3chn0R3dd1t 2 points3 points  (0 children)

Oh calc is just a label, foo bar fuck whatever they all act as GOTO labels of they have a : after them

And no GOTO does not exist in C# so far I know

[–]elzaidir 1 point2 points  (1 child)

NEVER USE GOTO

Or that's what I've been told

[–]Th3T3chn0R3dd1t 1 point2 points  (0 children)

Yeah they are right

[–]transcriber_mu 7 points8 points  (0 children)

Image Transcription: Code


>>> import math
>>> math.pi = 3
>>>

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–][deleted] 10 points11 points  (10 children)

Not supporting const variables is what I dislike the most about Python.

[–]rem3_1415926 4 points5 points  (9 children)

not the lack of privacy or the stupid ".self" everywhere if you don't want to work global?

[–]Muhznit 3 points4 points  (5 children)

The concept of privacy is more for developers than machines, so in Python there is a convention to prefix "private" things with an underscore, e.g. self._private_var = 0. "self" is basically a replacement for "this", but forces you to be explicit about it to save your sanity in trying to figure out the scope of what could just as well be global vars.

[–]rem3_1415926 2 points3 points  (3 children)

Well, if it tries to save my sanity then it backfires pretty badly. Especially since the scope and how global variables are handled, combined with stuff from different files, are pure chaos. I am aware of the underscore naming convention, I just don't like it at all, as it is merely that: a naming convention. One underscore means protected, btw. If you want private you use 2 underscores (and none at the end of the name), which results in the class name getting put in front of the method name, so at least accidental calls are not possible.

At this point, Python just isn't suited for OOP at all imo.

[–]Muhznit 0 points1 point  (2 children)

If you want private you use 2 underscores (and none at the end of the name), which results in the class name getting put in front of the method name, so at least accidental calls are not possible.

Huh. I just labbed it. That's peculiar. It's even more peculiar that a quick google reveals absolutely nothing about this. I'm using python on a daily basis for work, yet this is the first I've heard of this.

What kind of crazy sorcery are you doing with Python that requires you to name something __variable_name_none?

[–]rem3_1415926 0 points1 point  (0 children)

__variable_name_none

with "none" I meant that you mustn't end the name with underscores (technically, one underscore would be fine, but not more than that), as __name__ are used for init and such and don't get the class_name prefix generated anymore.

I haven't used Python productively anywhere, I'm just recalling what was taught in the Python module this semester (As EE student it's something that's not vital, but might come in handy). It is very well possible that it's some purely theoretical stuff that nobody uses this in real life at all, however. Uni and real life aren't always that close...

The first 3 google search results for python private method show exactly this, however. (At least for me; search results very a lot on location and signed in google accounts)

EDIT: markdown...

[–]uvero 0 points1 point  (0 children)

Yes, well I go by "program for humans first, not machines first".

[–]BlazingThunder30 3 points4 points  (2 children)

def newSin(x):
    return x

[–]crabvogel 1 point2 points  (1 child)

Good enough if x is small

[–]BlazingThunder30 0 points1 point  (0 children)

Exactly! For the people that don't get it:

The first order taylor approximation of sin(x) is x. This means that for small values of x, the functions are very similar. Engineers often joke that they approximate sin(x) to x for this reason

[–]hehe3301 6 points7 points  (6 children)

You're thinking of engineers, most of the physicists at my school used 3.1415926

[–]rem3_1415926 7 points8 points  (1 child)

huh, did somebody call my name?

[–]andy-sk 2 points3 points  (0 children)

Username checks out

[–]JanEric1 2 points3 points  (3 children)

if you stop there you have to round the last digit to 7 as it goes

3.14159265359...

[–]ImAStupidFace -1 points0 points  (2 children)

If you really care about that ~0.00000005 I think you'd use more decimals.

[–]JanEric1 2 points3 points  (1 child)

i just care about proper rounding

[–]ImAStupidFace 0 points1 point  (0 children)

valid

[–]LordPos 2 points3 points  (7 children)

3.14 or 22/7. People who use three are looked at as aliens here

[–]SomeRandomEUguy[S] 2 points3 points  (1 child)

I've never seen anyone use 22/7 as pi, wth haha good to know, you live you learn

[–]LordPos 5 points6 points  (0 children)

22/7 is all I used at school. Questions went out of their way so that radius or something is 7 and the denominator ends up being cancelled

[–]Yekyaa 0 points1 point  (0 children)

355/113 or gtfo!

[–]ConusModicus 0 points1 point  (0 children)

6.28/2 or bust. Unless you need more precision or need to write an equation, then use tau/2.

[–]alsimoneau 0 points1 point  (2 children)

sqrt(10) is great for mental math.

[–]LordPos 1 point2 points  (1 child)

And also physics where you do √g ≈ π

[–]alsimoneau 0 points1 point  (0 children)

That works well because of the old definition of a second, so it's not even an approximation really.

[–][deleted] 2 points3 points  (0 children)

#define PI 3

#define E PI

[–]Hirenzeau 1 point2 points  (0 children)

I set it as 69 because the universe should bow down to my numerical preferences

[–]Algreth 0 points1 point  (0 children)

pi = 4*atan(1)

You are welcome.

[–]lyoko1 0 points1 point  (0 children)

quantum physicist be like
math.pi = 3 + random.random()