This forum is in permanent archive mode. Our new active community can be found here.

Getting hot with Python

2»

Comments

  • I configure my editor to use 2 spaces instead of a tab when I hit my tab button.

    Why u so mad bro?
    That's not good. For Python you absolutely MUST use four spaces. For other languages, no matter what they are, four spaces is very strongly suggested. I'm not trolling, this is serious. http://www.python.org/dev/peps/pep-0008/

    If you need help, check my vimrc. https://github.com/Apreche/vim/blob/master/vimrc.vim
    That's how I have it set up for everything else. I read the tutorial on python and I saw that it uses the 4 spaces instead of brackets. I was talking about my notepad++
  • Autohotkey could easily be set up to make 4 spaces when you press tab.
  • For Python you absolutely MUST use four spaces.
    Style guides are not MUSTs for everything. If I write my own Python script and I put in full tabs instead of spaces, IT STILL WORKS. Style guides are suggestions to get consistency across multiple writers for say a newspaper, or an open source project. As long as you keep to the grammar of the language, fuck the style guides.
  • Any IDE or text editor worth a shit could easily be set up to make 4 spaces when you press tab.
  • Style guides are not MUSTs for everything. If I write my own Python script and I put in full tabs instead of spaces, IT STILL WORKS. Style guides are suggestions to get consistency across multiple writers for say a newspaper, or an open source project. As long as you keep to the grammar of the language, fuck the style guides.
    Fuck tabs. As far as I'm concerned, if you use tabs in Python code you deserve to die a horrible, painful death.
  • Make a script that swaps tabs and spaces for a random combination of both.
  • For Python you absolutely MUST use four spaces.
    Style guides are not MUSTs for everything. If I write my own Python script and I put in full tabs instead of spaces, IT STILL WORKS. Style guides are suggestions to get consistency across multiple writers for say a newspaper, or an open source project. As long as you keep to the grammar of the language, fuck the style guides.
    Nobody works on code alone. It is incredibly rare that you have code that is written by a single person and is actually used and is never ever read or written by anyone else ever. Especially when working with Python you are going to be sharing a lot of your code with others, and more importantly bringing a lot of open source code into your project. All that open source code will be using four spaces. If you don't use four spaces, you will be in for a world of hurt.
  • I know next to nothing about coding, but I know that when I'm trying to learn how to do something, and someone who does that thing for a living is giving me advice, I tend to take it.
  • I know next to nothing about coding, but I know that when I'm trying to learn how to do something, and someone who does that thing for a living is giving me advice, I tend to take it.
    Wait until you work in computer repair.
  • edited June 2011
    Nobody works on code alone. It is incredibly rare that you have code that is written by a single person and is actually used and is never ever read or written by anyone else ever. Especially when working with Python you are going to be sharing a lot of your code with others, and more importantly bringing a lot of open source code into your project. All that open source code will be using four spaces. If you don't use four spaces, you will be in for a world of hurt.
    I've not had a single fucking problem using 3 spaces-wide expanded tabs. Also way to miss the fucking point.
    but I know that when I'm trying to learn how to do something, and someone who does that thing for a living is giving me advice, I tend to take it.
    Don't. Find someone who both knows how to do that thing and knows how to teach properly, not just someone who makes a living doing it. That just means you end up with a mediocre to bad teacher.
    Post edited by Zombie Nine on
  • edited June 2011
    Style guide where I work says that you should use two spaces; Where I work also employs Guido. Two spaces is clear enough of an indent.

    (the other option is to use a language like C, which has brackets to indicate flow control, and then just use GNU indent to make the code readable to your standards, with a presubmit that makes it readable to the standards of the repository)

    EDIT: To be clear; I'd get no work done without python, awesome language. But I still think it's indent flow-control is a flaw.
    Post edited by GauntletWizard on
  • But I still think it's indent flow-control is a flaw.
    Agreed, though "flaw" seems harsh? I appreciate that Python wants to box you into correct style (god help me I appreciate it), but putting it directly into the language feels inherently wrong to me. Big ups for at least attempting to innovate on block representation in a modern programming language, though.
  • dsfdsf
    edited June 2011
    4 spaces or tab is python's version of:
    {
    }

    I knew that before this thread.
    I'm going to back burner python for a while since I have other things that must be done in other languages as a constraint of the project. When I can think of something to do with python I guess I'll give it another look.
    Post edited by dsf on
  • but putting it directly into the language feels inherently wrong to me
    Technology doesn't care about your feelings. It works.
  • but putting it directly into the language feels inherently wrong to me
    Technology doesn't care about your feelings. It works.
    It doesn't read your comments either ^_~
  • edited June 2011
    but putting it directly into the language feels inherently wrong to me
    Technology doesn't care about your feelings. It works.
    It doesn't read your comments either ^_~
    Yes it does.
    http://sphinx.pocoo.org/
    http://docutils.sourceforge.net/
    Post edited by Apreche on
  • putting it directly into the language feels inherently wrong to me.
    Other than human perception, a space or sequence of spaces is no different than any other character or set of characters.

    But, if you look at Python's core philosophy, then it makes absolute sense. Write it once. If ten programmers are given the same task, and use Python, they should (in theory) write ten identical programs. Enforcing style drives that point home exceptionally well and ensures that most programs will look and read very similarly.
  • edited June 2011
    but putting it directly into the language feels inherently wrong to me
    Technology doesn't care about your feelings. It works.
    It doesn't read your comments either ^_~
    Yes it does.
    http://sphinx.pocoo.org/
    http://docutils.sourceforge.net/
    I wouldn't class that as reading.
    Post edited by Apreche on
  • but putting it directly into the language feels inherently wrong to me
    Technology doesn't care about your feelings. It works.
    It doesn't read your comments either ^_~
    Yes it does.
    http://sphinx.pocoo.org/
    http://docutils.sourceforge.net/
    I wouldn't class that as reading.
    Ok, fine how about this then?
    http://docs.python.org/library/doctest.html
  • Yeah, I'll grant you that one.
  • If ten programmers are given the same task, and use Python, they should (in theory) write ten identical programs.
    I wasn't aware that was python's philosophy. Given that the decision makes significantly more sense. I'm just putting this out there: near as I can tell, Python is the anti-PERL, which is probably the greatest thing ever to happen in computing ever.
  • RymRym
    edited June 2011
    Python is the anti-PERL, which is probably the greatest thing ever to happen in computing ever.
    image
    Post edited by Rym on
  • If ten programmers are given the same task, and use Python, they should (in theory) write ten identical programs.
    I wasn't aware that was python's philosophy. Given that the decision makes significantly more sense. I'm just putting this out there: near as I can tell, Python is the anti-PERL, which is probably the greatest thing ever to happen in computing ever.
    While I enjoy this philosophy, it doesn't hold up for three reasons.

    One is that you can write something in a functional way or in an object oriented way. For any given project, Python already gives you at least two ways to do it.

    Two is that some people know more Python than others. For example, someone who is knew to python might do something like this.

    ...
    result_list = []
    for item in inputs:
    result_list.append(process(item))
    ...

    Someone who knows more Python will write this.
    result_list = [process(item) for item in inputs]
    Someone who knows even more Python will write this.
    result_list = map(process, inputs)
    The main advantage over Perl is that even the advanced programmer's code is still readable. Unlike advanced Perl code which looks like this.
    (*@&#^$(*&^@#$)*(%^&
    Three is libraries and frameworks. Sometimes there is very much agreement and everyone does things the same way. For example, just about every Python web application nowadays uses WSGI. But one person might use Flask and another might use Pyramids. Also, even within the same framework people might do things different ways. While there's only one way to do things in Python, there are multiple ways to do the same thing in Django. For example, one person might use class based views where another person uses a bunch of context processors.
  • While I enjoy this philosophy, it doesn't hold up for three reasons.
    Oh, it definitely doesn't hold up practically on any scale for all of the reasons you mentioned. But, I think it's a good core philosophy.
  • No goofy time tonight
    To clarify: I meant the development of an anti-PERL is the greatest thing. I will admit PERL has its use cases, but it was taken way, way too far. (Like PHP!)
  • Someone who knows more Python will write this.
    result_list = [process(item) for item in inputs]
    Someone who knows even more Python will write this.
    result_list = map(process, inputs)
    The choice between those two isn't really that clear-cut - as far as I know list comprehensions are generally preferred. Also, in Python 3 map returns an iterator, in which case if you'd need list(map(...))) if you want a list.
  • The choice between those two isn't really that clear-cut - as far as I know list comprehensions are generally preferred. Also, in Python 3 map returns an iterator, in which case if you'd need list(map(...))) if you want a list.
    Oh, cool on Python 3.
  • Huh? Cool on?
  • Huh? Cool on?
    Like "good on." As in, "good on ya."
  • dsfdsf
    edited June 2011
    Huh? Cool on?
    Like "good on." As in, "good on ya."
    Fancy ya butchers!
    as in take a butcher's hook!
    as in take a look!

    why didn't you understand what I said?
    seewhutididthar?
    j/k
    What you said reminded me of some cockney slang and the conversation about how ridiculous it was to expect someone from outside that subculture to just understand. I'm not trying to be dickish, I just think linguistics are interesting. And this comment like exactly mirrors some of the the things that I think are interesting about how language morphs and changes.
    Post edited by dsf on
Sign In or Register to comment.