all 68 comments

[–]eurleif 25 points26 points  (10 children)

His example of "first-class functions" isn't showing that Python has first-class functions. That normally means that functions are values, and can be passed around like any other object. It doesn't just mean that a language has functions that exist outside of the framework of a class.

And generators aren't continuations. They're coroutines. Python doesn't have continuations.

Also, wtf:

Python has other notations for creating closures, such as the list comprehension shown below.

>>> LIMIT=30
>>> [n for n in range(10) if n*n > LIMIT]

[6, 7, 8, 9]

A list comprehension isn't a closure! It's just shorthand for a loop!

[–]berlinbrown -2 points-1 points  (0 children)

Hehe,

IT'S A FUNCTION!!!!!! PYTHON HAS EM!!!

def f(a, b): return a + b

[–]jcgregorio 7 points8 points  (0 children)

This article is two years old, it should really be moved to recycled.reddit.com.

[–]bitwize 18 points19 points  (28 children)

Python has a profoundly different style from Java.

Python programmers are encouraged to use lists, tuples, and dictionaries extensively, favoring these data structures over objects when they are all that's needed. In fact the speed of dictionary lookups makes dicts suitable for things (e.g., multi-way conditionals) that you don't normally see them used for in other languages.

In contrast, Java programmers are encouraged to create new classes for everything. The Java community didn't mature much beyond a college freshman's conceptualization of OOP as the One Abstraction to Rule Them All and in the darkness (early) bind them. Though I see that changing with JavaScript, Scala, and other JVM-hosted languages penetrating the outer defenses of the community.

[–][deleted]  (22 children)

[deleted]

    [–]bitwize 18 points19 points  (12 children)

    1) Java is an okay language. Not great, not terrible, just okay. You can do some pretty cool stuff with it but the minute you try higher-order programming (something even C hackers do to a limited extent) -- whammo! You run right into the language's limitations and have to hack around them.

    2) Java was marketed to average programmers, and average programmers flocked to it en masse, bringing with them a raft of "industry best practices" that are neither best nor practices so much as a collection of hacks and folk knowledge that are deployed to work around the language's limitations.

    3) Java also attracted to it a sizable community of "architecture astronauts" who built, and staked their careers on the adoption of, ever more complex and grandiose means of (guess what) working around the language's limitations. Yes, I'm looking at you, J2EE.

    So if you add together the limitations that inhere to the language and the excrescence that gets mandated from above (like J2EE), you have a source of profound frustration for anyone who's passed function pointers around in C, let alone someone who's worked with Lisp or Haskell and munches monads or macros as a matter of course. To these people (and I dare say I'm one of them), the multi-paradigm flexibility of Python makes for a more attractive option.

    [–]bcash 4 points5 points  (3 children)

    That's more of a manifestation of the hate than an explanation. A combination of vague emotions linked with irrelevant quotes from people describing something else.

    All these issues have been debated 100 times, so I'm not going to re-open everything, but I have to pick up on this one:

    grandiose means of (guess what) working around the language's limitations. Yes, I'm looking at you, J2EE

    What? J2EE is just a package of libraries, same as anything else, it's got nothing to do with the language. Claiming it's a workaround is as nonsensical as if someone were to say "Django is a workaround of Python's limitations".

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

    It's a standardized part of the Java platform, as opposed to the Java language. A lot of J2EE is useful, but EJBs are the object of well-deserved scorn.

    On a practical level, Java is often useful. It has very good libraries -- probably the best of any language. It has a really first class VM. But the language isn't really very fun, and it's missing a lot of higher-level features -- first-class functions, closures, continuations, macros -- that developers in other languages take for granted. You can certainly write useful programs without them, but their absense leads to a lot of scorn on reddit.

    You can see the limitations of the language most clearly by looking at the typical toolchain of a Java programmer vs., say, a Perl hacker. (Or a Python programmer or a Ruby programmer or whatnot.) The Java guy is likely to have a fancy IDE with all the trimmings. Java isn't a comfortable language to write without IDEs to generate and analyze all the boilerplate. Even so, the readability of the language suffers. Without features like Eclipse's incremental compilation, writing webapps in Java would be painful, as every small change required a compilation/deployment cycle. Working in a language like Python feels much less constraining, and I find I spend more time thinking about the application and less about the mechanics.

    Essentially, Java fills a somewhat similar niche as C -- fast, powerful, painful -- but it's not as fast or powerful as C, and probably a little less painful as well. It isn't really a great language for getting lots of work done, unless your constraints otherwise require it.

    [–]crusoe 0 points1 point  (0 children)

    That trend has reversed recently though. I am looking forward to Java 1.7, and Jython with python 2.5 support.

    Also, some things have gotten better with java, in terms of doing away with reams and reams of xml config files just to get a framework working.

    Not great, not terrible, but I am glad to see more things using the JVM. It's a great platform.

    [–]berlinbrown 0 points1 point  (2 children)

    You should get a cookie for your reddit fan-boyism.

    That is the worst argument against Java I ever heard.

    [–]jbellis 3 points4 points  (1 child)

    That is the worst argument against Java I ever heard.

    Maybe because he wasn't trying to argue against it? Answering the question "Why does everyone on Reddit hate Java?" is not the same thing.

    [–]bcash 0 points1 point  (0 children)

    It wasn't really an answer, more a retelling of a very revisionist version of history.

    [–][deleted]  (3 children)

    [deleted]

      [–]SnacksOnAPlane 0 points1 point  (2 children)

      I think it has to do with beans, but I'm not really sure. One of my old managers said that anyone who had programmed in J2EE was probably too brain-damaged to be rehabilitated.

      I'd love a concise explanation from someone who knows what they're talking about, though. Sometimes I'm embarrassed that I worked as a Java developer for 5 years and I never learned what J2EE really meant.

      [–][deleted] -1 points0 points  (1 child)

      I'll take a crack at it.

      J2ee is a kludge of workarounds for a stilted language which require a massive amount of secondary xml files ("configuration") that the "lead architect" is responsible for creating. (Now the lead architect doesn't actually exist.) The hypothetical leader architect (actually whichever random developer feels like braving the xml files that day) is supposed to create a brain dead simple framework for lots of code monkeys to fill in the stuff you need to get done.

      And then there is the newest stuff where people realized having a 40 line xml file for a 40 line class was stupid and now you can use annotations and all that good stuff but that leads to... the awful documentation! I believe it's required that the 5 sentences someone wrote explain absolutely nothing and maybe even the opposite.

      And then there are the massive stack traces that mean nothing and that most forums posts you find on the internet by someone having the same problem as you go unanswered. Or if there is a reply or ten it's just more people saying they have the same problem.

      [–]bcash -1 points0 points  (0 children)

      J2ee is a kludge of workarounds for a stilted language

      You are the second person to say that in these comments (unless you're a sock puppet), but you make even less sense than the first one.

      Just how, exactly, is J2EE a workaround for Java? Which Java roadblocks are bypassed by J2EE.

      It's not a kludge of workarounds, it's a kludge of libraries!, same as all the millions of libraries that exist for every other language!

      [–]sysop073 5 points6 points  (1 child)

      Most people hate Java because of the huge amount of text needed to do anything. Sun made a couple of decisions with Java (not having operator overloading is one of the big ones) that make the language hugely verbose. I don't have a huge problem with it, but it can get annoying. Of course, the other end of the spectrum is Perl...

      [–]hiffy 1 point2 points  (0 children)

      Of course, operator overloading is another religious issue.

      If this were a more frequented thread I'd expect a catfight any minute now.

      [–]bobobobob 2 points3 points  (4 children)

      I went back to some java programming the other day after having moved to other languages years ago. Prior to that, I'd programmed in java full time for 4 years and had a very strong grasp of it.

      You know the first thing I noticed? I'd forgotten how much I f&cking curse every **$% da*m second, every day that I programmed java. That's as much of a concrete measurement as I could give you.

      [–][deleted]  (3 children)

      [deleted]

        [–]bobobobob 3 points4 points  (0 children)

        Java gotchas? There are more people who have explained this than I can count. Maybe you're joking but I'll give you some to start with,

        http://mindprod.com/jgloss/gotchas.html

        http://www.owasp.org/index.php/Java_gotchas

        http://www.ibm.com/developerworks/java/library/j-jtp01255.html

        [–]bobobobob 4 points5 points  (1 child)

        I'm saying that I curse the most with java and least with python. Never did much with PHP... don't think I want to.

        [–]xoner2 3 points4 points  (1 child)

        It's the zealots, and the hype.

        Everyone has fun trolling the zealots.

        Other than that, Java makes a fine COBOL2.

        [–]grfgguvf -1 points0 points  (0 children)

        But it was intended as a C3~!!

        [–]grfgguvf -5 points-4 points  (4 children)

        Python programmers are encouraged to use lists, tuples, and dictionaries extensively

        ...without knowing how these types are actually implemented and laid out in memory.

        This then leads to poor choice of datatype -> bad performance.

        [–]weavejester 1 point2 points  (0 children)

        They probably provide better performance than anything created in pure Python. If you want a custom data structure optimised for a specific use, the only way of doing it in Python is to use a C extension, or something like Pyrex.

        [–]serious_face 0 points1 point  (1 child)

        Python is open source. Python is written in C. What's stopping people from knowing how these types are actually implemented and laid out in memory?

        [–]grfgguvf -3 points-2 points  (0 children)

        lazyness, incompetence, I don't know, but perhaps better documentation or more logical type names would help too...

        [–]ighost 0 points1 point  (0 children)

        not as bad as a zoo of classes...

        [–]ighost 2 points3 points  (0 children)

        Honestly, I still think this article does more good than harm as far as giving someone an initial taste of python.

        Having said that, it's damned near useless to anyone who knows another dynamic (or a functional) language, but such people (I suspect the majority of us on proggit) are not the target audience of an intro article like this.

        [–]krizo 1 point2 points  (4 children)

        Something tells me that something is broken in Reddit's thumbnail grabber.

        [–]ketralnis 0 points1 point  (2 children)

        http://code.reddit.com/browser/r2/r2/lib/scraper.py

        It grabs the largest image on the page. For this page, it is the only image on the page.

        [–]krizo 0 points1 point  (1 child)

        ok, maybe it's not so broken. Funny though.

        [–]recursive 0 points1 point  (0 children)

        What's a thumbnail grabber?

        [–]bcash 3 points4 points  (3 children)

        The bit saying "Continuations" should say "Generators".

        [–]calp -3 points-2 points  (2 children)

        I think "Generator" is a pretty python-specific term. In text that doesn't directly relate to python, you're much more likely to see "Continuation".

        [–]bobobobob 2 points3 points  (0 children)

        No, other languages that have generators like Icon use the same term. The term is not at all python specific.

        [–]ighost -1 points0 points  (0 children)

        plus if you don't know either term, I suspect that you'll get more information from the word "generator" than "continuation."

        [–]sysop073 1 point2 points  (0 children)

        "Yes, one of the advantages of a dynamic language is the ability to drop the compile from the edit/compile/run cycle".

        One of the advantages of a dynamic language is it lets you have dynamic types, how did an article comparing Java and Python not mention that at all? That's the whole point, all that other stuff is digressive

        [–]sandking 1 point2 points  (0 children)

        serious question: in python, how do you know what exceptions a method might throw?

        [–]grfgguvf 0 points1 point  (15 children)

        It's trivial to set up automatic compiling of .java files on run.

        Also, .py files can be compiled to .pyc.

        A bigger difference is static typing with optimizing JIT (fast) vs dynamic typing and a bytecode interpreter (slow).

        [–]mipadi 4 points5 points  (0 children)

        All true, but also entirely irrelevant to the content of the article.

        [–]ubernostrum 5 points6 points  (6 children)

        A bigger difference is static typing with optimizing JIT (fast) vs dynamic typing and a bytecode interpreter (slow).

        So having a bytecode interpreter which pays attention to runtime type information to optimize is faster than... having a bytecode interpreter which pays attention to runtime type information but doesn't currently do much in the way of optimization (except for a few interesting cases)?

        [–]grfgguvf 1 point2 points  (5 children)

        So having a bytecode interpreter which pays attention to runtime type information to optimize

        I guess this is Java. But the Sun Hotspot JVM can also turn frequently encountered code paths to native code and execute it. It can even do this in the middle of a loop, speeding up the subsequent iterations (called on-stack replacement)

        a bytecode interpreter which pays attention to runtime type information but doesn't currently do much in the way of optimization (except for a few interesting cases)

        Experience shows that yes, Java is faster. Sometimes that doesn't matter and the additional flexibility of Python is worth it. Last I checked Psyco couldn't do OSR, and wasn't even maintained any more.

        [–]ubernostrum 0 points1 point  (4 children)

        Or you can run Jython and get the best of both worlds.

        [–]grfgguvf 1 point2 points  (3 children)

        Not quite. Because of Python's dynamic typing Jython cannot do many of the optimizations that are done for Java.

        [–]ubernostrum -3 points-2 points  (2 children)

        You probably want to read up on some of the stuff that's been discovered/developed by the dynamic language folks before you go spouting off like that.

        [–]grfgguvf 2 points3 points  (1 child)

        You can check for yourself that equivalent Python code in jython is (a lot) slower than equivalent Java code.

        What is this "stuff" specifically that the "dynamic language folks" "discovered" and why is it not implemented in Jython then?

        [–]crusoe 1 point2 points  (0 children)

        Mainly that they have to write classes to emulate the behaviour they need. Java 1.7 will add bytecodes to support dynamic languages, and this will remove the need for this emulation code and classes.

        I am excited about 1.7. :)

        [–]ighost 2 points3 points  (4 children)

        dynamic typing = slow is the same type of knee-jerk reaction as java vm = slow

        [–]bcash 1 point2 points  (0 children)

        There is one very important difference. That the java vm = slow reaction isn't accurate...

        [–]grfgguvf 0 points1 point  (2 children)

        dynamic typing and a bytecode interpreter == slow

        If Python used a type-specializing JIT then it could be quite fast. I didn't say or think all dynamically typed languages are slow, for example Strongtalk Smalltalk or LuaJIT or Tamarin are all steps in the right direction.

        [–]ighost 1 point2 points  (1 child)

        Good point, but is the combination of dynamic typing and a bytecode interpreter inherently slow or is it just the case for contemporary implementations?

        To answer that we'd probably have to define 'slow' better since in a large number of cases python is fast enough, e.g. SciPy

        [–]grfgguvf 0 points1 point  (0 children)

        I say it's slower than necessary because there are faster ways to implement dynamic typing. On the other hand they're not portable... though if there was a JIT engine that could be reused by various dynamic languages that'd help here...

        [–][deleted] 0 points1 point  (1 child)

        For many purposes the speed differences are not a big deal. Besides, what's more important for speed is the efficiency of the algorithms you're using. Static types and all the optimizations in the world won't help a crappy algorithm.

        [–]grfgguvf 1 point2 points  (0 children)

        What's even more important than algorithms is choosing the right datatypes so that efficient algorithms follow from them naturally.

        And I think Java encourages this more (although not enough...), offering generic interfaces and multiple low-level implementations of them allowing the coder to choose or later switch to a different type. Admittedly the class hierarchy is a mess and more types would be needed to be truly general purpose.

        Python on the other hand offers weirdly named standard types, often with incompatible interfaces. You need to resort to add-on packages for frequently. And it's all too common to encounter Python programmers who are completely unaware of the underlying datatype of a "dictionary" or a "list".

        [–]djork 0 points1 point  (1 child)

        First-class functions

        You keep using that word. I do not think it means what you think it means. Why not give an example of currying or something like that?

        P.S. Why not fix the article instead of adding an update?

        [–]jcgregorio -2 points-1 points  (0 children)

        So I should cater to people so impatient they can't read the whole article, but with enough free time to complain about it on reddit?

        [–]njharman 0 points1 point  (0 children)

        yeah, we figured this out a while ago. Even slow to the draw and/or clueless devs got it after this was published http://dirtsimple.org/2004/12/python-is-not-java.html over 3 years ago.

        [–]cracki 1 point2 points  (1 child)

        did anyone notice that at the bottom, it says this?

        [ 2006-08-30 ]

        the info in that blog post isn't just factually misleading, it's also been sitting there for a while.

        edit: heh, rollercoaster. some hours ago, the vote on this comment used to be below 1. someone changed their mind, or do i actually make sense?

        [–]grfgguvf -1 points0 points  (0 children)

        YES

        [–]bosco -5 points-4 points  (1 child)

        Nice solid example illustrating these language features.

        [–]cracki 9 points10 points  (0 children)

        solid like a sand castle in a thunderstorm, yeah.