Slashdot Mirror


Think Python

An anonymous reader writes "In a neverending effort to spread the word about free quality online programming books, here is a Python programming book. 'How to Think Like a Computer Scientist: Learning With Python', by Allen B. Downey, Chris Meyers, and Jeffrey Elkner is a copylefted work available in multiple formats at Green Tea Press: HTML , PDF, LaTeX. Compliments of the online books what's new page."

18 of 200 comments (clear)

  1. Question by citizenc · · Score: 3, Insightful

    Am I the only person who thought the title of the book was "How to Think Like a Computer Scientist: Learning With Monty Python"?

    Man, it's early.

  2. Re:How to think like a computer scientist by vofka · · Score: 2, Insightful

    True 'Computer Science' covers a lot of areas, mostly fundemental, including Computer Theory, Electronics, Mathematics, Logic, Processor Theory and Design, to name but a few.

    The majority of today's CS Courses seem to fall into two broad categories, 'Software Development', and 'Systems Management'. Whilst these are both elements of computer science, they do not encompass computer science as a whole.

    Universities are more and more often cutting out the core Computer Science components of their courses, such as Electronics and Computer Thery, which is a shame - whilst the courses leave graduates with an understanding of 'How' to do certain tasks, they are left with no understanding of 'why' they are done that way, because they have no real understanding of how the Computer Systems they are carrying out tasks on actually perform their functions.

    NDFSM's are important, Karnaugh Maps are important, Understanding the CPU F/E Cycle is important too - bring back real CS to our Universities!

    --
    Disclaimer: I meant what I thought, not what I wrote! What? You can't read my Mind? Oh dear!
  3. How about how to think like a Software Engineer? by hacksoncode · · Score: 5, Insightful
    I should probably quit whining and write my own copyleft book, but I skimmed through this book, and I'm not all that impressed.

    This book doesn't strike me as a book on how to think like a Computer Scientist, except insofar as Computer Scientists generally make lousy Software Engineers. There are no descriptions of the advantages of object oriented programming, discussions of theoretical topics, and in general very little encouragement to view programming as a science. Basically, this appears to be just a book on the Python language, written for someone who has never programmed before. That's a fine thing, don't get me wrong. My brief look even makes me think it could be an effective example of such a book. At the very least, I think it's hyped wrong.

    However, from a software engineering point of view, I find it damning that the book forgoes any explanation of the practice of, or motivation for, writing maintainable code. I consider that unforgivable in a beginning programming book. You absolutely have to impress on newbies early the importance of documentation, sensible structure, logical variable naming, good class hierarchy, etc.

    I consider this especially true for Python, which is an interpreted non-declarative language (making maintainabilty all that more important). Python is, conversely, also especially well designed as a platform where such concepts could be taught. It largely overcomes the occasional weaknesses of its design philosophy by consciously including language features such as built in support for docstrings, well crafted namespaces, modules as first-class citizens, etc.

    Yet, these language features are barely given a nod in this book.

    It's books for existing programmers that can afford to skimp on these areas.

  4. Re:Computer 'Science'? by Anonymous Coward · · Score: 1, Insightful

    Feynman doesn't have a fucking clue about anything outside his own field. He's a prime example of one of these arrogant beings who believes nothing is more important than their field of choice.

    Of course Computer Science is a science - take any introductory CS course and you will come across many formal theorems and hypothesis-based discoveries.

    Examples:

    Halting problem - this is essentially derived logically from basic premises.

    Neural networks - these are constantly the subject of scientific study in much the same way as geneticists study rats.

  5. Re:How about how to think like a Software Engineer by Anonymous Coward · · Score: 1, Insightful

    That's because it's not about Software Engineering, you fool. It's about Computer Science.

    Software Engineering is essentially the application of CS to real world projects - and the current fashions in SE should be a separate course entirely. It's more about psychology and HR than it is about Computer Science.

  6. C is a high-level language?? by jackb_guppy · · Score: 2, Insightful

    From the opening section of each book: 1.1 What is a programming language?

    Java is an example of a high-level language; other high-level languages you might have heard of are Pascal, C, C++ and FORTRAN.

    Python is an example of a high-level language; other high-level languages you might have heard of are C, C++, Perl, and Java

    Both C++ and Pascal are high-level languages; other high-level languages you might have heard of are Java, C and FORTRAN

    C, a language without file i/o, without bound checking, and with direct access to ports is high-level? If you say the libraries chucked into a C load makes it so... Then Assemebler is a high-level language, too.

    Last I heard was Binary Code=0, Assem=1, C=1.5, Fortran, Cobol, & Basic were about 3, ADA, C++=5.

    Perl was not even in the picture, because it was scripting language

    Also high-level languages does not equal easier code or does not make it faster code... It does makes more strict to code, more following the limited ways the authors of the langauge thought you should think (like the use of GOTOs :-). Low-level languages allow the coder the freedom to get the job done and not comprise the functions to limits of the authors, and it requies the coders to truely think like computer sceincist. Look at ADA for what is wrong with really high-level langauge. See how limiting the langauge can be made. And how much time is need to see up the coding effort.

    PS: maybe these are great books, but I stopped reading there, because how can it teach to "Think like Computer Sceincist" when it does not know about the basics of computer sceince?

    1. Re:C is a high-level language?? by nd · · Score: 2, Insightful

      The bases for a sceince is terms. If they can not get the basic of terms right then there is no science.

      I don't think they got any "terms" wrong. I still assert that how "high-level" a language is is NOT an absolute scale.

      MIPS assembly compared to C - C is higher, more human to read (if you do not compound expressions (example: x(i++) =+ y(--j); ). But C is much lower than Basic.

      Good, so you are thinking in terms of "higher" and "lower".

      Know the question: Did your teacher refer C as a HIGH-LEVEL LANGAUGE (wrong) or a HIGH-ER-LEVEL LANGUAGE (right)?.

      High-level language. This is NOT wrong in the context of the course. Relative to the course material (assembly), C is a very high-level language. I have always thought of this scale in terms of context and relativity, not absolute.

      Why do I do this? Well, I suppose in theory someone could come up with an absolute scale and say "C is classified as a X-level language", but when the only terms we're using are "high", "low", and sometimes "medium", this will not hold up.

      You've been programming for a long time. Certainly you realize that C was considered more high level back then than it is now.

      Rewind back to the early 90's. Ignoring Basic, Pascal was the highest-level language I was familiar with and used. People undeniably (and fairly consistently) referred to Pascal as a high-level language. Along comes languages like Java, which is clearly higher level than Pascal, and we have to re-evaluate what we consider to be "high-level".

      The point is, we can't keep redefining this stuff everytime a new language comes out. You call Python high-level today, but 15 years from now when some other language comes out even more abstract, you can no longer call Python high level unless you keep attaching superlatives (like "very") to the new languages.

      Relative. Not absolute.

  7. Pointers required by magi · · Score: 3, Insightful

    While Python is my favourite language, I think it's rather silly to teach Computer Science and especially basic algorithmics with a language that doesn't have pointers.

    At low level, pointers are everything, and low level is what you want to teach when you're teaching basic data structures and algorithms. There's simply no point in demonstrating list implementation with an interpreted language that has very efficient native lists, dictionaries, etc. C/C++ or Pascal are much better for that; with them you can teach real implementations, not toy ones.

    On the other hand, Python might be ideal for teaching advanced algorithms such as sorting and string algorithms, as those are more "high-level" problems and low-level pointer-messing is no longer needed nor desired. Python has very beautiful string and list operations, which make such algorithm implementations cleaner.

    Also, Python might be ok for the very first Basics of Programming course with respect to pointers, as they don't really teach any algorithmics there. However, the weak typing (very late binding) would be a problem in this case. Beginners will have enough trouble understanding the language without the need to handle implicit types. I'd very much suggest a strongly typed object-oriented language such as C++, Java, or Eiffel, where the types are always explicit. For an algorithms course this isn't so much a problem.

    For some classes, such as AI, there's simply no winner for Prolog, and perhaps Lisp, but many Python features such as easy string manipulation and other middle-level data structures make it temptating for many subjects such as Automata and Formal Languages. It would be interesting to have a good Python interface to a Prolog interpreter; one that is well integrated with the syntactic philosophy of Python.

    1. Re:Pointers required by cheezedawg · · Score: 5, Insightful

      I think it's rather silly to teach Computer Science with a specific programming language at all. Computer Science is not about teaching people how to program.

      To me, Computer Science is a very cool blend of:
      - Discrete mathematics
      - Computation theory
      - Linguistics
      - Complexity theory
      - Logic
      - Probability

      None of these rely on programming at all, let alone a specific language or whether that language has pointers or not. Programming is only an application of Computer Science.

      You gave example of an AI class- to me, the core of AI is learning about first-order logic and predicate calculus, searching and graph traversal heuristics, reasoning, and natural language processing. I know this list isn't complete, but the point is that these concepts are for the most part independent of programming. Sure, you can start off by teaching somebody a specific implementation in Lisp or Prolog, but then they only know program AI in Lisp instead of how to apply AI concepts in any setting.

      --
      "The defense of freedom requires the advance of freedom" - George W Bush
  8. Re:Computer 'Science'? by Lictor · · Score: 4, Insightful

    Hmm... to be honest... the "Feynman Lectures on Computation" are just about as absurd as the "Goedel Lectures on Biochemistry" (these don't really exist... I'm just being sarcastic). The original poster's comments on Feynman had some merit.

    The phrase that you quote here displays a mind-boggling ignorance about exactly what "Computer Science" is. Software Engineering is, indeed, "like Engineering" but there are many branches of Computer Science that deal *purely* with the abstract. I do Formal Language Theory and Automata Theory for a living and I just can't see how these fields are about "getting something to do something". Feynman, like most people, has missed the science for the telescope.

    The real joke is that things like the Church-Turing thesis could not possibly be MORE about "natural objects". In the abstract, I can define a machine that can solve the halting problem. Heck, I can define a machine that solves any problem I want! The Church-Turing thesis tells us about a PHYSICAL limitation on computing. In this universe, you can only build a machine that will compute *these* functions.... But what if I live in a universe where time has no meaning? All of a sudden, I get a *very* different Church-Turing thesis.

    There is no question that Feynman had some brilliant insights in physics, but I have to admit that when I read the Lectures on Computation, not only did I lose a small amount of respect for him... I found myself actually outraged. Many intelligent people will read these lectures and believe them... I mean, after all, they're written by Feynman, right?

    Computer Scientist's have enough trouble trying to explain to people that, no, we don't just sit around installing Windows network drivers all day without a respected and intelligent person like Feynman adding to the problem.

  9. Not convinced at all by Anonymous+Brave+Guy · · Score: 2, Insightful

    After having a quick look at bits I'm qualified to assess (I'm not a Python programmer, but do have plenty of background in CS, C++ and other related topics) I'm not convinced at all that I'd want to learn from this book.

    Much of the preface by Jeff Elkner basically compared C++ to Python and has a go at the deficiencies of C++. It would be more convincing if he knew the return type of main(), the name of the standard header <iostream> and what a statement was. Three fundamental mistakes just in discussing "Hello, world!" is not a good sign for the author's level of knowledge and understanding.

    Trying to put aside my bias, as I like C++ as a practical language, I examined the appendix on creating a UDT for fractions to form a second opinion. Here, they do the obvious simple things to create a rational number class, and nowhere do they make the basic sanity check that your denominator is not zero. Surely one of the basic tenets of OO theory is that you always maintain your class' invariant properly? Their class may be a fine demonstration of Python's OO features -- I don't know, I'm not familiar enough with them to judge -- but it's a lousy demonstration of either good CS or good OO.

    From these observations, I have to ask whether I'd actually want to learn Python from this book. If I do, how will I ever have any faith that what I've learned is correct and in good style?

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:Not convinced at all by elflord · · Score: 3, Insightful
      But think that your comment about main() might indicate a lack of understanding on your part, not on Elkners. I don't think that the ANSI C specification defines a return type for main() (I did a quick grep of the spec to check).

      The C++ spec certainly specifies that the return type of main() is int. It's covered in 3.6.1 of the C++ standard. (I'm pretty sure the same is true for C).

      Also, in practice, different implementations require different return types.

      They're not conforming implementations if they require that main() doesn't return int.

  10. You miss the point(er) by pclminion · · Score: 4, Insightful
    While Python is my favourite language, I think it's rather silly to teach Computer Science and especially basic algorithmics with a language that doesn't have pointers.

    You have failed to understand the point of Computer Science (pun intended). Python is a terrific language for teaching CS because it has the basics of discrete structures: lists, maps (in Python, called dictionaries), tuples, and atomic data types such as strings, ints, and reals. That's all you need.

    There's really nothing you can't do once you have lists and maps. Don't object that you can't have O(1) access-time arrays -- you can do that with a map.

    I challenge you to describe any algorithm at all that can't be implemented without pointers. If you think you need pointers, you just aren't thinking like a computer scientist.

    For some classes, such as AI, there's simply no winner for Prolog, and perhaps Lisp

    In general, you are absolutely correct. Of course, this is opinionated and others may disagree. But remember, you can use any Turing-complete language to simulate any other Turing-complete language (that's the entire definition of Turing-complete). Which means I can write a C interpretter in Prolog if I want (and I'm feeling particularly masochistic), and therefore I can simulate pointers using Prolog.

    Oh, but you cry "That can't possibly be efficient!" Right again. But you've again missed the point of Computer Science. CS is about efficient algorithms, not efficient programs. That's something we leave to the software engineers and other "implementors." Us CS freaks think about what can be done, we don't actually do it ;-)

  11. Python is a GREAT language, but. . . by stevarooski · · Score: 4, Insightful
    Python is an excellent languange that I've been using for about 8 months now. Anyone who has ever programmed before can pick it up easily just by reading the [very thorough] documentation at python.org. It also has an rabid support base via newsgroup, who are excellent at answering questions.

    That said, I don't know if I would teach a begining computer science course in python. At my University, our general intro to CSE involves a two class series teaching generic basic theory wrapped around a programming language. We used to teach them with C and C++ but just recently moved to Java. I have been a TA for these classes before. Based on my experiences, I think there are both pluses and minuses to the idea of teaching these classes in python.

    Benefits:
    1. Python is extremely easy to learn, as mentioned before. Much easier than C, C++, or Java.
    2. Python works really well with Tk, which would make it easy to build out skeleton code (multiplatform skel code at that) for the students using windowing and graphics. Students are 100% happier if they can see what they're working on reflected graphically. Makes it more fun to show off. This is why our projects usually include basic games.
    3. BASIC Python is truly, completely, multiplatform, working identically on Mac, Win*, and *nix. Some specialized functions in modules don't support all platforms, but nothing that would be important to a begining student. Support issues would be MUCH simpler than C or C++. God, we had huge headaches trying to support MSVC, CodeWarrior, CodeWright, Borland, etc. . .
    4. There is a great installer script available that will build python modules into either standalone exe's or distributable directories. (Available here if you've never seen this before)
    But, there are also some downsides that would have to be weighed. These are:
    1. I have yet to find a solid dev environment that includes a great debugger. Yes, emacs can be set up to help a bit, and the default program included with the windows install is ok (albiet a bit flaky), but I would want a rock solid, easy to use complete dev studio for my students.
    2. I REALLY dislike any language that depends on white space. Miranda and Haskell are two other examples of this. Its a pain to move blocks around and anyone who doesn't use an editor with auto-indent is screwed. Also, unless tabs are set to spaces, computers with differnt tab stops will see your code differently, which can be a problem if code is emailed, etc.
    3. As has already been mentioning, not too much one can teach about memory management and pointers with python. . .
    4. Sounds kinda strange as a complaint, but too much is built in. I have this complaint about java too. As an example, I would much rather have an early homework be a sorting algorithm and then have them reuse this algorithm in other homeworks than let them just type "xxx.sort()". Not that this isn't a great feature for experienced programmers, its just that begining students should have to do sorting, reversing, duplicating, etc themselves at first.

    Looking away from basic intro classes, python is great to know. I did a lot of AI code sketches in python, and have used it to slap together simple programs at work. However, I would consider it a tool to be learned after the basics have been beat in. If I had learned python first, it would be a lot harder to force me to do everything in C later. :o)

    -s
    --

    - - - - - - - -
    Don't worry, being eaten by a crocodile is just like going to sleep in a giant blender.
  12. Not about computer science; try SICP instead by alienmole · · Score: 3, Insightful
    That's because it's not about Software Engineering, you fool. It's about Computer Science.

    If you actually look at the book in question, you'll see that the original poster was correct: it's not about computer science at all. It's a Python programming book with a marketing angle relating it to computer science.

    If you really want a book which teaches "How to Think Like a Computer Scientist", try SICP. For a good summary of the book, see this comment from the recent "Best Computer Books" article.

    1. Re:Not about computer science; try SICP instead by alienmole · · Score: 3, Insightful
      We want it for free :(

      The link I gave to SICP includes the full text in HTML. How much more free do you need it to be? It's accessible by clicking the link on that page which reads "Full text! The complete text in HTML". Unintuitive, I know, but that's the kind of thing you'll learn to understand as a computer scientist...

      though many of the critics are ineed covered in the book: naming of variables, abstracting and not hardcoding stuff, making it readable, making it generic, wrapping code, etc.

      These things have very little to do with computer science, with the exception of abstraction (which has very little to do with "not hardcoding stuff"). What we have here is a situation where people who know absolutely nothing about the current practice of computer science are using the term to mean whatever they imagine it means.

      Variable naming, readability, wrapping code etc. all involve techniques which any good programmer should understand, academic or otherwise. But calling that computer science is like calling hammering a nail "civil engineering" or "materials science". The Python book, at best, could be described as an intro guide to software engineering, but even that's a stretch. It's really "how to program in Python", with a few technical terms introduced along the way.

    2. Re:Not about computer science; try SICP instead by alienmole · · Score: 3, Insightful
      I don't like math much though I adore logic)

      I also tend to prefer the logic side of things. A lot of computer science of the kind that SICP deals with has to do with mathematical logic, which I find more logic-like than math-like. For that reason, I love the lambda calculus, which is what almost all functional programming is based on.

      If you like logic, and you like programming, you *must* learn the lambda calculus - it'll give you new insight into the meaning of computer programming, and you'll probably enjoy it, too. It has applications to literally every programming language. If you're not already familiar with lambda calculus, the name sounds a lot more daunting than it really is. To start out with, you can think of it as a really simple and primitive programming language - almost the prototypical programming language.

      I'm not sure what the best intro source into lambda calculus is - the academic works are mostly heavier-duty than you really need. Some google searching definitely turns up some useful stuff, but offhand I don't know of a definitive intro site. However, SICP teaches a lot of the necessary fundamentals, since the Scheme language that it uses as a teaching tool is just about the closest language to the lambda calculus that there is. If you learn a bit of Scheme first, learning lambda calculus from the lay perspective is fairly straightforward. (I say "lay perspective" because it has some hairy mathematical underpinnings, which I mostly ignore, and that's OK for most purposes unless you're trying to prove mathematical theories.)

      (ie: I know to how to program, but not how to make good programs. Every tome i need to add unexpected features or when I review my old stupid ugly code, I am reminded of that fact :-)

      ...And then there's programming under a deadline, which is a whole 'nother story.

      I think that these academic topics can be excellent for improving one's design and thinking skills, at least I've found that to be the case. It's an indirect kind of thing, though, and experience is probably equally useful. Abstraction is key, though, whether you do it using object-orientation or modules in functional programs, keeping interfaces separate from implementations is probably one of the most important things, which people violate all the time. It doesn't help that many languages don't provide features to do this properly...

  13. Sorry, but you're confused by alienmole · · Score: 4, Insightful
    While Python is my favourite language, I think it's rather silly to teach Computer Science and especially basic algorithmics with a language that doesn't have pointers.

    At low level, pointers are everything, and low level is what you want to teach when you're teaching basic data structures and algorithms.

    Conceptually and from a computer science perspective, the object references present in languages like Python, Java etc. are equivalent to pointers in all the ways that matter for representation of data structures and algorithms. In the academic community and elsewhere, it's generally considered beneficial to teach such things without reference to the machine pointers which you're referring to, since machine pointers carry a lot of baggage that's unrelated to the abstractions involved in data structures and algorithms.

    There's simply no point in demonstrating list implementation with an interpreted language that has very efficient native lists, dictionaries, etc.

    To refute this, let me offer a tutorial: A Gentle Introduction to ML. If you work through this tutorial, you'll very soon begin implementing functions in the ML language for basic list operations and the like - functions that already exist in the language. And guess what: the implementations that the beginner typically comes up with in that tutorial are very close to the actual implementations that ML uses - the tutorial gives some examples of actual implementations for comparison.

    This high-level operation doesn't even cost much -languages in the ML family, including OCaml, regularly are top performers - see e.g. Doug Bagley's language shootout. They can perform on par with languages like C because their type systems allow sophisticated compile-time optimizations to be performed, and their high-level abstraction features are supported by optimizations such as tail recursion.

    C/C++ or Pascal are much better for that; with them you can teach real implementations, not toy ones.

    If you believe that C/C++ and Pascal are good languages for teaching computer science, you don't know much about modern computer science. All three of those languages have very weak type systems and lack basic features that allow the construction of high-level abstractions.

    Pascal is all but a dead language in the CS community nowadays. The primary use for C is as a decent portable assembler. Learning C has very little to do with computer science, and absolutely nothing to do with teaching computer science concepts.