Slashdot Mirror


Testing Frameworks in Python

An anonymous reader writes "This article looks at Python's two standard modules for unit testing: unittest and doctest. These modules expand on the capability of the built-in assert statement, which is used for validation of pre-conditions and post-conditions within functions. The author discusses the best ways to incorporate testing into Python development, weighing the advantages of different styles for different types of projects."

120 comments

  1. GNAA presents.. by Anonymous Coward · · Score: -1, Troll

    GNAA claims responsibility for Momfuck virus.

    By Horatio Brunswick

    New York, NY - GNAA (Gay Nigger Association of America) The GNAA today claimed
    responsibility for the release of the devastating trojan Momfuck.1o1, which has
    caused an estimated 486 billion dollars US in lost productivity and unread
    penis enlargement offers.

    In a drastic escalation of their widely criticized christmas island bombing
    campaign which has killed thousands of defenceless CI natives, the GNAA made
    vague threats last week in a "first post" on slashdot.org, a popular "news for
    trolls" website. In the post (not published here due to profanity and ascii
    nudity) the GNAA threatened the "Destruction of all internet" if net martyr
    http://www.goatse.cx was not immediately reinstated. Initally dismissed by self
    proclaimed security experts Cowboykneel and Linux Toreballs as a childish lark,
    the world was totally unprepared for the storm to come.

    Momfuck.lol exploits three vulnerabilities within Linux's UPnP implementation:
    a remotely exploitable buffer overflow that allows an attacker gain SYSTEM
    level access to any default installation of Linux, a Denial of Service (DoS)
    attack, and a Distributed Denial of Service (DDoS) attack. Within hours of
    release, every backbone in the country had become infected with the virus,
    bringing the internet to a crashing halt. The DHS announced an orange alert
    when the virus spread to even such such remote non-countries as Canada and
    England, becomming a worldwide computer epidemic. The sequence of events that
    followed was devastating. ATMs in several states began routing funds from
    caucasian bank accounts into a GNAA controlled cayman islands account. Traffic
    lights in all major metropolitan areas malfunctioned, displaying pink rather
    than the standard red yellow and green configuration, causing unprecedented
    accidents and traffic delays. Radio stations ceased transmitting their standard
    programming and began a round the clock broadcast of a bootleg of the Village
    People's "YMCA" which was altered to "GNAA." Perhaps most horrifyingly, The FOX
    network's LOL sunday programming lineup was interrupted, and replaced by a
    graphic video of two men having anal sex, backed by the lyrics "Boom I got your
    boyfriend".

    The FBI has fallen under heavy criticism for their failure to respond to the
    threat of the GNAA. The general public seems uwilling to accept their claims
    that the post was below their current threshold. The FBI's top cyber-security
    unit warned consumers and corporations Friday night to take new steps beyond
    those recommended by SCO Corp. to protect against hackers who might try to
    attack major flaws discovered in the newest version of Linux software, or to
    get a life, faggots. FBI Department head John Asscrotch is expected to resign
    in disgrace shortly.

    What follows is a transcript of an actual internet relay chat conversation,
    with two individuals who seem to have been infected by momfuck.lol. It is my
    hope that this will help computer users to recognize and avoid the virus if
    encountered.

    * Now talking in #eurotekken

    * Topic is 'http://www.tekkenzaibatsu.com/forums/showthread.p hp?s=&postid=1527925#post1527925 : everyone give your 0.00c'

    * Set by SirCane on Tue Apr 06 15:57:26

    <l0de> "Mom, I can't sleep would you mind if I get in bed with you?

    <l0de> I have virus!

    <l0de> She was wearing a baby doll semi-see through nightie, and was embarrassed to let me in bed with her.

    <subt-L> haha.. this is a fucking crazy virus..

    <l0de> I can't type this fast!

    <l0de> However she remembered how I had let her sleep with me when she needed to.

    <l0de> Oh my god.

    <l0de> "Sure John, it's a big bed," she said in an uncertain tone.

    <l0d

  2. 1st post by Anonymous Coward · · Score: -1, Offtopic

    1st post

    1. Re:1st post by Anonymous Coward · · Score: -1, Offtopic

      no
      1st post
      1st post (Score:123)
      by Anonymous Coward on Monday April 12, @11:45AM (#8838653)
      1st post1st post
      1s141
      1st post

  3. Traditional testers might be interested... by tcopeland · · Score: 5, Informative

    ...in Bret Pettichord's Scripting for Testers one day class.

    It talks about eliminating some of the tediousness from testing web applications, mainly by using automated solutions like WTR.

    He's also got a list of testing resources that's got some good stuff in there...

    1. Re:Traditional testers might be interested... by Anonymous Coward · · Score: 2, Insightful

      how about "testing for scripters" to avoid all those errors the languages allow to happen?

    2. Re:Traditional testers might be interested... by Anonymous Coward · · Score: 0

      how about "testing for scripters" to avoid all those errors the languages allow to happen?

      Umm ... that's the what the article is about.

  4. c'mon ppl by Anonymous Coward · · Score: -1

    lets stick to the subject at hand, and not ramble on about why python sucks or why it owns, this isn't a general review of python, keep it on topic ffs.

  5. Song of the piracy apologist by Anonymous Coward · · Score: -1, Offtopic

    (1) I don't personally believe in copying CDs illegaly-- but I think we should
    avoid using unkind words like "piracy" to describe those that do -- instead, we
    should describe it as an "infringement", much like a parking infringement.

    (2) I don't believe in the record companies emotively abusing the word "theft",
    but I do believe in emotively abusing words like "information" and "sharing".

    (3) I believe that piracy is driven by "overpriced CDs" even though CDs have
    dropped in price over the years.

    (4) I believe that piracy is driven by overly long copyright duration, even
    though most pirated works are recent releases.

    (5) I believe that illegitimately downloading music is giving the author "free
    advertising". I don't buy any of the music I download, of course -- but lots of
    other people probably do.

    (6) I believe that ripping off the artists is wrong. The record companies
    always rip off the artists. Artists support P2P, except the ones that don't
    (like Metallica), and they don't agree with me, hence they're greedy or their
    opinion doesn't count or something.

    (7) I believe that selling CDs is not a business model, but giving away things
    for free on the internet is.

    (8) I believe that artists should be compensated for their work -- preferably
    by someone else. I mean, they can sell concert tickets (which someone else can
    buy) or sell t-shirts (to someone else) or something. As long as someone else
    subsidises my free ride, I'm coooooool with it.

    (9) I believe in capitalism but only support music business models which
    involve giving away the fruits of ones labor for free.

    (10) I believe that copying someone elses music, and redistributing it to
    my 1,000,000 "best friends" on the internet is sharing. Music is made for
    sharing. It's my right.

    (11) I believe that record companies cracking down on piracy is "greed", but
    a mob demanding free entertainment is not.

    (12) I believe that it's not really "piracy" unless you charge money for it,
    because, receiving money is wrong, but taking a free ride is fine.

    (13) I believe that disallowing copying and redistributing music over Napster
    is the same as humming my favourite song in public. Because when I hum my
    favourite song in public, everyone likes it so much that they run home, get
    out their tape recorders and once they've got a recording of it, they aren't
    interested in hearing the original any more.

    (14) I believe that when illegal behaviour destroys a business, it's "free
    enterprise at work".

    Heaven forbid one actually acquire the skills to be creative! What I find
    amusing is that the pirates seem unable or unwilling to distinguish between
    creative activity and brainless copying.

    Since a lot of the people here are GPL/OSS advocates: the "OSS way" applied to
    this domain is to learn how to play an instrument. Or how to sing or whatever.
    Then get together with a bunch of other people who can also play music, and
    make some noise.

    One of the unfortunate things that has happened to the OSS movement is that a
    lot of the loudmouth advocates for it don't understand what it's really about.
    They view it primarily as a means to get free stuff, and then they turn their
    eyes from the free stuff to the non-free stuff and think to themselves "maybe
    I'm entitled to get that one for free too". The noble ideals of grass roots
    participation in the creative process, and/or supporting it in a principled
    way (namely, boosting the "free foo" movement by preferring free foo to
    nonfree foo), or for that matter, any other form of moderately principled
    codes of ethics, are completely lost on them.

    I think it's a shame that these leeches use OSS, but there's not a whole lot
    that can or should be done about that. But I'd be much happier if at the very
    least, they wouldn't confuse the OSS movement (free as in freedom) with the
    Napster driven movement (free as in "loader")

  6. How is this a troll? by Anonymous Coward · · Score: -1, Offtopic

    How can it be a "troll" if no one (normally) responds to it? Wouldn't that be just "off topic"?

    1. Re:How is this a troll? by Anonymous Coward · · Score: -1, Troll

      No, it would just be a failed troll.

    2. Re:How is this a troll? by Anonymous Coward · · Score: -1, Flamebait

      but the troll didnt fail this time, being they got a first post..

      I think they are just modded as Gay Niggers :)

    3. Re:How is this a troll? by Anonymous Coward · · Score: -1, Troll

      Yeah, it's just because they're black.

    4. Re:How is this a troll? by Anonymous Coward · · Score: -1, Offtopic
    5. Re:How is this a troll? by Anonymous Coward · · Score: -1, Troll

      OMG is that sperm?

  7. Python's dirty little secret by b.foster · · Score: 0, Interesting
    As a long time Python developer I would like to take this opportunity to shed some light into one of the most overlooked design flaws in the language: memory leakage.

    Despite all of Guido Van Sustren's claims to the contrary, Python's garbage collector just doesn't work correctly, allowing the programmer to create a circular reference which never gets resolved. This is a critical impediment to writing mission critical applications in Python, as they will eventually run out of memory and fail.

    Python is an excellent beginner's language, well-suited to replace Visual Basic or possibly even Perl for many tasks. But testing about unit testing before we address a fundamental design flaw such as memory leakage is tantamount to putting the cart before the horse. Python's memory issues need to be fixed before the language can break out of its niche.

    1. Re:Python's dirty little secret by tuffy · · Score: 3, Interesting
      Despite all of Guido Van Sustren's claims to the contrary, Python's garbage collector just doesn't work correctly, allowing the programmer to create a circular reference which never gets resolved.

      Circular references are what weak references are meant to handle. But it'd be nice if the garbage collector would handle those cases automatically.

      --

      Ita erat quando hic adveni.

    2. Re:Python's dirty little secret by jabbadabbadoo · · Score: 1, Flamebait
      Agreed. This isn't well known mostly because Python is used to create short-lived scripts and OS's are fairly good at cleaning up after leaky processes.

      I would never use Python for server applications, but I love it for quick'n'dirty scripts (although I prefer Ruby more and more these days.)

    3. Re:Python's dirty little secret by gaj · · Score: 3, Informative
      Um ... you'd have much more credibility if you at least got his name right.

      It's Guido van Rossum.

      As for your claims about the GC, I was under the impression that current versions of Python have a hybrid GC that cleans up circ-refs. I certainly could be mistaken, though, as I've been exiled to Java-land for the last several years.

    4. Re:Python's dirty little secret by AKAImBatman · · Score: 2, Interesting

      Are you saying that this is an inherent language problem, or simply an implementation problem? i.e. Does the Jython interpreter display this issue, or only the native Python compiler/interpreter?

    5. Re:Python's dirty little secret by Anonymous Coward · · Score: 3, Informative

      "As for your claims about the GC, I was under the impression that current versions of Python have a hybrid GC that cleans up circ-refs."


      According to this you are correct.

      BUT.. please note it also says "You can run gc.collect() to force a collection, but there are pathological cases where objects will never be collected."

      It also mentions the use of weakrefs. :)
    6. Re:Python's dirty little secret by jemfinch · · Score: 5, Insightful

      You're not a "long time Python developer." Far from it. You may qualify as a "python developer from a long time ago," though -- in fact, that seems likely, given that the page you linked was last modified in 1999.

      It's Guido van Rossum, not Guido van Sustren. And Python's garbage collector works fine on cycles, as it has done since 2.0, iirc. The only way you'll get a memory leak with Python these days is by writing a C module that forgets some DECREFs or by writing cyclic objects with __del__ methods, and even in the latter case, you can easily take care of your leaks by breaking the cycle yourself.

      You're uninformed and incorrect; take your troll to the next Perl story, please :)

      Jeremy

    7. Re:Python's dirty little secret by gregfortune · · Score: 3, Insightful

      Despite all of Guido Van Sustren's claims to the contrary, Python's garbage collector just doesn't work correctly, allowing the programmer to create a circular reference which never gets resolved. This is a critical impediment to writing mission critical applications in Python, as they will eventually run out of memory and fail.

      Neither of those references point out he weakref module that allows you to work nicely with circular references.

      Python's memory issues need to be fixed before the language can break out of its niche.

      Yep, it's a niche language. Crawl back under your bridge.

    8. Re:Python's dirty little secret by smallpaul · · Score: 5, Informative

      It is clear you do not know anything about Python. You are not a long-time Python developer but rather a troll. The first hint is that you misspell Guido Van Rossum's name.

      The second hint is that you cite a page from 1999. A Python developer would know that that was before Python had cyclic garbage collection. Here is an article from 2001 that describes how the issue was fixed.

      The third hint is that you point to a page that describes how to avoid creating a memory leak by appending an infinite number of items to a list. Guess what: appending an infinite number of items to a list causes a memory leak in Java, C++, C, assembly, Scheme, sh, Perl and every other programming language in the world. If you ask the computer to store a continually growing list of items, it will do so...in any language.

      If you think that Python can leak memory in circumstances where other languages would not, post an example program and we'll all test it out.

    9. Re:Python's dirty little secret by HiThere · · Score: 1

      I think that you need to specify which version of Python you are referring to. It's been changing quite rapidly.

      In 1.5.x you were definitely correct. Except that it wasn't a secret.

      I don't know about the versions between 1.5 and 2.1. Somewhere in there they changed the garbage collector, but the change to 2.x had to do with a change in sponsorship/licensing, not with a change in technology...so I dont' know just where.

      In 2.1 the new garbage collector was introduced that handles cycles. I don't know how well that first version handled them. The version I'm currently using is 2.4a0.

      Now I didn't notice any problems with the garbage collection in any of these, but the applications that I use and write tend to live but a short time between invocations, so that doesn't prove much. I will say that I haven't encountered this assertion on comp.lang.python in a long time, but again, I must admit that I skip most of the posts. (There's just too many!)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    10. Re:Python's dirty little secret by be-fan · · Score: 2, Insightful

      Guess what: appending an infinite number of items to a list causes a memory leak in Java, C++, C, assembly, Scheme, sh, Perl and every other programming language in the world.
      Properly implemented, Scheme should never leak memory. Even if you try to add an infinite number of items to a collection, you'll get an out-of-memory error before you'd get a leak.

      --
      A deep unwavering belief is a sure sign you're missing something...
    11. Re:Python's dirty little secret by Lulu+of+the+Lotus-Ea · · Score: 4, Informative

      FWIW, I'm the author of the referenced testing article. Though that's not really germane to the following comment.

      b.foster's misguided comment gives a link to a 1999 article about problems in Python with cleaning up circular references. Well, yeah: in 1999, Python 1.5.2 could leak on circular references. It was actually less of a problem in practice than advocates of mark-and-sweep collectors tended to complain about; but it really was a limitation. That was a long time ago.

      Nowadays, Python still uses references counting as its primary collection mechanism. It's a nice system: fast, deterministic, etc. (despite what you might think, refcount *really is* faster than Bohm generational; and is well-tested as such by very smart Python developers). However, the last half-decade of Python versions also perform occassional checks for orphaned objects, and cleans them up too. The "problem" pointed to is of historical interest, at most.

    12. Re:Python's dirty little secret by smallpaul · · Score: 1

      You do not need weak references to work nicely with circular data. Python has a cyclic garbage collector that works the same way that garbgage collectors in Java etc. do. Weak references are for referencing things without keeping them alive. e.g. for caches

    13. Re:Python's dirty little secret by smallpaul · · Score: 3, Informative

      Argh...the garbage collector does handle circular references automatically and has done so for at least two years. Weak references are something totally different and are used e.g. for caches.

    14. Re:Python's dirty little secret by Anonymous Coward · · Score: 3, Funny
      So the article he linked to is a "historical document", not something we should take seriously?

      Sorry bud, I think I've heard that line before.

    15. Re:Python's dirty little secret by Daath · · Score: 1

      I like your python bot, supybot, it's really nice! I'm gonna use it for a project soon and write a DCC chat module for it. Great work :)

      --
      Any technology distinguishable from magic, is insufficiently advanced.
    16. Re:Python's dirty little secret by smallpaul · · Score: 1

      An out-of-memory error is the end result of a long-term leak. You'll get the same out-of-memory error in Java, Python, C (reported as a malloc failure), etc. What do you mean by leak? Physical sims slipping out of the machine and onto the ground?

    17. Re:Python's dirty little secret by smallpaul · · Score: 1

      Please moderators: this post is over-rated. Weak references are NOT the right way to deal with circular references. There is NO NEED to deal with circular references because Python has had NO PROBLEM with them for years.

    18. Re:Python's dirty little secret by slinkp · · Score: 2, Interesting

      I've been running Zope (implemented in python) on production servers for years. The zope process typically has uptime of weeks and downtime is typically only of the scheduled variety. In the past 20 months I've been at my current job, I can count the number of Zope crashes on one hand. OTOH, we also run Java app servers (formerly BEA, now Jboss) and they crash all the time... frequently with out-of-memory errors.

      Snide remarks about "dirty little secrets" notwithstanding, I know which platform I trust to keep running.

    19. Re:Python's dirty little secret by smallpaul · · Score: 1

      It is neither an implementation problem nor a language problem. There has been no such problem in any implementation of Python for years now.

    20. Re:Python's dirty little secret by Anonymous Coward · · Score: 0
      Guess what: appending an infinite number of items to a list causes a memory leak in Java, C++, C, assembly, Scheme, sh, Perl and every other programming language in the world. If you ask the computer to store a continually growing list of items, it will do so...in any language.

      Not if you use lazy evaluation.

    21. Re:Python's dirty little secret by be-fan · · Score: 1

      Leak has a very specific meaning. A memory leak is memory that is no longer referenced by the program, but is not freed within an indefinite period of program runtime. Memory has been leaked when it can be proved that the memory manager cannot collect that memory at any point in the future. Thus, you can have leaks without hitting an out-of-memory error (if leaking is slow enough that you don't fill memory during program execution), and you can have out-of-memory errors without necessarily having leaks (your program references too much memory).

      --
      A deep unwavering belief is a sure sign you're missing something...
    22. Re:Python's dirty little secret by kraut · · Score: 1

      Errr.. by that argument, nobody would ever have been able to write anything useful in C, since that doesn't have any garbage collector at all?

      Circular references, in my experience at least, are a) rare and b) easily avoided if they cause problems.

      --
      no taxation without representation!
    23. Re:Python's dirty little secret by smallpaul · · Score: 1

      Leak has a very specific meaning. A memory leak is memory that is no longer referenced by the program, but is not freed within an indefinite period of program runtime.

      If this is your definition of "leak" then Python cannot leak either. In my mind, if you are running a server application and over days, months or years the process grows for no outwardly observable reason, that application is "leaking".

      I think FOLDOC agrees with me: A leak in a program's dynamic store allocation logic that causes it to fail to reclaim memory in the heap after it has finished using it, eventually causing the program to fail due to lack of memory

    24. Re:Python's dirty little secret by be-fan · · Score: 1

      I never said that Python can leak. Given the GC, I'd suspect it cannot. I said that Scheme couldn't leak.

      Your example about a server process isn't necessarily a leak though. If the app is keeping references to that data (ie: it's not finished using that data), then its not leaking. If it *isn't* keeping references to that data, but it still does not get reclaimed, then it is a leak.

      --
      A deep unwavering belief is a sure sign you're missing something...
    25. Re:Python's dirty little secret by smallpaul · · Score: 1
      Okay, this is my last post in the thread. You are using the term memory leak in a manner different than I do. If we use your definition then Python, Scheme, Java, C#, Modula-3, Eiffel, Sather, Lisp, Dylan and hundreds of other languages do not leak memory. I don't know why you picked Scheme out of the list and remarked on it specially. I also don't know why you didn't look to see the definition of memory leak being used on the page I linked to: l = []; def leak(self, item): l.append(item)

      If Scheme IS immune to this kind of leak then that is news to me. If it ISN'T immune to this kind of leak, then your post is off-topic. If you want to claim that this ISN'T a leak, then you could have said that in the original post rather than bringing Scheme up at all.

    26. Re:Python's dirty little secret by smallpaul · · Score: 1
      BTWE, here is the Scheme program that is equivalent to the Python program in the very original referenced URL:
      (set! L ())
      (define (func) (begin (set! L (cons L () ) )
      (func) ) )
      (func)
      The process grows without bound, just like in every other language...just as in the original URL. Sorry to keep on about it but it annoys me when I am stomping a troll and somebody pops up with a non sequiter that confuses the issue.
    27. Re:Python's dirty little secret by be-fan · · Score: 1

      The example you linked to isn't an example of a leak, it is an example of unbounded space usage. See, the elements in the list are still referenced, so the program isn't "finished using them."

      The only reason I brought up Scheme is because you mentioned it.

      --
      A deep unwavering belief is a sure sign you're missing something...
    28. Re:Python's dirty little secret by gregfortune · · Score: 1

      Thanks for pointing that out. Weak references are not an *incorrect* way of dealing with circular references as their behavior is exactly what one wants for circular references, but I was unaware that the garbage collector handled that automatically. Too bad I can't give you a few those mod points ;o)

  8. Genius by Anonymous Coward · · Score: -1, Offtopic

    That was great and mirrors the way I feel about people who claim that infringment is not theft.

    You sir are a genius.

    Be proud, you are one of the few, the proud, the intellignet, here in /.

    1. Re:Genius by Anonymous Coward · · Score: 0

      Yes, I wish I was part of the "intellignet" around here.... How do I connect to that net, I want to be proud too!!!

  9. Different types of project ? by MosesJones · · Score: 1, Offtopic


    Call me silly here, but that article talks about developer ONLY testing, and doesn't seem to discuss different types of projects at all. This was about basic code testing, and mainly unit-test.

    No UAT, no System Test, no Integration Test... no how test cases should be defined.

    Please go an get a decent, non-language specific book on testing before reading and listening to this article.

    --
    An Eye for an Eye will make the whole world blind - Gandhi
    1. Re:Different types of project ? by kpharmer · · Score: 4, Interesting

      > Please go an get a decent, non-language specific book on testing before reading and listening to this
      > article.

      Sure usability, user acceptance, system, string, and integration testing are all valuable. But why can't developers without any knowledge of these start with built-in unit testing?

      And keep in mind that few books on testing cover the fairly recent phenomenon of test-driven-development (or test-centered-development).

      The use of built-in test harnesses and focus upon developing tests as documentation of requirements is probably the biggest single improvement in testing in twenty years.

      In one fell swoop the debugger is rendered obsolete...

    2. Re:Different types of project ? by tcopeland · · Score: 2, Insightful

      > probably the biggest single improvement
      > in testing in twenty years

      Right on. Being able to make some changes and run a suite of 500+ tests to make sure things still work is a thing of beauty.

      And when a bug slips through, that's just an opportunity to write another test and make sure that bug never happens again. Good stuff.

    3. Re:Different types of project ? by Stultsinator · · Score: 2, Interesting

      I agree that those topics are worthy of deeper discussion, but I think the article stands well on its own. I'm learning Python and I think the unittest section will help greatly while stumbling through the process of building applications.

      The links he provides in the Resources section at the end of the article provide well-rounded background information on testing in general.

    4. Re:Different types of project ? by pavon · · Score: 2, Insightful

      Call me silly here, but that article talks about developer ONLY testing, and doesn't seem to discuss different types of projects at all. This was about basic code testing, and mainly unit-test.

      Yes, this is exacly what this article is about. What is wrong with that?

      No UAT, no System Test, no Integration Test... no how test cases should be defined.

      No it is assumed that anyone programmer worth his salt knows some test methodology, and this usefull article explains tools that make that task easier.

      Please go an get a decent, non-language specific book on testing before reading and listening to this article.

      Yes I agree, if you don't know these things you should learn them. But you act as thought this article is a waste of the electrons it traveled over, while it is actually quite usefull. I program python, learned about test methodology years ago but didn't learn about these tools until today.

      I don't see how you got +5 Insightfull for pointing out that this is article is not the all-inclusive source of testing knowledge. Everything ever written is limited in scope, that doesn't make it less usefull for the purpose it was written.

    5. Re:Different types of project ? by Lulu+of+the+Lotus-Ea · · Score: 4, Insightful

      How is the parent "insightful"?!

      I wrote a 2300 word article for a column on Python! I didn't write a book. Well, actually, I did write a book, but it isn't the above article (and it's not about testing frameworks). It's certainly not a good idea to think my short article is the alpha and omega of testing. But I am confident that my article -does- address a topic that some Python programmers can benefit from. And other installments of _Charming Python_ each address similarly small, but useful, topics.

    6. Re:Different types of project ? by Simon+Lyngshede · · Score: 2, Informative

      It is a very short article about using the unit testing framework for Python, not the definitive guide to testing. Do you even understand how amazingly large a subject software testing is?

      I think that unit testing is an important tool, it allow you to easily continue to do integration test and regression testing, if you know what you're doing.

      I will however agree with you on the "get a book on testing" part. I think it's important that anyone who develop software, understand what is involved in testing.

    7. Re:Different types of project ? by Capsaicin · · Score: 1

      I'm learning Python and I think the unittest section will help greatly while stumbling through the process of building applications.

      I've found that writing tests before writing the code they test requires a deal of self-discipline (ie. I don't do it as often as I should. When I have made this effort however, rather than stumbling through, the unittest module will took me by the hand and led me through.

      Running the test suite while writing really focuses you on a specific part of your code (ie. that part that is failing) which can in turn affect the logic of your program.

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
  10. bull by kpharmer · · Score: 5, Informative

    A few thoughts:

    1. I've never had a problem with memory management in python. Can't say it doesn't exist, just never impacted my production applications.

    2. Implementing great built-in test frameworks doesn't need to wait for memory management improvements. I'm seeing almost immediate pay-offs from this kind of built-in testing.

    3. I'm implementing python as an alternative to java in large applications - with complete success. Easy to learn, easy to maintain, fast enough to handle millions of rows of data a day - what's not to like?

    1. Re:bull by Anonymous Coward · · Score: -1, Flamebait

      what's not to like?

      Python uses whitespace as a delimiter. It's true that Python is OK as a beginner language, but people should try to graduate to Perl or Ruby as soon as possible when writing real-world applications.

    2. Re:bull by LarryRiedel · · Score: 0
      I'm implementing python as an alternative to java in large applications - with complete success. Easy to learn, easy to maintain, fast enough to handle millions of rows of data a day - what's not to like?

      For large application maintainability, I do not like that I cannot expect to look at a Python function definition and see what are the expected types of the arguments.

      Larry

    3. Re: bull by LarryRiedel · · Score: 1
      I do not like that I cannot expect to look at a Python function definition and see what are the expected types of the arguments.
      If you could, ie if the functions did expect arguments to be of certain types, you couldn't use polymorphy in python, could you?

      Yes, with the type of the formal parameter an ancestor of the class of the actual parameter.

      Probably the answer is to rely on unit testing instead of static typing for large application maintainability in python.

      Testing is useful after changes have been made. Knowing the expected argument types for a function is useful in determining what changes to make.

      Larry

  11. Slashdot's dirty little secret by Anonymous Coward · · Score: -1, Flamebait

    Python is an excellent beginner's language

    Which is why everyone on Slashdot just loves it.

    1. Re:Slashdot's dirty little secret by Anonymous Coward · · Score: -1, Troll

      Visual Basic + 311t = Python.

  12. All in all.... by Anonymous Coward · · Score: -1, Offtopic

    You got some really fucking boring topics today!!
    Jeez, talk about slow news day.....NEXT!

  13. true programmers... by Anonymous Coward · · Score: -1, Troll

    True programmers never test their code, that is for people who are unsure of themselves and who should not be trusted

    1. Re:true programmers... by JohnGrahamCumming · · Score: 5, Insightful

      True programmers never test their code, that is for people who are unsure of themselves and who should not be trusted

      Despite that fact that you are clearly trolling I think there's a valid point in what you are saying: there are programmers who think that they are too good to write unit or system tests for their code. And that's a real danger.

      The adage "a line of untested code is a line of broken code" is so often true that I still find it scary when examining untested code. It's just amazing how much of a difference the discipline of writing automatic unit tests makes in improving code.

      If you think you are too good to write tests, then perhaps you are too good for the software industry?

      John.

    2. Re:true programmers... by Anonymous Coward · · Score: 0

      yo man, I was just joking. Personally, I test all my code and very thoroughly so don't worry about me. And i do not think I am too good, actually I do not think I'm good at all. So again, I was just joking and maybe I should have put a ":)" at the end to drive that home but meh.

    3. Re:true programmers... by Abcd1234 · · Score: 2, Insightful

      You know, the funny thing about this is that a good coder must want to see their code actually run, right? After all, everyone wants immediate gratification. And the beauty of unit tests is it provides just that... you can actually run your code in a controlled environment easily without the need to start up an entire application/framework/etc. This is especially true of large and/or distributed applications where there's a great deal of overhead in running a full system test.

      Moreover, unit tests make the test-develop cycle a *lot* shorter, especially on large projects, since you can easily run your code. Thus, you're wasting less time testing and more time coding... sounds like a great deal to me!

      So, in my mind, any coder that doesn't feel like writing tests isn't, in fact, a particularly good coder. Or, perhaps, they're doing their job for all the wrong reasons. I code because I want to see the fruits of my labour, and unit tests are a great way to quickly and easily see the results of my work.

    4. Re:true programmers... by Anonymous Coward · · Score: 0

      If you think you are too good to write tests, then perhaps you are too good for the software industry?

      But just about ideal for being a CEO or a politician:

      Programmer: If it compiles, it works!
      CEO: If the share price goes up before end of quarter, it works!
      Politician: If it get's my face on TV, it works!

  14. Testing.. by MosesJones · · Score: 4, Informative


    I hate to break it to the hack and slashdot crowd, but Testing is actually a whole career in itself, and the application of different testing processes and methods to different projects is a critical part of ensuring projects succeed.

    This article covers NOTHING about the different types of testing on a project, or indeed how test cases should even be constructed. Its basically about some UnitTesting elements that could be done by testing.

    I know its unpopular here on Slashdot to claim that there are more developers working on big projects than people hacking in Python. Buts its articles like these that underline the difference between professional software development and hacking.

    This is about hacking.

    --
    An Eye for an Eye will make the whole world blind - Gandhi
    1. Re:Testing.. by Spoing · · Score: 3, Interesting
      1. I hate to break it to the hack and slashdot crowd, but Testing is actually a whole career in itself, and the application of different testing processes and methods to different projects is a critical part of ensuring projects succeed.

      Agreed. I can impress someone with my knowledge and professionalism, but when they ask what languages I can program in and I state "I'm not a developer", they just don't get it. That I can whip a program up is one thing...that I know that I'm not the person to do that seems to lead to puzzlement.

      These days, testing (and CM) is so far off the radar for most folks that it is no longer considered an issue. Yet, developers are constantly required to know all details of the specs and to deliver code that does not immediately fall apart. Some can, but very few can do it rapidly.

      The extra burden of detailed testing -- work that the developers are usually not suited for or have time for anyway -- does not make for a productive environment. Limited testing is OK though full testing by development is a distraction -- both VV&T and development groups know it.

      That said, initial unit tests of the core services can be the responsibility of the development group, though it should never fall to the same person writing the code being tested. The unit test framework will be incomplete and faulty since the developer does not have the proper distance from the code they are testing.

      A skilled VV&T developer can do the job much better, though time for that person to write code to test the developer's work is usually not allocated in the schedule...even if such a person is hired at all.

      (Case in point: I was hired last year to automate testing and test 2 applications...10 months later, and here I am having tested about 20 applications and have not written any automated test sripts. Yes, I warned them that it takes a specific type of environment to support automated testing, one that can allow substantial amounts of time and effort to creating and maintaing those scripts, and I didn't see that environment. Yes, they understood and said 'do it anyway'. Yep, that worked.)

      --
      A firewall can not protect you from yourself. Turn off what you do not need. Do not use the firewall to do your work.
    2. Re:Testing.. by SoSueMe · · Score: 1

      I see nowhere a claim that this article is meant to be a "be all and end all" statement on Software Testing.

      The posting and the article it links to are just what they claim to be.

      Software Testing is a whole different discipline, in its entirety, from software development. This does not negate the fact that unit and integration testing should first be performed by the developer, since they know their expected results.
      This article is "a good start" for information on Unit Testing Frameworks for Python.

      As a ST/QA person, I tend to try to absorb as much information on the discipline as I can ane learn from it.
      I try to not treat every scrap of info as "missing the mark" when it doesn't conform to my views on what Software Testing is or isn't.

    3. Re:Testing.. by SurfTheWorld · · Score: 2, Interesting

      What is it about testers and their negative reactions to developers writing tests? Is it out of fear of job security? I don't understand why so many testers frown upon or discard tests written by developers as worthless, or second rate, to the tests that they have written. Indeed, many times what accompanies test dismissal is the comment of "Developers don't know how to test software." Nevermind the lack of supporting details to back up this broad generalization.

      What to me is so strikingly insane is that at the most primitive levels, testers write tests. What kinds of tests they write vary in size, scope and purpose. Developers, through unit tests, are technically doing part of the the tester's job. They produce tests! Sure, they are unit tests, but they are still valuable from the standpoint of software verification. Even if a tester walks away from them with simply a better understanding of how the software is put together, does that not make them valuable or important?

      Too many times do testers toss away unit tests as worthless (or in Moses' case "hackish") simply because they were not written by a tester. Tell me what qualifications you must have to be a tester and to write tests. What are your criteria for considering a test valid or valuable? Now tell me how I can run the litmus test against my test to see if it passes what you consider to be the qualifications for inclusion into a suite of tests.

      Were the best interests of the project (not the individual) ranked at the top of the importance list, I would expect testers to gleefully accept developer unit tests. Not only do they show accuracy in the software, but they more importantly demonstrate a developer's willingness to test and prove functionality. "Here's my code, it implements requirements X, Y, and Z, and here are the unit tests that demonstrate the functionality." Given that, a tester needs to tie together a high level interaction test or execute the regression tests. But the developer has gone a long way to help out the tester, and more times than not the tester pushes back with some assinine comment like "developers don't know how to write tests."

      Successful software teams are not like the 4x2 tetris block, where the design team hands off UML to the developers to implement, who then hand off the code in an assembled version to the testers to verify. Successful software teams are a coagulation of the + tetris blocks where developers perform some requirements analysis and testing while at the same time coding. Testers pick up some system administration. And system administrators do some testing and even development. This type of cross-pollinated structure on a team keeps code velocity high, job competition to a minimum, and leads to higher overall satisfaction (generally speaking, of course ;-)).

      Your view of unit tests as hacks without the proper overall test plan shows your inflexibility to cohabitate with developers willing to test on your project. Archaeic views like this usually lead to unsuccessful projects. Take a moment to look back over your resume and reflect on the various software projects you've worked on. Ask yourself what developement environment existed, and if the project was successful. My guess is you'll notice a pattern.

      --
      Do it for da shorties
    4. Re:Testing.. by _|()|\| · · Score: 1
      What is it about testers and their negative reactions to developers writing tests? ... What are your criteria for considering a test valid or valuable? ... I would expect testers to gleefully accept developer unit tests.

      Hard-earned experience shows that it's risky to depend on developers to test their own code. It's kind of like playing a chess game with yourself. That said, I disagree with MosesJones's claim that unit testing is just hacking. It's an excellent part of a balanced breakfast. Ironically, if testers do their job too well, developers begin to treat them as a safety net, like the next step after compiling and linking. I spend too much of my time in this mode, so that there is little time or incentive to take it to the next level; in effect, I write the unit tests that the developer should have written.

      The value of a particular test depends on the maturity of both the testing and development process. If I'm hurting for coverage, I may well incorporate a developer's unit test vebatim, especially if experience shows the feature under test to be fragile. Ideally, however, an automated regression test has some stricter criteria than "it's already written":

      Clarity. A test should pass or fail. "Inspect output for anomalous values" is okay for a developer's tool box, but doesn't cut it for an automated regression test.

      Granularity. Related to clarity is an appropriate level of granularity. I can't necessarily allocate five hours of a nightly run to a detailed set of tests for one API function. On the other hand, it's difficult to diagnose a failure in an omnibus test that fails if any of a hundred different assertions fails, even it runs in a fraction of the time.

      Reliability. I have a limited amount of time to write tests, run them, and analyse their results. A test with too many spurious failures wastes my time during analysis. These failures may occur because of unstated dependencies (e.g., must be run in a certain order), race conditions, etc.

      Generality. If the feature under test is applicable on several platforms and will be relevant to future versions of the product, then I want a general, portable test. This portability may be best achieved by working within a framework that may not be appropriate for use in a unit test.

      Testing involves many of the same complexities as development of the software itself, with a less tangible deliverable and a (usually much) smaller budget.
  15. Languages form an ecosystem by Anonymous Coward · · Score: 4, Insightful

    Judging from some previous comments, I see that some fail to grasp that modern computer languages form a large ecosystem. Each language has its purpose, and one can not easily dismiss a language as dead, just because some other, ostensibly more powerful language has appeared on the block. Monkeys, whales, cockroaches, ants, and plants continue to coexist with humans.

    When I want to solve a program I choose the language I will use, taking into account the abstractions and facilities it offers. * I chose Java when I wanted to leverage the javadoc applets (doclets) to convert a Java-like syntax into UML with my UMLgraph tool .
    * I chose C++ to implement the CScout refactoring browser for C programs. In this case I wanted rich and efficient data structures, with minimal speed and space overhead. CScout datasets can require more than 1GB of RAM, and runtimes can span more than a day; any overhead of object boxing, garbage collection, or bytecode interpretation would in this case be unacceptable.
    * I chose Perl to o Convert digital photographs and GPS track logs into annotated photo albums and trip maps
    o Examine the availability of 4500 URLs cited in computer science research papers.
    o To create the diagrams and the index for my book Code Reading: The Open Source Perspective.
    In all the above cases, I needed a typeless language with a rich set of operators, functions, and libraries to minimize the time I would spend to convert my ideas into code. Ruby and Python would have served me equally well.
    * Finally, I chose C to write
    o the *BSD sed implementation.
    o The socketpipe zero-overhead network pipe tool.
    o The Outwit Windows-Unix shell integration tool suite.
    o The fileprune backup file prune utility.
    o A device driver for interfacing with my home's alarm system.
    In these cases, I did not require any fancy data structures or framework APIs, but I did want tight integration with the underlying system, absolute efficiency, and minimum-fuss portability. For code that will be executed billions of times on tens of thousands of systems, spending some additional effort to provide the absolute efficiency and reasonable portability that are possible in C, is a proposition one should take into account.

    1. Re:Languages form an ecosystem by Anonymous Coward · · Score: 0

      In summation, you used Perl when you needed to manipulate strings or when a preexisting Perl module did exactly what you needed, Java for reasons not relating to the language, C++ when C would've been a better choice, and C when you needed to do something important.

      It's true that languages exist for different purposes, but C, Perl, and shell scripting cover 100% of the gamut well already.

    2. Re:Languages form an ecosystem by Anonymous Coward · · Score: 0
      In all the above cases, I needed a typeless language with a rich set of operators, functions, and libraries to minimize the time I would spend to convert my ideas into code. Ruby and Python would have served me equally well

      But Ruby and Python are not typeless; they have strong dynamic typing.

  16. Slashdot lies, opinions, and half-truths by Anonymous Coward · · Score: -1

    If you agree with any of this, feel free to repost it endlessly!

    * If "Linux" just refers to the kernel and not the operating system, how can "FreeBSD" refer to the operating system (userland tools, standard libraries, etc.) and not just the kernel? Face it, "GNU/Linux" looks and sounds ridiculous.

    * If you expect companies to follow the copyright of the GPL, you should support the RIAA going after infringers of its copyright. If not, you're a hypocrite.

    * There is absolutely nothing wrong with a company being upset that its product is being pirated freely over online networks. Try getting a real job sometime and see what it feels like when your work is everywhere, and you start worrying that your days are numbered. Does John Carmack want you to "sample" his new game via the "free advertising" happening on eMule?

    * OSDN-owned Slashdot thinks its niche opinion represents the majority of the world. This is a result of people visiting every day and buying into the groupthink. Nobody outside of Slashdot knows or cares about "Linux," "RIAA", "M$," or anything else Slashdotters think is such a huge issue in today's society. Go to a mall or coffee shop sometime and see what people actually talk about.

    * Speaking of OSDN--it's a Linux company...that owns a "tech news" site...that posts news stories negative toward competitors like Microsoft. If a Windows company or even Microsoft itself owned a "tech news" site and posted anti-Linux articles all the time, everyone would be up in arms. But with OSDN, it's a-okay.

    * Slashbots think people don't like the music coming out these days, which is the cause of the piracy. Never mind that if people didn't like the music they wouldn't be pirating it, most Slashbots--again, this goes back to the niche opinion thing--don't realize that most people these days love the music coming out and want to hear all of it. Probing around, you discover that Slashdot is made up of nerds and fogies who listen to things like The Who and Blind Guardian and techno--not what mainstream society enjoys.

    * Any company ending in "AA" is evil. Especially if it doesn't want you distributing its works without paying for it. Somehow, this mindset is supposed to make sense.

    * The inevitable result of all this is a world in which nothing can be profitable because people simply pirate free copies. Is that really what Slashbots want? OSS and free-ness in general reminds me of the hippie era of the 60s--idealistic socialism that only exists because of the surrounding capitalism around it that provides the environment for it to exist. We all know what happened to that idea.

    * Slashdot editors are abusive. We all remember The Post. It's amusing the editors never mention the issue. The worst editor is michael, who will mod you down, insult you for your post count, and post unprofessional color commentary along with the article. This is the same bizarre person who cybersquatted Censorware for years--even as Slashdot posted articles negative toward cybersquatting! Michael played it off like he was some sort of stalking victim, which made it all even more bizarre.

    * The moderation system is broken. If you mod someone as "Overrated," you can't be metamodded. People abuse this all the time to gang up and knock you down into oblivion.

    * Somehow, user-ran executables are always a "New Microsoft Hole" (actual article headline). Meanwhile, LinuxSecurity posts weekly security advisories for all the Linux distributions. You never, ever, EVER see any of these mentioned on Slashdot--bizarre things like arbitrary code execution via MPlayer.

    * Microsoft is supposed to be some sort of non-innovative rip-off artist. Meanwhile, the same people posting those comments do it through KDE with taskbars, sidepanels, start menus, similar print dialogs, and an integrated web/filesystem browser. Slashdotters--ripping people off then criticizing those who came up with the ideas

  17. You, sir, are just trolling. by James+A.+M.+Joyce · · Score: 0

    You obviously made up the developer's name "Guido Van WHAT???" and your claims about leakage are complete crap. We've had up to a dozen coders working on a single project at my organization, and we've hit 20KLOC without a single memory leaking problem: that tends to be reserved for our C apps. I think you're just a copy-'n'-paste troll who's trying to spread FUD about Python. Yeah, yeah, IHBT, whatever.

    1. Re:You, sir, are just trolling. by Anonymous Coward · · Score: 0

      We've had up to a dozen coders working on a single project at my organization, and we've hit 20KLOC without a single memory leaking problem: that tends to be reserved for our C apps.

      Know what this says to anyone who reads it? It says, "we're a bunch of bad coders who need a language to make up for our suckiness." Languages like Python and OCaml exist because people are too stupid to program good code in C and readable code in Perl.

  18. Python and Perl... by goldspider · · Score: -1, Flamebait

    ...are for rank amateurs, and there's no two ways about it! They are inelegant and clumsy languages that are only used by unsophisticated, lazy, self-titled "developers" who don't understand Unix as well as they would have us or their employers believe.

    There is nothing, and i do mean NOTHING that a real Unix professional can do with Python or Perl that he or she can't do with awk, sed, and grep.

    Any argument to the contrary would not only expose your own inadequacies as a Unix programmer, but would also perpetuate the myth that, as Microsoft also argues, bloated, "feature-rich" languages are ideal for business application. I submit that such an argument would be itself an attack on the very concept of open source software.

    --
    "Ask not what your country can do for you." --John F. Kennedy
    1. Re:Python and Perl... by Anonymous Coward · · Score: 0

      Can you write a customized HTTP server with sed,awk and grep?

    2. Re:Python and Perl... by Mateito · · Score: 1

      > There is nothing, and i do mean NOTHING that a real Unix professional can do with Python or Perl
      > that he or she can't do with awk, sed, and grep.

      And there is nothing a that a real Unix professional can do with awk, sed and grep that cant be done with emacs.

      But then, there is nothing that cant be done with emacs.

    3. Re:Python and Perl... by Anonymous Coward · · Score: 0

      "...There is nothing, and i do mean NOTHING [,] that a real Unix professional can do with Python or Perl that he or she can't do with awk, sed, and grep..."

      Humm, that doesn't sound too practical and portable for many cases. I take it you would also need bash or something to go with those tools. And heaven forbid if someone else has to maintain the code after you on a large-scale project.

    4. Re:Python and Perl... by ArghBlarg · · Score: 1

      Actually, one almost certainly *could* write a "customized HTTP server" with awk (and you wouldn't even need sed and grep). It's a Turing-complete langauge.

      Just thought you might want to know.

      --
      ERROR 144 - REBOOT ?
    5. Re:Python and Perl... by Anonymous Coward · · Score: 0

      Just because a language is Turing-complete doesn't mean it can do everything, just that it's capable of computing everything. I imagine an awk program might have some difficulty acquiring a socket to a network interface; establishing connections to hardware that communicates using electrical signals isn't exactly a computational problem in the usual sense.

    6. Re:Python and Perl... by patthoyts · · Score: 1
      Like this one? http://awk.geht.net:81/README.html
      AWKhttpd - HTTPD written in AWK This is another "fun" HTTPD and it's written in the unix tool language AWK. This is (still) an Alpha prerelease.

      There are httpd's written in pretty much every language -- although I don't think BrainF*ck has been used yet. And Malbolge certainly hasn't.

  19. Gentoo by bonch · · Score: 2, Interesting

    For using a niche language, Portage sure seems pretty popular.

  20. Jython for unit testing by Avumede · · Score: 4, Interesting

    I use Jython regularly for unit testing Java. The expressivness of jython is great for writing shorter unit tests, and the lack of compilation makes the whole write-test-debug cycle short. And, dare I say, it's just more fun to code in jython than Java.

  21. programming languages... by Anonymous Coward · · Score: 0
    ...are for pussies

    dip switches are the only way to program

    1. Re:programming languages... by Anonymous Coward · · Score: 0

      dip switches? HAH! Jumper cables I say, jumper cables.

    2. Re:programming languages... by Anonymous Coward · · Score: 0

      well I'm gunna dig the copperout of the ground, smelt it myself and beat the circuts into shape with a ballpen hammer!

    3. Re:programming languages... by UserGoogol · · Score: 1

      Copper? What a wuss. I use highly elaborate complex fusion reactions to make copper out of Hydrogen Gas. Of course, its hard to find Hydrogen gas these days, so you gotta first perform electrolysis on water. But of course, I don't use none of that fancy pants store-bought electricity. No, I make all my electricity by cranking a small generator which I made a while ago.

      --
      "Never attribute to malice that which can be adequately explained by stupidity." -- Hanlon's Razor
  22. Why Python? by sucati · · Score: 1, Interesting

    Can someone help me understand why I would want to use Python as opposed to Java? I've read several articles touting how concise Python is e.g. for what takes 20 lines in Java, can be done in 3 lines in Python. This argument just doesn't hold water. Am I to believe that us coders are that slow at typing? And we don't have modern IDEs that handle source code generation? And most importantly the bulk of development time should be spent in design and problem solving, not typing, right? We should also keep in mind the reality that we as programmers make mistakes and typing a few extra characters to improve code readability/maintainability may not be at that bad of an idea.

    1. Re:Why Python? by Anonymous Coward · · Score: 0

      Use whatever language you want. That's why there are choices.

    2. Re:Why Python? by leshert · · Score: 3, Insightful
      A good point. The idea of reducing the number of lines of code isn't just to reduce the amount of typing--it's mostly to reduce the amount of code you have to _read_ to understand what's going on.

      For example, it's easier to see what's going on in:

      for line in file("/var/log/messages"):
      processLine(line)

      than in the equivalent C or Java code. Also, terseness isn't the ultimate goal--I could make this more terse (and less readable or efficient) by saying:

      [processLine(line) for line in file("/var/log/messages")]

      The biggest benefit of Python over Java, as far as I'm concerned, is that code written in Python looks like what it does--that's the source of the "Python is executable pseudocode" meme you often hear from Python fanboys. The lack of a compile step and the dynamic typing help, but they're secondary to me.

    3. Re:Why Python? by dubious9 · · Score: 3, Informative

      First off, I had mod points and I feel bad about not modding you up, and you don't deserve a 0:offtopic score.But I though a responce would be better.

      Can someone help me understand why I would want to use Python as opposed to Java?

      Python is not just about brevity, but I think you underestimate writing less lines of code. Take the fact that if you are writing twice as much code, you're probably writing twice as many bugs. Also a consise 50K LOC program is much easier to get around in than a 200K program.

      But anyway, Python is an interpreted, interactive, object-oriented programming language., where as Java is only the last of those three. Python also has dynamic documentation, meaning that the documentation string can be inspected at run-time, without the need to maintain a separate doc tree, ie Javadoc.

      Classes are dynamic ie. you can change their behavior at runtime. All python objects can be marshalled or serialized, while in Java you have to define the interface, and account for anything that you use that can't be serialized.

      There are also thing which I am indifferent about like tabbed blocks, and some things which I don't like, like not having enough compile time type checking. IMHO you should always define the type of a function parameter, it makes learning the API faster.

      In general, Python is great for script-strength stuff, ie. in situations where you would use perl. I can see it getting unwieldly as it got bigger but it generally scales much better then perl. Java tends to be too complex and too restrictive. In short there are many situations where you would choose one over the other.

      --
      Why, o why must the sky fall when I've learned to fly?
    4. Re:Why Python? by prestidigital · · Score: 1

      I'm not a Python person, but...I think the issue of 20 lines versus 3 has more to do with how efficient the code is, especially once it is translated into assembly. I think the basic question you ask is a good one, but your reasons for asking seem a little off the mark. Perhaps I am misunderstanding your point about lines of code? It doesn't seem to me that the amount of typing involved has anything to do with the Java vs. Python debate.

    5. Re:Why Python? by Daath · · Score: 2, Informative

      Try reading ESR's Why Python?, also check out the Quotes on Python from python.org :)
      It's a beautiful language, I'm sorry I can't code in it more...

      --
      Any technology distinguishable from magic, is insufficiently advanced.
    6. Re:Why Python? by CrankyFool · · Score: 1
      ITYM:

      for line in file("/var/log/messages"):

      processLine(line)
    7. Re:Why Python? by leshert · · Score: 1

      Correct. Slashdot's tag ate the opening indent on the second line, and using blockquote made it ugly.

      Anyway, I figured anyone who read it would either have enough Java and Python experience to parse it, or too clueless to catch it. :-)

    8. Re:Why Python? by Incessant_Ranting · · Score: 1

      In general, Python is great for script-strength stuff, ie. in situations where you would use perl. I can see it getting unwieldly as it got bigger but it generally scales much better then perl. Java tends to be too complex and too restrictive. In short there are many situations where you would choose one over the other.

      Python actually scales very well. I feel most people tend to think that it doesn't thanks to its "interpreted language" label. While the label is correct, the argument that it doesn't scale is just plain false (just look at some major apps using it or just plain written in it to see that it doesn't).

      But the interesting point to be made from this is that I would like to know what language truly scales *that* well? Immense apps are written in all the time C and we all know how much of a pain it can be to prevent namespace collisions and all of C's other inherent issues. C++ helps with some of this, but then the language's complexities can get in the way. Java is no better off. I would argue that Python scales as well as Java, C, or any other major language; it scales, but with its own set of issues for large apps.

      As dubious9 said, " there are many situations where you would choose one over the other", although I manage to always choose Python. =)

      like not having enough compile time type checking

      Guido plans to have **optional** type checking added to the language at some point. It's just going to take someone to come up with a good PEP (Python Enhancement Proposal) with a really good implementation to get it in.

    9. Re:Why Python? by Capsaicin · · Score: 1

      We should also keep in mind the reality that we as programmers make mistakes and typing a few extra characters to improve code readability/maintainability may not be at that bad of an idea.

      One of Python's great virtues is its readibility/maintainability. Python is not a terse language, if your really want to minimise line count (and decrease readibility) you'd do much better with Perl (which is not to say that you cannot write readible Perl). In fact part of Python culture is the eschew the one-liner.

      The reason it takes less lines of code to get something done in Python as opposed to Java, in my experience, is that you don't have to spend so much time wrestling with the compile-time type system of Java (Python is run-time typed). When I write^H^H^Hote Java I had to cast objects continuously. For instance to collect a bunch of ints into a vector, and then pull them out again, I'd have to cast the ints into Integers, stick them in the Vector, when I want them again out come Objects that have to be cast to Integers etc etc. Python (at least since 2.2) is more object oriented. There are not non-object primitives, ints are already objects (meaning btw that you can subclass them), and the basic list in Python is a vector. So you just push ints into a list and pop them out again, no drama, no casting, and consequently shorter and more readible code.

      Another benefit of run-time typing is that true polymorphism of interface (rather than of implementation) a la Smalltalk, is possible. That is to say, where Java will ask an object it's racial background (why type are you?) before operating on it, Python will just ask the object what it can do. Consequently the try-except (try-catch) mechanism adopts a central role in the logic of Python programs.

      Now people often fear that run-time typing will result in more and more difficult to locate errors. I remain to be convinced of this. In any case, the kind of unit testing discussed in this article is, imho, a far more effective way of locating/preventing errors, than relying on a type system.

      Can someone help me understand why I would want to use Python as opposed to Java?

      Maybe you wouldn't want to. Trying the language out would probably be the best way of answering your question. Perhaps you are so comfortable with Java, that you would find it difficult to think 'pythonically' about the problem, and you would hate Python? Lucky you! For myself, when I try to write in Java nowadays, my nose starts to bleed ;)

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
    10. Re:Why Python? by dubious9 · · Score: 1

      Well, the only reason I didn't think it wouldn't scale "well" (in comparision to Java) was that it didn't have static type checking which makes it harder to read APIs. However, I have seen less type error in Python than other languages with no static type checking.

      Also, my python programming isn't quite yet "pythonic" so my concerns are likely unjustified, and it does remain on my short list of implementation languages.

      --
      Why, o why must the sky fall when I've learned to fly?
    11. Re:Why Python? by whereiswaldo · · Score: 1

      I'm not a Python person, but...I think the issue of 20 lines versus 3 has more to do with how efficient the code is

      Less lines of code != more efficient

      It boils down to what those lines of code are translated into. You can just as easily write a single line program which makes a library function call containing 50 machine instructions as you can write a 50 line assembly language program which gets converted to 50 machine instructions. Lines of code is not a good indicator of efficiency - not by a longshot.

  23. YUO FAIL IT by Anonymous Coward · · Score: -1, Troll
  24. Unit tests are just one aspect of testing by DeadVulcan · · Score: 4, Insightful

    What you're saying puzzles me. You're absolutely right that this article is not about testing as a whole. The title should have been "Unit Testing Frameworks in Python."

    But your statement that "this is about hacking" and not professional software development puzzles me.

    I believe unit tests are a very legitimate piece of testing - a kind of first-line defence. They're intended to test individual software modules for their low-level behaviour. Typically, a developer would be expected to run them before submitting any change or bugfix, as a kind of "smoke test" to make sure things are okay. Certainly, some organizations might make the mistake of thinking that this kind of testing is all that's required - which is dreadfully wrong - but I don't think there's anything hackish about it.

    In a large organization, the testing team might not consider it testing because unit tests are necessarily maintained and performed by the developers only.

    But I would argue the exact opposite with regards to underlining the difference between professional software development and hacking. If you don't have unit tests, I would say that what you're doing is closer to hacking.

    --
    Accountability on the heads of the powerful.
    Power in the hands of the accountable.
  25. merit by Doc+Ruby · · Score: 0

    How does his braino reference to the poisonous Greta Van Sustern in any way detract from the merits of his argument about the language? This isn't a celebrity deathmatch between tcopeland and van Rossum. Is your complaint the tip of the sharkfin, as a new class of "strawman ad hominem" inversted criticism surfaces on Slashdot? Debaters play the ball, not the man.

    --

    --
    make install -not war

    1. Re:merit by gabec · · Score: 1
      Though I'm convinced you're simply trolling, I thought I'd point out that the reference to the "van Stustern" as well as his very out-dated knowledge of Python (he references a problem solved 2 years ago at least) implies he knows nothing of Python and contrary to the authoritative tone he used when creating his post, he knows nothing of which he speaks.

      Would you not expect ridicule if you said that Bill Gables was a fool because his OS, Windows 3.11, was full of security holes that hadn't been dealt with?

    2. Re:merit by Doc+Ruby · · Score: 1

      If you pointed your criticism at my obsolete version of Windows, pointing out the security holes don't exist, your comment would be worth reading. If you just said I was a fool, or said I was a fool because I referred to an obsolete version, without backing it up with a reference to the fixed status of the new one, your comment wouldn't be worth reading. That's the difference between a worthwhile, though rude, correction, and a worthless flame.

      BTW, a troll is criticized because it is designed merely to elicit responses, which is usually irrelevant: isn't all of Slashdot a troll? But a troll is bad when it has no informational content. My original post, although you might disagree with it, is cogent and includes information as facts as well as analysis.

      Criticism of the information in these posts is worthwhile. Criticism of the personality or "intent" is irrelevant.

      --

      --
      make install -not war

  26. top of the foodchain by Doc+Ruby · · Score: 2, Insightful

    Unfortunately you had to use HTML to render an outline, when you'd have used PostScript if you had a choice. The reality of programming is the necessity of working with other people, including programmers thinking in the paradigm of the moment (think 1990s Perl), graphic designers/artists with Flash on the brain, marketers with buzzword colored glasses, legacy systems, and customers seeing their businesses modeled explicitly for the first time in any terms. I'd prefer compiling everyone's flowcharts to C++/IDL/VHDL, but that environment is at least 5 years away. Meanwhile, all we have it this year's hammer, and everything looks like a nail.

    --

    --
    make install -not war

  27. sufficiency by Doc+Ruby · · Score: 1

    Technology is for medieval primates. Real results need nothing more than a verbal, somatic and material component, in a TV studio.

    "Any technology, sufficiently advanced, is indistinguishable from a rigged demo." - Luke McCormick

    --

    --
    make install -not war

  28. Integrating the two approaches by teknico · · Score: 2, Informative

    Here is a presentation, with PDF article, about integrating the two approaches, straight from recent PyCon:

    Literate Testing: Automated Testing with doctest

  29. What did you expect? by Anonymous Coward · · Score: 0

    >>I hate to break it to the hack and slashdot crowd, but Testing is actually a whole career in itself,

    You were looking for mention of this in an article about Python unit-testing?

    I am sure the programmers that read this page respect their testers.

    Knock that chip off your shoulder.

    1. Re:What did you expect? by Anonymous Coward · · Score: 0

      Just like in development, testing has both its zealots and evangelists.

  30. QMTest, a testing framework in python by Anonymous Coward · · Score: 0

    The title of the article makes me think of QMTest, an actual testing framework written in Python.

  31. Randomized unit testing by Anonymous Coward · · Score: 0

    I've written an extension of unittest that adds random unit testing in the style of Haskell's QuickCheck: pickcheck.

  32. Map by Anonymous Coward · · Score: 0

    how about just :
    map(processLine, file("/var/log/messages"))
    or if processLine is set to return 1 for error and 0 for okey-dokey :
    l = filter(processLine, file("/var/log/messages"))

  33. BitTorrent, too by Anonymous Coward · · Score: 0

    BitTorrent is also written in Python.

  34. ep!! by Anonymous Coward · · Score: -1, Troll
  35. Interest by Anonymous Coward · · Score: 0

    You can see the slashdot crowd's level of interest by just comparing the number of comments to those on other stories.

    This kind of rubbish is only of interest to stupid academics who like drawing boxes inside other boxes and call it research. Then these peons make me sit stupid exams on ir where I have to draw the damn boxes again, while yapping about all this object orientated rubbish.

  36. MOD PARENT AS FUNNY by Anonymous Coward · · Score: 0

    I do not like that I cannot expect to look at a Python function definition and see what are the expected types of the arguments.

    If you could, ie if the functions did expect arguments to be of certain types, you couldn't use polymorphy in python, could you? In fact it can (has) been argued that particularly in large projects, type restrictions lead to lack of maintainability.

    Probably the answer is to rely on unit testing instead of static typing for large application maintainability in python.

  37. demerits by Doc+Ruby · · Score: 1

    I had to laugh at the moderation results for the parent post, pointing out that debate targets the stated ideas with counterideas, not the people stating them with mere negation:

    Starting Score: 1 point
    Moderation -1
    100% Overrated
    Karma-Bonus Modifier +1 (Edit)
    Total Score: 1

    Sharkbite!

    --

    --
    make install -not war