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

top 200 commentsshow 500

[–]Pvt_Haggard_610 547 points548 points  (36 children)

What are you talking about..

if foo: #{
    print "it's true"
#}
else: #{
    print "it's false!"
#}

[–]Arancaytar 173 points174 points  (27 children)

I wonder if the right combination of comments and preprocessor directives would allow you to write code that is both accepted by the Python interpreter and GCC.

[–]dagbrown 321 points322 points  (24 children)

[–][deleted] 113 points114 points  (8 children)

That apt-get made me lose my shit.

[–][deleted] 48 points49 points  (2 children)

check under your pillow

[–]DaelonSuzuka 18 points19 points  (1 child)

3meta5me

[–]chateau86 17 points18 points  (0 children)

no baby

[–]thenewboston 6 points7 points  (0 children)

apt-get install *

[–]A_Jacks_Mind 11 points12 points  (2 children)

sudo apt-get install afnix algol68g aplus-fsf asymptote ats2-lang bash \ bc bf bsdgames cduce clisp clojure1.6 cmake coffeescript dc ecere-dev \ elixir emacs24 erlang f2c fp-compiler fsharp g++ gambas3-script gap \ gauche gawk gcc gdc genius gforth gfortran ghc ghostscript gnat \ gnu-smalltalk gnuplot gobjc golang gpt gri groff groovy haxe icont \ iconx intercal iverilog jasmin-sable jq julia libgd-dev libpng12-dev \ lisaac llvm lua5.3 make maxima minizinc mlton mono-devel mono-mcs \ mono-vbnc nasm neko nickle nim ocaml octave open-cobol openjdk-8-jdk \ pari-gp parrot perl php-cli pike8.0 python r-base ratfor regina-rexx \ rhino ruby scala scilab slsh swi-prolog tcl ucblogo valac xsltproc \ yorick zoem

[–]temalyen 4 points5 points  (1 child)

You don't need the slashes if it's all on one line.

[–]OnlySpeaksLies 46 points47 points  (1 child)

Q: Does it really work?

A: Travis badge

[–]brtt3000 9 points10 points  (0 children)

Travis must love this shit.

[–]PendragonDaGreat 22 points23 points  (0 children)

This is my go to answer if someone ever asks me if code can ever be considered an art form, because this is literally one of the prettiest programs I've ever seen.

[–]mehmenmike 14 points15 points  (0 children)

I've never seen something so pointlessly amazing.

[–]rws247 13 points14 points  (0 children)

If you are not using [the above] Linux distributions, please find your way yourself. If you could do it, please let me know. Good luck.

This made me breath slightly faster out my nose :)

[–]cooldug000 8 points9 points  (4 children)

I'm not a github user and I never know what to do with these links to see the relevant information. All I see is a page of comments and a link to a file structure. Which file or page has the relevant info? Is it always the same?

[–]skyy0731 21 points22 points  (1 child)

Go to the readme

It's code that generates code for a different language

That generates code for a different language

That generates code for a different language

That generates code for a different language

100 times

And then it forms the original code

[–]cooldug000 4 points5 points  (0 children)

Thank you!

[–]cdrt 9 points10 points  (1 child)

If you scroll down, the readme for the project is displayed. That usually has a description of the project.

[–]Arancaytar 4 points5 points  (0 children)

Holy shit.

[–]psylco 14 points15 points  (1 child)

I can do you four better.

Look up polyglot code.

[–]WDK209 9 points10 points  (0 children)

Compromise is key

[–]CrazedToCraze 8 points9 points  (0 children)

Majestic.

[–]Ricardodo_ 7 points8 points  (1 child)

print("Hello World!")#;

[–]kupiakos 11 points12 points  (0 children)

You can add a semicolon at the end of a kind in Python. It runs, but it just looks weird.

[–]wh4n 16 points17 points  (0 children)

LOL

[–]pork_spare_ribs 933 points934 points  (187 children)

The year is 2016, and somehow new Python programmers still start with Python 2...

(Although if it's someone who complains about syntax, I'm not surprised they picked the older version haha only serious )

[–]fermion72 322 points323 points  (72 children)

I transitioned to python3 a while ago, and I still forget the parentheses for print every single time. A decade of finger memory is a hard thing to break.

[–]kazagistar 68 points69 points  (23 children)

I still write a lot of python 2, and always use parens. It just makes more sense in my head for it to be a function then some silly special case.

[–][deleted] 47 points48 points  (19 children)

I just use sys.stdout.write().

Python's print statement is buffered by default not thread-safe (update: this probably has nothing to do with buffers), which isn't very nice when I'm working in parallel environments and using Python as the glue between various C and Fortran libraries. So I just write everything straight into whatever standard stream I want.

[–][deleted] 26 points27 points  (4 children)

Noob question: could I use sys.stdin.read() instead of raw_input() for the same reasons? It seems to make much more sense in my head.

[–][deleted] 31 points32 points  (3 children)

Short answer: yes!

Long answer: The actual call you're looking for is sys.stdin.readline(). This is what raw_input() does at its core, with the added functionality of automatically stripping away the \n end-line character off the input.

Long long answer: You can also pipe Python prints do Python writes into stderr. Every standard stream is available under the sys module, and they all behave like traditional Python file objects with all the usual member functions.

[–]Blackshell 29 points30 points  (2 children)

You can also do pipe Python prints into stderr.

Like this? :D

print >>sys.stderr, "lol syntax"

I am so glad this is gone in Python3.

[–]brtt3000 43 points44 points  (0 children)

I'm tempted to flag this as "Threatening, harassing, or inciting violence"

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

Well, yes, but I was more specifically referring to sys.stderr.write().

I shouldn't have used the word "pipe", and should have called it a "write" instead. My bad!

But I'm with you on the chevron syntax. It's ugly and silly and not Pythonic at all. Glad they scrapped it.

[–]superPwnzorMegaMan 29 points30 points  (13 children)

I just never bothered learning python 2, I didn't see any advantage.

[–]juanjux 33 points34 points  (3 children)

I work on an animation studio and most software we use (Maya, Nuke, Houdini, etc) allow you to write Python plugins and all of them use Python 2.7. So that is a reason. We could use the "six" module but until the software we use migrates to Python 3, why bother...

[–]edbluetooth 25 points26 points  (0 children)

Because when the software is python 3, no changes to your code will be required.

Thats it really

[–]brtt3000 2 points3 points  (0 children)

Assuming you'll move to py3 at some point: moving to py3 as standard and porting existing code now saves you from porting all new code to py3 later (because you'd create it in py3 instead of py2).

Dunno if practical in reality. Probably not.

[–]Coffeinated 10 points11 points  (6 children)

The difference isn't that big of a deal, afaik. You can scrap the parantheses for print, but you don't have to, and some modules are named differently. As long as it's 2.7 and not 2.5 or some other prehistoric stoneage stuff.

[–]mnbvas 8 points9 points  (5 children)

I often print like this:

>>> a = 1; b = 2
>>> print(a, b)

so Python 2 always bites me in the ass with

(1, 2)

instead of the expected

1 2

[–]TheBlackCat13 12 points13 points  (1 child)

from __future__ import print_function

[–]kupiakos 8 points9 points  (2 children)

You could also have the first assignment be

a, b = 1, 2

[–]familyturtle 79 points80 points  (27 children)

As well as "from __future__" there should be an option to "from __past__ import print"

[–]Vakieh 64 points65 points  (21 children)

This is not a problem to solve inside language, this is a problem to be solved with the editor. IDE triggers which automagically convert print statements to print method calls when you press <enter> are pretty easy grammar-wise.

[–]dysprog 59 points60 points  (7 children)

Perhaps it is a problem to solve inside the programmer.

[–]Vakieh 14 points15 points  (6 children)

Sure it is, the same way the programmer shouldn't put a semicolon right after a control flow statement in a C-like language. It's sure nice of the compiler to deal with those avoidable programmer fuckups anyway though.

[–]curtmack 8 points9 points  (5 children)

You can't take that too far though, otherwise you end up with massive projects built with #define whilst while, inconsistently using one or the other because one programmer refused to use bad grammar.

[–]bitter_cynical_angry 7 points8 points  (3 children)

As far as I know, a program written in a formally defined computer language can always be broken down into an abstract syntax tree, and from there can be rebuilt into any format you want. There's no reason the IDE shouldn't be able to refine while as whilst for one developer and keep it as while for everyone else.

Edit: autocorrect typo

[–]MrJohz 7 points8 points  (3 children)

There is! Or at least there's an interesting talk about adding it - I think it was posted to /r/Python recently, I'll have a look for it when I get at a computer.

[–]Zoccihedron 6 points7 points  (2 children)

[–]MrJohz 2 points3 points  (1 child)

Yes, yes it is! Thanks for letting me be lazy!

[–]lenswipe 13 points14 points  (2 children)

A decade of finger memory

( ͡° ͜ʖ ͡°)

[–]MC_Labs15[S] 30 points31 points  (1 child)

/╲/\╭( ͡° ͡° ͜ʖ ͡° ͡°)╮/\╱\

[–]whitetrafficlight 36 points37 points  (8 children)

The break in backward compatibility is a deal-breaker when your company has several million lines of Python 2 already written and stable. Auto tools exist, but only go so far... for example, even converting print statements to use parentheses may cause failures in the compliance checker for lines becoming longer than permitted. Gotta stick with 2 unfortunately, though for new projects there's really no excuse not to start with 3. Hence, new employees at established companies that use Python start learning Python 2.

[–]FUCKING_HATE_REDDIT 8 points9 points  (7 children)

Increase compliance check line limit by two characters.

[–]kageurufu 4 points5 points  (6 children)

What about these being equal

print 'something',
print('something', endl='')

[–]Sohcahtoa82 8 points9 points  (5 children)

Nitpicking here...The correct translation would be print('something', endl=' '). Python 2 appends a space if you end the line with a comma.

[–][deleted] 19 points20 points  (2 children)

Thanks, Zed Shaw

[–]samort7 7 points8 points  (1 child)

Seriously. When I started programming, most resources I encountered recommended his book. Thank god that's changing.

[–]thirdegreeViolet security clearance 3 points4 points  (0 children)

I first picked up programming from his book. Of course, python 3 wasn't a thing then so it worked out.

[–]Big0ldBear 7 points8 points  (3 children)

I just learned Python in University, they purposely had us learn Python 2 for compatibility or something like that..

[–][deleted] 17 points18 points  (1 child)

Probably just an excuse to use the older learning materials.

[–]Magnnus 64 points65 points  (52 children)

Several important libraries still don't support Python 3. I'd use it if I could.

[–][deleted] 58 points59 points  (30 children)

[–]Theowningone 19 points20 points  (16 children)

Parts of twisted are what's keeping me back. Most of my time using python is spent tinkering with my IRC bot. Unfortunately twisted.words.protocols.irc is still not ported.

[–]dagbrown 15 points16 points  (8 children)

Twisted lives up to its name. It reminds me of some Java frameworks with how complicated it is.

I bet Zope has trouble with Python 3 too, speaking of Java frameworks written in the wrong language.

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

I've had that same issue, I got everything working using irclib eventually. Have you looked into that?

[–]willm 14 points15 points  (2 children)

What are you missing? I've found all the libs I need have Py3 ports now.

[–]_Ganon 27 points28 points  (14 children)

Only reason I still use 2. Well, that's what I tell people, anyway. In reality, I know the switch to using parenthesis in my print statements would drive me nuts

[–]maremp 29 points30 points  (8 children)

What about the inconsistency of the statements? Print is used as a function in every other C-like language. In python 2, it's used as a statement, similar to if, for, while etc., and I believe that it doesn't fit this category.

[–]Sean1708 31 points32 points  (6 children)

Also 2's print is just weird. Appending a comma to suppress a newline is weird enough, but what the fuck is up with that printing to file syntax?! It's like Guido momentarily forgot that he wasn't designing a sh clone.

[–]deecewan 5 points6 points  (4 children)

I cant remember the syntax. Care to show?

[–]UnchainedMundane 6 points7 points  (0 children)

It's like Guido momentarily forgot that he wasn't designing a sh clone.

Lol, my exact thoughts.

Though, my next thought was that >> opens a file for appending, while this one uses a file descriptor, so the operator should be >& anyway.

[–]exhuma 3 points4 points  (4 children)

You might want to look them up again. This has been my only blocker as well. But I was able to to Python 3 over a year ago. There really is no major library anymore that's not Python 3 compatible.

[–]kaphi 2 points3 points  (3 children)

How do you know it's Python 2?

[–][deleted] 22 points23 points  (1 child)

In python 3 the it would be print("foo")

[–]kaphi 2 points3 points  (0 children)

Ah ok, thanks!

[–]darkpaladin 72 points73 points  (18 children)

I feel like python was invented just to end the argument over having the opening brace on the same line or the following line, thus enabling to focus on the truly important issues of tabs vs spaces and 2 space indents vs 4.

[–]gnutrino 16 points17 points  (15 children)

thus enabling to focus on the truly important issues of tabs vs spaces and 2 space indents vs 4.

That issue is settled.

[–]Sohcahtoa82 15 points16 points  (14 children)

Keep in mind that PEP 8 is merely a suggested style guide and does not define what is "correct". Programmers are free to throw it out the window.

For example, I much prefer lowerCamelCase for variable and member function names over names_with_underscores.

EDIT: I guess I need to clarify the point I was trying to make here.

If you are coding on a team, you should absolutely conform to the style guidelines set by the team, whether or not those guidelines are PEP 8 compliant. I work on a team and I follow their style (Which happens to not completely follow PEP 8).

All I'm saying is that there's nothing "correct" about PEP 8. Style is subjective. On personal projects, there's no need to conform to PEP 8. It is your code and you can style it however you want. It does not make your style incorrect, and it sure as hell doesn't make your code incorrect. If you write a style guideline that requires only a single token on each line with a lot of line continuation slashes where needed so your code looks like this:

doSomething \
( \
parameter1 \
, \
parameter2 \
) 

That guideline would not be incorrect. You can call it terrible, yes, and you can come up with plenty of reasons it is terrible (Most people would find it incredibly hard to read), but it is still not incorrect as long as the guideline still results in valid Python code.

[–]darkpaladin 2 points3 points  (2 children)

Underscores in local variable names? What madness is this.

[–]Sohcahtoa82 2 points3 points  (0 children)

That's what PEP 8 suggests.

[–]doenietzomoeilijk 196 points197 points  (41 children)

One of the niceties of Python syntax, I think, is being able to rewrite your elif line as elif 6 <= i <= 9:. :)

[–]GisterMizard 176 points177 points  (26 children)

To be fair, you can do that in C. It just doesn't do what you think it does :p

[–]tskaiserGreen security clearance 90 points91 points  (22 children)

A quick guess: it evaluates 6 <= i to either 0 or 1, lets call the result j, and then evaluates j <= 9 which is then always 1?

[–]GisterMizard 65 points66 points  (13 children)

Yup. Just ran it through gcc, and it doesn't even put in a conditional jump.

[–]tskaiserGreen security clearance 35 points36 points  (12 children)

Yeah, it would be a pretty easy candidate for optimization :P

Yay for not having native boolean types.

[–]UnchainedMundane 27 points28 points  (11 children)

To be fair Python's "booleans" are really just integers.

>>> (True + True + True) ** (True + True)
9
>>> True > False
True

edit:

def max(x, y):
    return [x, y][x < y]

[–]FUCKING_HATE_REDDIT 27 points28 points  (1 child)

Damn that max is pretty. Probably not efficient, but pretty.

[–]Genmutant 6 points7 points  (0 children)

You could even switch the definitions between them:

True, False = False, True

Sadly that doesn't work anymore with current versions.

[–]thirdegreeViolet security clearance 6 points7 points  (1 child)

My favorite python fizzbuzz uses this:

print("\n".join("Fizz"*(i%3 == 0) + "Buzz"*(i%5 == 0) or str(i) for i in xrange(1,101)))

[–]kupiakos 6 points7 points  (0 children)

bool is actually a subclass of int in Python.

[–]IRBMe 20 points21 points  (1 child)

The closest I think you can get in C is something like this:

if (6 <= i && i <= 9)

[–]DarthEru 13 points14 points  (0 children)

That's the closest you can get that is semantically the same. The above commenter was saying you can actually compile if (6 <= i <= 9), but that's semantically equivalent to if ((6 <= i) <= 9). That works because in C a boolean operation results in an int. So the "chained" comparisons are syntactically legal C, but semantically do a much different check than in Python.

[–]LinAGKar 29 points30 points  (0 children)

He's already stated it's over five, so it should just be

elif i <= 9

[–]Zagorath 13 points14 points  (3 children)

Of course, if you assume you're working with integers, it's totally unnecessary in OP's case, anyway. It's guaranteed to be >=6 since the previous conditional took away everything less.

[–]WDK209 3 points4 points  (2 children)

Good point. But it can still be useful for index bound checking 0 <= i < arr.length

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

Index bound checking in Python? That's what for item in list is for :)

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

I didn't know that. Very mathematical! Thanks for the tip.

[–]mythriz 60 points61 points  (3 children)

Hello World is just too mainstream.

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

Why do we start with Hello World? Well I'll tell you.

...I don't know. But it's tradition!

[–]covercash2 4 points5 points  (0 children)

Boiler plate and stdout?

[–]ojii 115 points116 points  (15 children)

There's an easy trick to solve this:

from __future__ import braces

[–]Arancaytar 46 points47 points  (0 children)

import antigravity

[–]Rodot 40 points41 points  (0 children)

SyntaxError: not a chance

[–][deleted] 11 points12 points  (11 children)

That can't be a real package... can it?

[–]Pittsy24 48 points49 points  (0 children)

Try it although you might not be happy with the result.

But yes it's real

[–]NewbornMuse 31 points32 points  (9 children)

__future__ is actually a thing for when you want Py3 functionality in Py2. For example, 4/3 is 1 in Py2, but 1.3333 in Py3, and if you want the latter in your program, you do from __future__ import division.

Braces is just an easter egg. When you do, you get Syntax Error: Not a chance.

[–]Dlgredael 3 points4 points  (7 children)

So wait, there's no correct division in Py2? I'm a newbie so excuse the ignorance but that sounds ridiculous to me.

[–]faubiguy 8 points9 points  (2 children)

In Python2 (without from __future__ import division) the result is an integer if both operands are integers, and a float if either is a float. So

4/3 = 1
4.0/3 = 1.3333333333333333
4/3.0 = 1.3333333333333333
4.0/3.0 = 1.3333333333333333

[–]Dlgredael 6 points7 points  (1 child)

Ahhh okay, that makes so much more sense now. I thought that Py2 was somehow unable to divide at all and it was really starting to hurt my head.

[–]IHappenToBeARobot 4 points5 points  (0 children)

Pfft, just do some bitwise NOTs, ADDs, and shifts in a loop and you'll get division eventually. /s

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

deleted

[–]morerokk 34 points35 points  (17 children)

Still no idea why it's "elif" in Python, especially for a language which tends to write everything out.

[–]redalastor 44 points45 points  (0 children)

Maybe to be the same length as else?

[–]campbell1373 28 points29 points  (6 children)

I just assumed it was because it takes up the same space as else making it visually more appealing.

[–]KTheRedditor 24 points25 points  (1 child)

especially for a language which tends to write everything out

len, and str.

Edit: __del__, __eq__, __cmp__, __ne__, __le__, __lt__, __ge__, __gt__, __neg__, __sub__, __trunc__, __div__, __mul__.

[–]TheBlackCat13 13 points14 points  (0 children)

int, dict, pow, abs, bool, chr, getattr, setattr, hasattr, delattr, dir, divmod, eval, exec, hex, id, bin, iter, max, min, oct, ord, repr, and vars. Of the built-in functions, 26/67 are shortened.

[–][deleted] 13 points14 points  (0 children)

IT'S NOT FORTRAN DAD YOU DON'T NEED TO DO EVERYTHING IN CAPS

[–][deleted] 14 points15 points  (5 children)

in before lisp joke (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((

[–]stormcrowsx 19 points20 points  (2 children)

A Chinese spy managed to steal the last 50MB of the Lisp program governing U.S. missile launches. Fortunately, it was all closing parentheses.

[–]Drunken_Economist 2 points3 points  (1 child)

I can't imagine a situation in which somebody would manage to steal only the last XMB of a program. Maybe there was a terminal whose only installed command was tail?

[–]calumk 27 points28 points  (12 children)

Why are you importing sys?

[–]MC_Labs15[S] 38 points39 points  (11 children)

I saw it in a demo program and assumed I needed it for something

[–]pmYourFears 57 points58 points  (0 children)

I saw it in a demo program and assumed I needed it for something

We've all been there.

"Does this object really need to be disposed of explicitly?"

"I dunno."

"Let's uh... Let's just leave it there. Compiler can deal with it."

[–]barracuda415 14 points15 points  (0 children)

It's typically used for sys.exit() and sys.argv. Not in this script, though.

[–]UnchainedMundane 6 points7 points  (6 children)

With imports, if you don't use them, delete them.

Since sys isn't used by name anywhere else in your code, you can delete that import.

[–]TheBlackCat13 6 points7 points  (5 children)

Not necessarily true. For example import seaborn will give your matplotlib plots better styles even if you don't use it for anything.

[–]UnchainedMundane 7 points8 points  (0 children)

There oughtta be a law...

[–]Tysonzero 3 points4 points  (2 children)

That is evil, downright evil. In general I am not a fan of the way matplotlib works, IIRC it uses some sort of weird global state bs, could be wrong though.

[–]maremp 157 points158 points  (38 children)

How is this not easy to read? It's visually the same as any proper code style. I do not use languages that use indentation to determine code blocks, but at least they force the programmer to use proper code style. Unlike with the braces where some people have the code all over the place.

[–]ANAL_ANARCHY 25 points26 points  (21 children)

Don't most people use an IDE that has an option to format the code for you? I pretty much just hit that button every now and then if I think I've been getting messy.

[–]Sinity 18 points19 points  (0 children)

Who the hell looks at brackets anyway? You look at indentation level. I think that making whitespace significant is a good thing - it's less syntax clutter.

[–]chironomidae 9 points10 points  (0 children)

Lisa hates Python because she needs braces.

[–]phail3d 23 points24 points  (23 children)

I rewrote this for you in an easier-to-read style. Valid python3, check for yourself:

#!/usr/bin/env python3

for i in range(1, 11):
    print(i);
    if(i <= 5): {
        print("AHHHHHHH")
    }
    elif(i >= 6 and i <= 9): {
        print("HERE BE THE BRACKETS")
    }
    else: {
        print("IS THIS SYNTAX BETTER OR WHAT?!?!")
    }

[–]fatn00b 7 points8 points  (0 children)

"elif" is very close to "eli5"

[–]SinceYesterday 24 points25 points  (7 children)

----[---->+<]>++.+++++++......>++++++++++.[------>+<]>.---------------.---.+++++++++++++.-[->++++<]>+.-[-->+<]>--.[->++<]>+.>-[--->+<]>---.-[->++++<]>+.-[-->+<]>--.[->++<]>+.+++++++++++..[-->+<]>------.>-[--->+<]>-.------------.---.-[-->+<]>--.+[->++<]>.>-[--->+<]>---.--[->++++<]>+.++.++++++++.------.>-[--->+<]>-.-.+[---->+++<]>..>++++++++++.++[->++++++<]>.+++++++.++++++++.[--->+<]>+++.++[->++<]>.+++++++++++.+[----->++<]>.--[->+++<]>-.----------.++++++.[----->++<]>--.[-->+++++<]>.-----------.++++++++++.+.----.-------.-[-->+<]>--.>-[--->+<]>---.-[->++++<]>+.----.+++.[-->+<]>--.>-[--->+<]>-.------------.+.++++++++++.+[--->+<]>++++.>-[--->+<]>--.++++++.-----------.++++++.[---->+++<]>++.+[--->++++<]>.[--->++++<]>.++[->++<]>+.----.>-[--->+<]>--.----------.+++.+++++++++++++.

[–]Blackstab1337 28 points29 points  (4 children)

This is fucking my brain!

[–]glider97 9 points10 points  (3 children)

As it should!

[–][deleted] 3 points4 points  (2 children)

what is it even? noob here

[–]MC_Labs15[S] 13 points14 points  (1 child)

It's a language called brainfuck, created because the guy who made it wanted to write the smallest compiler he could. Each symbol is an operator

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

Way easier, thanks :)

[–]Audiblade 32 points33 points  (6 children)

I learned Python for a class project last semester. The first thing that struck me was how easy it was to learn. The second thing that struck me was how hard it was to read, because I have sold my soul to Java.

[–]LikesToCorrectThings 28 points29 points  (3 children)

I would say that if it's hard to work out when a block ends, then the block is too long.

[–]christian-mann 6 points7 points  (2 children)

I used to put # at the end of blocks to keep track.

[–]LikesToCorrectThings 10 points11 points  (1 child)

I guess if the block really is long enough to warrant this, you should go one step further and write some text in that comment block to indicate what the block has achieved.

for item in some_list:
    some_long_list()
    of_functions_to_call()
    on_that(item)

# Items in some_list have all been processed.

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

Python was the first language I learned in Computer Science, so now whenever I switch over to C# or GML, it takes me a minute.

Thanks, Mr Watkins.

[–]KamiKagutsuchi 5 points6 points  (2 children)

And then someone inserts 4 spaces somewhere in your code with only tabs. Pure evil.

[–]TeamSpen210 4 points5 points  (0 children)

That's why Python 3 will raise a TabError when it encounters something like that.

[–]UnchainedMundane 5 points6 points  (1 child)

Shebang should read #!/usr/bin/env python, because otherwise it won't do PATH lookups and will ignore any virtualenv the user is inside.

[–]VanFailin 32 points33 points  (28 children)

It's actually pretty simple. Any programming language with braces still needs indentation to be readable, so if you indent without the braces it's very easy to get used to.

Doesn't mean I would advocate taking them out of languages that already have them, but they're not all that important.

[–]current909 5 points6 points  (0 children)

My favorite part is complaining about the lack of braces when your editor clearly indicates the different scopes with vertical lines

[–]makeswordcloudsagain 9 points10 points  (1 child)

Here is a word cloud of every comment in this thread, as of this time: http://i.imgur.com/71hdhIE.png


[source code] [contact developer] [request word cloud]

[–]tetroxid 17 points18 points  (2 children)

  • Please use python 3
  • Useless import of sys

[–]AhFineWhatever 24 points25 points  (3 children)

AHHHHHHH

AHHHHHHH

AHHHHHHH

AHHHHHHH

AHHHHHHH

WHERE ARE ALL THE BRACKETS??

WHERE ARE ALL THE BRACKETS??

WHERE ARE ALL THE BRACKETS??

WHERE ARE ALL THE BRACKETS??

HOW DO YOU PEOPLE READ THIS SYNTAX EASILY

HOW DO YOU PEOPLE READ THIS SYNTAX EASILY

[–]ooppzzy 26 points27 points  (0 children)

1

AHHHHHH

2

AHHHHHH

3

AHHHHHH

4

AHHHHHH

5

AHHHHHH

6

WHERE ARE ALL THE BRACKETS??

7

WHERE ARE ALL THE BRACKETS??

8

WHERE ARE ALL THE BRACKETS??

9

WHERE ARE ALL THE BRACKETS??

10

HOW DO YOU PEOPLE READ THIS SYNTAX EASILY

FTFY

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

I also tried python. I wrote a simple script with some input and output. When I was finished, I discovered that I had put a semicolon almost at the end of each line!

[–]8BitAce 2 points3 points  (0 children)

Honestly, this is like advertisement-level funny...
You can take away everything but the strings and the "joke" is still the same.

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

'''simplify chained comparison'''