Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

My 1st /prog/ram

Name: Anonymous 2009-03-11 19:52

So I took /prog/'s advice and started learning python:

Here is my first ever program that is not copypasted from the tutorial. (I went further by not ONLY having it say 'too high' or 'too low' or 'you guessed it')

Am I doing it right or is declaring 5 variables a waste of time?
Why cant I just say
if a < 5:
    print('way too low') #?
why does it have to be a variable?

Name: Anonymous 2009-03-11 19:53

while True:
    number = 23
    smallnumber = 5
    bignumber = 50
    hugenumber = 150
    belownumber = 22
    abovenumber = 24
    a = int(input('Guess a number: '))
    if a == number:
        print('you guessed it')
        print('welldone, you have now finished phase one')
        break
    elif a == belownumber:
        print('almost there')
    elif a == abovenumber:
        print('just a bit overshot')
    elif a < smallnumber:
        print('way too low')
    elif a > hugenumber:
        print('Ok i didn\'t say infinity')
    elif a > bignumber:
        print('way too high')
    elif a < number:
        print('too low')
    else: print('too high')

Name: Anonymous 2009-03-11 19:54

ONE WORD THE FORCED INDENTION OF CODE THREAD OVER

Name: Anonymous 2009-03-11 19:56

>>3
I'm totally new but I chose my language by looking at samples of code from each language, and python just seemed really nice to look at.  Whats so bad about forced indentation (indention)?
Sage to keep you python haters happy

Name: Anonymous 2009-03-11 19:56

I still wish python had a case statement ;_;

Name: Anonymous 2009-03-11 19:58

r u srs?

Name: Anonymous 2009-03-11 20:02

Am I doing it right or is declaring 5 variables a waste of time?

Why cant I just say

if a < 5:

    print('way too low') #?

why does it have to be a variable?

It doesn't have to be a variable if a < 5: should be fine


And if declaring them on five lines is too annoying you could do

number,smallnumber,bignumber,hugenumber,belownumber = 23,5,50,150,22


Whats so bad about forced indentation (indention)?
Nothing, it's just the only thing we've been able to fault python for, so we mention it at every available moment

Name: Anonymous 2009-03-11 20:08

>>5
It never did?

Name: Anonymous 2009-03-11 20:11

>>8
They just stick with if elif elif .... else. I think there has been proposals but probably couldn't come up with anything pythonic enough for guido.

Name: Anonymous 2009-03-11 20:13

>>7
thanks

Name: Anonymous 2009-03-11 20:14

>>7-san has not read his SICP.

Name: Anonymous 2009-03-11 20:19

>>7
Ok you're right, I didn't have to make them variables... wierd..
How do i add colour when I'm pasting in my code?

Name: Anonymous 2009-03-11 20:34

I emulate switch statements with dicts and lambdas.
Seriously.

Name: Anonymous 2009-03-11 21:15

>>13
back to /pounce/, Leah

Name: Anonymous 2009-03-11 21:33

>>7
How about all the self() bullshit?
What about how retarded it is to save three characters and make the code less english like with elif instead of else if.
How about that it is slow as shit. Even ironpython is slow as shit.
How about that there exists no fully featured IDE for it?

Man thats 4 solid criticisms and I've never even coded in python.  The only time I've coded in python was to help a friend with his programming homework(because expert programmers can easily program in any non super gay language).

Name: Anonymous 2009-03-11 22:17

>>15
How about all the self() bullshit?
I don't know what language you think you're talking about, but it's not Python.

What about how retarded it is to save three characters and make the code less english like with elif instead of else if.
else: if: works just fine, if you're that confused by two-syllable keywords.

How about that it is slow as shit. Even ironpython is slow as shit.
It's an interpreted language. It compares very favorably to other scripting languages.

How about that there exists no fully featured IDE for it?
Vi and emacs are just as capable of editing Python code as they are any other language.

Man thats 4 solid criticisms and I've never even coded in python.
You don't say.

Name: Anonymous 2009-03-11 22:23

What about the distinction between statements and expressions?
How about the lack of distinction between variable assignment and variable binding? Forcing you to use shitty var[0] hacks etc.
How about the lack of several common control structures such as do..while loops, real for loops, multilevel break/continue, switches etc? Also the complete lack of ways to make your own control structures (no macros, no monads, nothing).1
How about the lack of proper tail calls?
How about Guido being a total retard?

1 At the ll2 workshop some python guy wanted to add a with syntax that automatically opens and closes handles, even in the presence of exceptions etc. A 10 second macro in any lisp, but the python guy needed a bunch of programmers hacking on CPython for a month to get it done.

Name: Anonymous 2009-03-11 22:27

>>17
Wah Python isn't exactly like Common Lisp. Only your last point has real merit.

Name: Anonymous 2009-03-11 22:30

It's an interpreted language.
It's only interpreted because of shitty implementations. lrn2futamura projections and read SICP.
One of the problems with python is that it's defined by CPython.

>>18
Python can be divided into two parts: the good parts and the original parts.

Name: Anonymous 2009-03-11 23:34

It compares very favorably to other scripting languages.
pretty much every other scripting language is faster.
the only scripting language it compares favorably to is ruby.
and with the way things are going (python getting slower and ruby getting faster), in about 10 years even ruby might be faster than python.

Name: Anonymous 2009-03-11 23:37

>>16
>How about all the self() bullshit?
>I don't know what language you think you're talking about, but it's not Python.

He was probably referring to things like:
class Name:
    def __init__ (self):
       self.x = 7

But that's ridiculously easy to understand, when you do:
foo = Name()
then
foo.x == 7

Name: Anonymous 2009-03-12 0:05

>>16
In Python, you have to declare "self" as a first parameter of all your methods.\
[quote]It's an interpreted language[/quote]
Doesn't change the fact that its slow as shit.
[quote]Vi and emacs are just as capable of editing Python code as they are any other language.[/quote]
*Rolls eyes* whatever makes you feel hardcore bro. Notepad is capable of editing python too.

Name: Anonymous 2009-03-12 0:05

>>22
BBCode fail

Name: Anonymous 2009-03-12 0:17

hax my anus

Name: Anonymous 2009-03-12 0:30

>>22
Hey now, Vim (not Vi) and Emacs implemented a shitload of "IDE" features long before bloatware like Eclipse got popular. And they're still small and fast like your tight, tight anus

Name: Anonymous 2009-03-12 0:52

Nothing, it's just the only thing we've been able to fault python for, so we mention it at every available moment

How about the fact that variable types don't seem to exist in the python world?

Name: Anonymous 2009-03-12 0:53

Python is fine as it does not endorse FOOP

Name: Anonymous 2009-03-12 0:56

>>25
Seconded.

He's probably one of those idiotic drones that keep calling Emacs and Vim 70's abandonware. But the latest stable version of Emacs was released in September 2008 and the latest stable release of Vim was released in August 2008. And Vim development is still very active, and Emacs won't go the way of the dodo even if RMS can't work on it anymore. Doesn't sound very "abandoned" to me.

Name: Anonymous 2009-03-12 1:00

>>28
Or probably, he thinks they're just updated versions of ed that have taken all this time to get even half of the bigs fuxed.

Name: Anonymous 2009-03-12 1:06

>>22
Yes, you declare "self" as the first parameter for (most) methods, but that allows you to reference them inside your function definitions and refer them to the actual outside variable.

note that:
class Name:
    def __init__ (bill):
       bill.x = 7

is also valid. "self" is just commonly used because it make sense. I don't see why any one would consider this stupid or in anyway a hassle. you might as well complain that __init__ has TWO underscores rather than 1.

As for speed:
yes, great. C is faster, WE KNOW. so don't use python to develop 3d engines. developing a small utility program which doesn't consume all your CPUs? who cares.

Name: Anonymous 2009-03-12 1:11

>>30
don't use python to develop 3d engines.
http://www.eve-online.com/

Name: Anonymous 2009-03-12 1:27

>>30
ok, write a python script that caculates 1000000! in less than 20 seconds.

Name: Anonymous 2009-03-12 1:31

>>31
I totally forgot about that! Though I don't know enough about the game to know whether that was an extraordinary feat or not. I am not an "expert programmer" (I don't even know how to do the bbcode or whatever to make it look all fancy).

Name: Anonymous 2009-03-12 1:33

>>32
x = 0
while x < 1000000:
   x = x + 1

total run time: <1sec

Name: Anonymous 2009-03-12 1:38

>>34
id is not factorial

Name: Anonymous 2009-03-12 1:44

>>32
write a C program that can calculate Pi to 1,000,000 digits in less than 3 years

Name: Anonymous 2009-03-12 2:02

>>35

Ah, I missed the "!".

My answer is: who cares. As I said in my original post, if all you're doing is writing small utility programs, speed really isn't a factor.

Name: Anonymous 2009-03-12 2:04

>>32

puts "8.2639312188778698163179091185559E+5565708"


Total runtime: 0 milliseconds

Name: Anonymous 2009-03-12 2:14

*** Exception: stack overflow

Name: Anonymous 2009-03-12 2:23

>>38
only the first 7 digits are correct.
unless you get all 5565709 digits right, you fail at factorial.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List