Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Python 3.0 Released

Posted by samzenpus on Thu Dec 04, 2008 07:57 AM
from the break-out-the-cigars dept.
licorna writes "The 3.0 version of Python (also known as Python3k and Python3000) just got released few hours ago. It's the first ever intentionally backwards-incompatible Python release."
+ -
story

Related Stories

This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • woohoo (Score:5, Informative)

    by liquidpele (663430) on Thursday December 04 2008, @08:02AM (#25987639) Homepage Journal
    will have to give it a try. For anyone interested, here is the what's new [python.org] page.
    • Re:woohoo (Score:5, Funny)

      by Anonymous Coward on Thursday December 04 2008, @08:31AM (#25987881)

      But I just came in here for an argument!

    • Re:woohoo (Score:4, Funny)

      by Chapter80 (926879) on Thursday December 04 2008, @11:09AM (#25989751)
      GREAT!

      Interestingly, it IS backwards compatible in areas that you wouldn't think it should be. For instance, the following program takes the version number, adds one to it, and divides by two. You'd think it'd give a different answer between version 3 and version 2. Glad they kept this program working for me, as it's the secret production code that runs my multi-million dollar business.

      import sys
      version=int(sys.version[0])
      print (version+1)/2

      Prints 1 in either version. (on the bright side, 1/2 is now 0.5!)

      • Re:woohoo (Score:4, Funny)

        by Chapter80 (926879) on Thursday December 04 2008, @11:10AM (#25989773)
        oops I really screwed that joke up... crap. somebody fix it.. you know what I was trying to do!
        • Re:woohoo (Score:5, Funny)

          by Random BedHead Ed (602081) on Thursday December 04 2008, @11:31AM (#25990073) Homepage Journal
          I think you should use a few more posts to explain the joke. The more you go on the funnier it gets. :)
          • Re:woohoo (Score:5, Funny)

            by Chapter80 (926879) on Thursday December 04 2008, @01:49PM (#25992407)
            OK. well, what I was aiming for was:

            True Part:
            In Python version 2, 1/2 = 1 (integer math)
            In Python version 3, 1/2 =0.5 (floating point math)

            Funny part:
            You can do some math on the version number and it comes out the same, even though the version number has changed. Because the divide operation changed too.

            wait, it's not so funny after all. What was I smoking?

  • Libraries (Score:5, Interesting)

    by explodymatt (1408163) on Thursday December 04 2008, @08:03AM (#25987653)
    Python 3 being out is great, they've fixed a few things that allow bad programming, but does anyone know how long it will take for the libs to start getting ported? Especially numpy and scipy
    • Re:Libraries (Score:5, Informative)

      by Yvanhoe (564877) on Thursday December 04 2008, @08:06AM (#25987681) Journal
      Last time I checked (several months ago) it was not thought that backward compatibility would be broken very hard. Most of the modification to do should be automatic so I think that a lot of packets that are still maintained will quickly be made compatible for python 3
      • Re:Libraries (Score:5, Insightful)

        by Alomex (148003) on Thursday December 04 2008, @09:16AM (#25988293) Homepage

        Backward compatibility is (i) over-rated and (ii) misunderstood.

        It is over-rated in the sense that the number of current users which are inconvenienced is a very small percentage of the total number of users of the language (unless the language is in the tail end of its life, like Fortran and Cobol).

        It is misunderstood in that with the use of a simple header or import declaration it is possible to have two different versions co-exist while the transition happens. This is done in HTTP where the first thing that clients exchange is the version of the protocol they'll use. It is also done in LaTeX, where the first declaration informs the compiler which major version is being used (pre-2e or 2e).

        Kudos for Python for not being afraid to rock the backwards compatibility boat.

        • Re:Libraries (Score:5, Informative)

          by Rostin (691447) on Thursday December 04 2008, @11:13AM (#25989807)

          unless the language is in the tail end of its life, like Fortran...

          Fortran will continue to thrive for many years. I don't know numbers, but based on my personal experience, it's the preferred language of most computational scientists and engineers. The most recent revision occured in 2003. According to this [acm.org], a new one is being worked on.

          • Re:Libraries (Score:5, Insightful)

            by Alomex (148003) on Thursday December 04 2008, @11:32AM (#25990097) Homepage

            Fortran will continue to thrive for many years.

            I agree. The point is that the number of current users is a non-negligible percentage of the universe of future users. It is in that sense that it is "near the tail end".

            For languages which are very early in their life cycle, such as Python, the number of users inconvenienced today are negligible compared to the total number of users that it will have and benefit from the changes.

            • Re:Libraries (Score:4, Informative)

              by 644bd346996 (1012333) on Thursday December 04 2008, @02:34PM (#25993085)

              Python can't replace Fortran, but C can (and to a large extent, is). For most serious scientific computation, the initial software is written in a language like MATLAB or Python, which make use of number crunching libraries written in C or Fortran. When that code needs to be modified to run on a supercomputer instead of a workstation, it is usually converted to pure C or Fortran.

              Interpreted and interactive languages like MATLAB and Python make it easy to prototype and test a new algorithm, but C and Fortran are still necessary to make an efficient implementation.

              (Disclosure: I am a mathematician, currently using all the above languages for ongoing research, though I am studiously avoiding having to write any Fortran myself.)

            • Re:Libraries (Score:5, Insightful)

              by Vornzog (409419) on Thursday December 04 2008, @02:40PM (#25993173)

              I wonder if Fortran may eventually be replaced by Python.

              Already has been, in my world. I know plenty of people around the chem department who still use Fortran because 'it is the language of scientific computing, dammit!'

              Here is the thing. Most of the time, they were so panicked about how long the program would take to run, they lost sight of how long it took them to write it.

              I replaced many Fortran programs with Python in my time, because I could write the data IO so much faster, and then just use the C-level numerical libraries to do the analysis. The program would end up running just as fast, and the code could be written in an hour instead of a week.

              Some people will die before they change languages. The rest of us just want our results. Hopefully, the switch to py3k goes easy and the community continues to grow.

    • Re:Libraries (Score:4, Interesting)

      by gzipped_tar (1151931) on Thursday December 04 2008, @08:21AM (#25987789) Journal

      IIRC numpy and scipy have dependencies on other libraries that are not 2.6-clean. They also have a lot of issue themselves. Currently it's not a priority for them to migrate.

      Can't remember when did I read about that... and I'm too lazy to dig it out from their Trac :-P

        • Re:Libraries (Score:5, Informative)

          by gzipped_tar (1151931) on Thursday December 04 2008, @08:59AM (#25988167) Journal

          I just did a Google search site:scipy.org ("2.6" OR "3.0") -"ipython" -"nipy" and there are a lot of results turning up (and of course lots of bogus ones).

          It seemed things are much better that I thought of. Those guys are making progress every day and my news were old news...

          The difficulty with numpy/scipy is they need a great amount of C-level coding. There's 2to3 for Python code but tweaking C code is not that easy...

        • Re:Libraries (Score:5, Insightful)

          by Anonymous Coward on Thursday December 04 2008, @01:54PM (#25992479)

          I can't help but think it was designed by someone who was pissed off that people didn't format their code the way he formatted his code. Since his way was obviously the "right" way, why not write a language that forces you to do it that way? Problem solved!

          This is actually the main reason I haven't worked with Python beyond tweaking a few existing scripts. The funny thing is that (unless I'm misremembering the syntax) I already code using that style in other languages. But the idea of forcing that style on everyone annoys me enough to put me off of the language as a whole.

          I was really hoping that 3.0 would remove that petty stupidity. Doing so would even retain backwards compatibility with prior versions!

          I just don't get it when people say that, its sorta like saying you don't use language X because you have to store numbers as floats or integers instead of char variables.

          I honestly like the fact that Python forces a coding format, I hate opening someone else's source and spending the first minutes trying to understand how they layout things if at all. And yes if people were smart it would be easy to pickup anyones code, sadly that world doesn't exist.

          No its not petty stupidity, not using Python because of your reasons is sadly what I would call petty stupidity.

        • Re:Libraries (Score:5, Informative)

          by bnenning (58349) on Thursday December 04 2008, @02:05PM (#25992665)

          But the idea of forcing that style on everyone annoys me enough to put me off of the language as a whole.

          I had that exact reaction when I first came across Python. But after giving it a chance (many years later), I realized that it doesn't force a style any more than C forces the "style" of putting braces around blocks. Indentation levels are just syntax elements that happen to correspond to what most developers naturally do. Really, having to indicate blocks to the compiler in one way and to humans in another way is a DRY violation, which Python eliminates.

  • good (Score:4, Funny)

    by Anonymous Coward on Thursday December 04 2008, @08:04AM (#25987665)

    previous releases were incompatibilie with earlier ones unintentinally.

  • Release notes (Score:4, Informative)

    by Max Romantschuk (132276) <max@romantschuk.fi> on Thursday December 04 2008, @08:05AM (#25987671) Homepage

    The release notes might interest people:
    http://docs.python.org/dev/3.0/whatsnew/3.0.html [python.org]

    Also note that in the end of the release notes are info on the migration path from Python 2 to 3. I'll leave the rest to people who bother to RTFA... ;)

  • by gzipped_tar (1151931) on Thursday December 04 2008, @08:13AM (#25987731) Journal

    The cool thing about Python is it's "time machine". In Python 2.x you can "from __future__ import " to use features scheduled for future releases. With the release of Python 2.6 there's also a "2to3" tool that will point out revisions needed for 2.x code to be 3.0-compatible, and generate patches for you.

    The Python developers have been aware of the difficult road of migration long before the release of Python 3, and they did a lot of careful planning and hard work for it. One of them being the __future__ module that has been there for quite long time just for this reason.

    As a Python user, my hat off for them. I wish them success heartily.

    BTW: In case you don't know, there's an Easter egg in the time machine: "from __future__ import braces" ;)

    • by makapuf (412290) on Thursday December 04 2008, @08:23AM (#25987815)

      You can also use the python 2.6 "-3" option to have warnings about non future-proof constructs (ie things that can't be handled by 2to3)

      in fact there are others python easter eggs :

      import this
      import __hello__

      and ... a new one in 3.0, related to xkcd.

      • Re: (Score:3, Informative)

        Ironically, the XKCD referring to python is now false : Hello world is not

        print "Hello world"

        anymore but in 3.0 :

        print("Hello world")

        But I guess the point is still valid.
  • by neoform (551705) <djneoform@gmail.com> on Thursday December 04 2008, @08:18AM (#25987763) Homepage

    Where's the mac version..?

  • by Ancient_Hacker (751168) on Thursday December 04 2008, @08:18AM (#25987767)

    Yes, Python 3.0 is a break.

    But in the past and forseeable future, Python has been exceedingly helpful, much more than most languages, during upgrades.

    Usually one has several months to try out new features-- they're in the current version but turned off until you ask for them with "future_builtins".

    Plus there's often a backwards feature in the next version to revert back to old behavior.

    Not to mention a -3 option to point out the lines in your old program that will need changing for version 3.

    But sometimes the changes are so big they can't be encompassed by a compiler switch. Such it is with 3.0.

     

    • Re: (Score:3, Interesting)

      But sometimes the changes are so big they can't be encompassed by a compiler switch. Such it is with 3.0.

      While I agree with your post, here it's not a problem with implementation but with syntax and backward compatibility within a given python version.
      The idea is that some needed changes cannot be made backward-compatible (new keywords, ...). So you group them and call that a new version of the language. I doubt you couldn't implement most of it with compiler switches.

  • by slumberheart (1423685) on Thursday December 04 2008, @08:39AM (#25987947)
    SyntaxError: maybe in 3.5
  • Yay, Unicode! (Score:5, Interesting)

    by shutdown -p now (807394) <int19h@@@gmail...com> on Thursday December 04 2008, @08:44AM (#25988007)

    Reworked Unicode support is a big deal. It was there before, of course (unlike Ruby - meh), but all those Unicode strings vs 8-bit strings, and the associated comparison issues, complicated things overmuch. Not to mention the ugly u"" syntax for Unicode string literals which was too eerily like C++ in that respect. Good to see it move to doing things the Right Way by clearly separating strings and byte arrays, and standardizing on Unicode for the former.

    Now, if only we could convince Matz that his idea for Unicode support in Ruby 2.0 - where every string is a sequence of bytes with an associated encoding, so every string in the program can have its own encoding (and two arbitrary objects of type "string" may not even be comparable as a result) - is a recipe for disaster, and take hint from Python 3...

          • Re:Yay, Unicode! (Score:4, Informative)

            by shutdown -p now (807394) <int19h@@@gmail...com> on Friday December 05 2008, @01:12AM (#25999547)

            It sounds like Python 3.0 will throw an error if you read a file that contains invalid UTF-8, until the program is rewritten to read the file as "bytes". Then it will throw errors when you convert the bytes to "str", until you rewrite the functions reading the files to return bytes instead of str. Then the users will hit this problem in that their code will no longer compile. I can't see this being any good.

            Why isn't it? If your input file is supposed to be UTF-8 text, and is not, then surely it's an error? As you say yourself, you can always load it as raw bytes if you want to work with it nonetheless. But, of course, as soon as you want to start treating it as an actual string - so that you can say things such as "give me the 10th character" (and not "10th byte") - it has to be valid, otherwise all string-specific operations would simply be undefined.

            You are parroting the same crap used by people who don't like UTF-8 and try to make it more difficult than it really is. It is indeed UTF-8, just because it has errors in it does not make it not be UTF-8, anymore than a misspelled word makes this post not be English.

            I like UTF-8, but UTF-8 with errors in it is clearly not valid UTF-8, no more than XML with a missing closing tag in the middle of the file is valid XML. The problem with such UTF-8, as I've mentioned earlier, is that no string processing function would know what to do with it. If you, say, try to convert it to uppercase, what should it do with invalid sequences? What about the earlier example of indexing by characters, or taking the leftmost or rightmost N characters - how should it could the unterminated sequence?

            You seem to have forgotten languages called "C" and "C++". I heard they were pretty popular...

            No, I did not. C and C++ actually work in precisely the way Python 3 does. The only difference is that in them, a plain unadorned string literal is a "byte array", and you have to explicitly request wide chars (to simplify, let's assume it means always means "Unicode" for now) by prefixing it with "L". Otherwise, it's precisely the same. In particular, L"\xC2\xA2" is not a cent sign in either C or C++. It's a wide (string with two characters. Plain "\xC2\xA2" is a non-Unicode (i.e. byte) string of two bytes, which produces a cent sign when treated as UTF-8 - and so is byte string b"\xC2\xA2" in Python.

            I think you might also check exactly what some of those languages do, you can't put more than \xff into most of them so they are actually doing exactly what I am saying

            It's a legacy of C/C++ - they couldn't extend the "\x" escape sequence to use more than 2 digits without breaking existing string literals, so they left it as is. In C/C++, Java, C# etc, if you want a full-length Unicode escape, you use "\u1234". However, note that it doesn't really change anything - inside a Unicode string literal, in all these languages, "\xFF" is the same as "\u00FF", which is the same as "\U000000FF". None of them allows to define individual bytes in Unicode string literals.

            What you are saying is that there is no difference between \x and \u, which seems pretty stupid to me.

            Yet that's how it is. Do you want quotes from the respective language specifications?

            The compiler is already assuming UTF-8 when it parses u"abÂ" so I see no reason it can't assume UTF-8 here as well.

            This decision is made on different levels. The compiler isn't assuming UTF-8, the code which reads the file as a sequence of characters (before lexing, much less parsing, takes place) does that. On the other hand, processing the content of the string literal is (most likely) done by the lexer, including character escapes. Also, keep in mind that non-UTF input files are still legal - should escape sequences in literals suddenly change meaning for them?

  • print function (Score:4, Interesting)

    by togofspookware (464119) on Thursday December 04 2008, @09:03AM (#25988181) Homepage

    First thing mentioned on the 'what's new' page (http://docs.python.org/dev/3.0/whatsnew/3.0.html)is that you'll have to change your code from

        print x, y, z,

    to

        print(x, y, z, end="")

    I can see the value of making things more consistent, but it seems to me whenever they update things in Python, it's usually to make programming in it a little bit harder.

    Why not make print a function, but then change the language to not require parentheses for any function call? You'd still have to use them when calling a function with zero arguments, and in sub-expressions, but to not require parens for top-level function calls would, if nothing else, make playing around in interactive mode or with short scripts a lot more pleasant.

    Granted, I come from a Ruby background, so I may not know what I'm talking about. My experience with Python is trying to write some scripts on my OLPC, where the craptacular rubber keyboard made typing parentheses all the more agonizing. I finally caved and installed Ruby so I could get some work done. Maybe people who prefer Python really like typing parens. And underscores.

    • Re: (Score:3, Interesting)

      The IPython (nothing Apple-related) interactive shell hacked the Python lexer to allow exactly this. You type this at the shell prompt:

      foo a, b, c

      it will be interpreted as a call foo(a, b, c).

      IPython still has some bugs with this feature, though. It can be turned out, but I still prefer it in interactive use just as you've mentioned.

      Anyway, I think the current Python syntax is OK.

    • Re:print function (Score:4, Interesting)

      by maxume (22995) on Thursday December 04 2008, @09:23AM (#25988375)

      I would say that it makes typing python a little bit harder, but I would also argue that it makes programming python easier, not harder (it eliminates print as a statement, but it also eliminates special syntax that existed only for redirecting print output, and makes it trivial to change the default behavior of print within a module (by defining a local print function)).

  • That'll be when Perl 6.0 ships.

    • by neoform (551705) <djneoform@gmail.com> on Thursday December 04 2008, @08:32AM (#25987893) Homepage

      I'm fairly certain they got all these non-backward compatibility issues out of the way with this release so they don't have to do this kind of thing again for a long while. My guess is, they wont ever put out a non-backwards compatible release, since those changes were mostly to fix poor coding practices like being able to run certain functions without braces (e.g print "hi").

      • by shutdown -p now (807394) <int19h@@@gmail...com> on Thursday December 04 2008, @08:57AM (#25988145)

        It's also cleanup of some stupid syntax that was there for ages. For example, exception handling. Old style:

        try:
        ...
        except (TypeError, ValueError): # catch both types of exceptions
        ...
        except os.error, e: # catch exception and store into variable 'e'
        ...

        New style:

        try:
        ...
        except (TypeError, ValueError): # catch both types of exceptions
        ...
        except os.error as e: # catch exception and store into variable 'e'
        ...

        It's fairly obvious that the latter is much clearer.

    • by lahvak (69490) on Thursday December 04 2008, @08:45AM (#25988033) Journal

      So what are you going to do, take all your existing Python applications and rewrite them in a different language, in order to avoid the "significant amount of work to maintain existing functionality with new language version"?

    • Besides teh above remark of well thoguth migration paths - it is importante to remakr that support for python 2.x has not ended in any way.

      As far as Iam aware, the recomendation is to keep working with python 2.6 - and use the py2to3 script to regularly to make 3.0 releases if you you can (i.e. if your dependencies have 3.0 versions already).

      No need to worry about anything, this will be a smooth, years long, transition. Chances are we will even see a python 2.7 before 2.x is officially deprecated.

      • by moranar (632206) on Thursday December 04 2008, @10:37AM (#25989229) Homepage Journal

        Besides teh above remark of well thoguth migration paths - it is importante to remakr that support for python 2.x has not ended in any way.

        As far as Iam aware, the recomendation is to keep working with python 2.6 - and use the py2to3 script to regularly to make 3.0 releases if you you can ...

        Are you typing while drunk?

    • Re:Hey! (Score:5, Funny)

      by drewness (85694) on Thursday December 04 2008, @08:46AM (#25988039) Homepage

      As someone mentioned above, try


      from __future__ import braces

      and see what happens. ;)

      As for Ruby, I don't really follow its development or use it, but I was reading just the other day that they're really focused on finishing 1.9, which does byte-compiling and some optimization. The current version (like JS before spidermonkey, V8, and squirrelfish) walks and executes the AST (as I understand it), which is slooow.

    • by MightyYar (622222) on Thursday December 04 2008, @09:53AM (#25988705)

      As they didn't fixed the stupid forced-indentation thing.

      Same reason I don't use C... that stupid forced-curly-brace thing. Why can't the language just know what I want to do?

      </sarcasm>

        • by cleatsupkeep (1132585) on Thursday December 04 2008, @11:14AM (#25989823) Homepage

          Well, the big issue I've run into with Python is when you are editing across multiple text editors, where some might use tabs, and some might use spaces. This seems to trip up Python where it wouldn't mess with a brace delimited language or something with an "end" syntax like Ruby.

          • by Abcd1234 (188840) on Thursday December 04 2008, @12:26PM (#25991041) Homepage

            Cut-n-paste is not a good way to learn.

            Ah, I see, you've never refactored code before. Well, good for you, apparently everything you write is either immediately perfect, or you never have to maintain it!

            Here in the real world, however, we *do* have to cut and paste blocks of code occasionally, and Python makes that annoyingly difficult.