Re: [Tutor] following on
> Does this comment extend to C++? :-) > > Could the experts, please, recommend a beginner's book to learn the > principles of good programming? I'm partial to How to Design Programs as a beginner's textbook: http://www.ccs.neu.edu/home/matthias/HtDP2e/ because it emphasizes a systematic approach to designing programs. Basically, it's a Polya's "How to Solve It" for programmers, with an expanded treatment on how data structures inform the shape of the functions that work on that data. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 19/02/13 11:27, Shall, Sydney wrote: Could the experts, please, recommend a beginner's book to learn the principles of good programming? Thats exactly what my book tries to do although it focuses on Python. But its really more about the general principles than learning the idioms of the language. The bad news is that it's now 12 years old and the language has moved on, although most (all?) of the code will still work in Python 2.7. Should be available through your local library or cheap on Amazon marketplace... The good news is that an updated and extended version is on the web (see the.sig) and is free! :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
> Could the experts, please, recommend a beginner's book to learn the > principles of good programming? I don't know about expert, but I found the Head First Lab's approach to be really good. The Python book is structured like so: -Lists introduction -(PyPi)/creating modules -- this I hope has been changed in future editions of the book, because PyPi now has a test server for those learning to use it, instead of people uploading to the official PyPi server (if you've ever wondered why there are so many modules for printing lists within lists (nester.py)). -Error handling -Saving data -Work on data -OOP -Web development -Mobile App development -Handling input -Scaling your webapp (which you built in the web development chapter) -Handling complexity Each chapter consists of a challenge that you'll work; the work on data one has a "Coach Kelly" giving you his files on runner times, wanting it formatted. So first you'll learn to read it in, sanitize it and everything, and after that you move on to OOP design, where you create a new class (let's see if I recall it): class Athlete: def __init__(self, name, dob=None, times=[]): self.name = name self.dob = dob self.times = times def add_time(self, time): self.times.append(time) def add_times(self, times): self.times.extend(times) After you've designed the class yourself they go on to mention that instead of building functionality that already exists -- self.times.extend(times) -- it's probably better to create a class that inherits from list, like so: class AthleteList(list): def __init__(self, name, dob=None, times=[]): list.__init__([]) self.name = name self.dob = dob self.extend(times) In each chapter they go through various approaches on things that crop up; for error handling it's the add extra logic/ask forgiveness, for classes it's custom class or inherited class, for saving data it's custom code vs off the shelf solutions, why you want to create functions instead of duplicate code and so on. It's well structured, readable, and have quite enjoyable challenges (compared to the usual "Hello World" approach that many other books do). So yes, they teach you Python, but they also teach you the principles of good programming. I recommend it to anyone who wants to learn Python, but there are probably better books for *specifically* programming principles -- this book is more of a bundled deal. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 19/02/2013 02:15, Steven D'Aprano wrote:hon modules. Many people will advise that learning C is a good idea. I understand their arguments, but as an old curmudgeon I can say I don't like C and I think the world would be much better without it :-) Does this comment extend to C++? :-) Could the experts, please, recommend a beginner's book to learn the principles of good programming? Ta muchly, Sydney -- Professor Sydney Shall, Department of Haematological Medicine, King's College London, Medical School, 123 Coldharbour Lane, LONDON SE5 9NU, Tel & Fax: +44 (0)207 848 5902, E-Mail: sydney.shall, [correspondents outside the College should add; @kcl.ac.uk] www.kcl.ac.uk ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
Hey, a Big thanks to everyone that has offered their input. I really appreciate it. Also thanks for all the additional links, i will definately start to read up on data structures , source code and everything else that was suggested ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 19/02/13 06:01, Matthew Ngaha wrote: understanding of how everything works. Use it., Experiment with it. Break it. Thats the best way. Read the source code its all available in Python or C. Hey can you please tell me which source code youre referring too? The initial files that come with Python? also the C code, where can i locate this? is C something worth learning? why is Python code available in C? If you want to learn Python programming, read other Python programs. You will find many Python programs, of greatly variable quality, here: http://code.activestate.com/recipes/langs/python/ You might also like to read this book: http://shop.oreilly.com/product/9780596007973.do You can see the source code used by Python modules by searching for them on your computer, then opening them in a text editor. But beware that you don't accidentally modify them, because you may break your Python installation. Another alternative is to read the source on-line. Many pages in the Python docs link directly to the source code. E.g. this page: http://docs.python.org/2/library/string.html links directly to the source code: http://hg.python.org/cpython/file/2.7/Lib/string.py You can learn a lot from the source code of Python modules. The source code of the Python interpreter, on the other hand, is much, much more complicated. You will probably have a lot of trouble with it, since you are unfamiliar with C, and unfamiliar with the internal C libraries used in the interpreter. But if you are feeling masochistic and want to give it a go, you will find the source code here: http://hg.python.org/cpython Click the "Browse" link to get to the latest version. Many people will advise that learning C is a good idea. I understand their arguments, but as an old curmudgeon I can say I don't like C and I think the world would be much better without it :-) The Python interpreter may be written in many different languages. C is only the most common language. The "Big Four" Python interpreters are written in four different languages: CPython (what you probably think of when you say "Python"): C Jython: Java IronPython: Microsoft .Net CLR PyPy: RPython ("Restricted Python") but there are others: CLPython: Common Lisp Burp and Hope: Haskell Nuitka: C++ Pynie: Parrot Vyper: Ocaml Skulpt: Javascript although some of these may be experimental, obsolete or abandoned. yes i will try not to reinvent the wheel, a lot of tutorials ive read seem to always point this out. Just out of curiousity what is a bag, stack or circular list? what is needed to create something like this? i sort of heard about a stack its a C/C++ thing i think? You can read about data structures like stack, bag (multiset) and circular list here: http://en.wikipedia.org/wiki/List_of_data_structures -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
>> i sort of heard about a stack its a C/C++ thing i think? > > A stack is fundamental to modern programming languages. The only two > machines I've used that didn't have a stack implemented at the machine level > were the CDC 6000 series, and the IBM 360. Both products of the 60's. A while back, while researching something else entirely, I came upon a useful article explaining recursion. In it he briefly touches on how a stack functions, and the explanation is well worth reading (as is the article!). You can find it here: http://inventwithpython.com/blog/2011/08/11/recursion-explained-with-the-flood-fill-algorithm-and-zombies-and-cats/ If you just want to read the stack explanation, scroll down to "Recursion is Just a Fancy Way of Using a Stack" -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 02/18/2013 02:01 PM, Matthew Ngaha wrote: i sort of heard about a stack its a C/C++ thing i think? A stack is fundamental to modern programming languages. The only two machines I've used that didn't have a stack implemented at the machine level were the CDC 6000 series, and the IBM 360. Both products of the 60's. Processors like the Intel Pentium series have a stack microcoded into their lowest level instruction set. When the processor itself is calling a subroutine, the current address is pushed onto the stack, and the return instruction pops it back off and jumps there. Other instructions for manipulating it exist at the same level. Typically all local variables in a function are stored in the current stack frame. The stack makes recursive functions practical, at a minimum. Having multiple stacks makes multithreading practical as well. Recursion and multithreading was very tricky on the CDC, since it stored return addresses right into the running code. Usually a programming language will provide a stack-like data structure, for manipulating data that needs similar behavior. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 18/02/13 19:01, Matthew Ngaha wrote: initial files that come with Python? also the C code, where can i locate this? Look in the python.org download page and you will find a link to the source for that release. For 3.3 it's here: http://www.python.org/download/releases/3.3.0/ Look at the first 3 bullets item under the Download header. is C something worth learning? why is Python code available in C? Because the core Python language is written in C. And many of the library modules have been written in C for performance reasons. Its worth getting a basic understanding of C, enough to read it if not enough to write it(much harder). seem to always point this out. Just out of curiousity what is a bag, stack or circular list? Use Wikipedia, it will explain what these standard computer science containers are and how they work. Wikipedia is a fantastic learning tool for would be programmers. what is needed to create something like this? Any general purpose programming language, such as Python. i sort of heard about a stack its a C/C++ thing i think? No, its a computing thing. It can be done in any common programming language. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On Mon, Feb 18, 2013 at 07:01:02PM +, Matthew Ngaha wrote: > >> understanding of how everything works. > > > > Use it., Experiment with it. Break it. > > Thats the best way. Read the source code its all available in > > Python or C. > > > > Hey can you please tell me which source code youre referring too? The > initial files that come with Python? also the C code, where can i > locate this? is C something worth learning? why is Python code > available in C? C is definitely worth learning. So is LISP. And a handful of other languages we could enumerate. It's worth learning if it adds something useful to your understanding of how computers operate on the instructions you give them, or if it changes your approach to creating software in a fundamental way. Actually using those languages in daily life is not the point. C, however, is still very useful in a number of situations. Python programmers can get leverage from its strengths by--for example--writing performance-critical modules in C and then calling them from their Python programs. Python itself (well, the standard implementation of it anyway) is written in C. It has to be written in something that ultimately compiles down to the machine language which the computer actually uses. That C code interprets your Python code so you have a much nicer, high-level programming environment to work with. But the computer itself doesn't directly understand Python. > yes i will try not to reinvent the wheel, a lot of tutorials ive read > seem to always point this out. Just out of curiousity what is a bag, > stack or circular list? what is needed to create something like this? > i sort of heard about a stack its a C/C++ thing i think? None of these are C/C++ things. They are basic building-blocks of Computer Science and data structures you'll use regardless of language. I'd really recommend investing some time reading up on these and other fundamental data structures. -- Steve Willoughby| Using billion-dollar satellites st...@alchemy.com | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
>> understanding of how everything works. > > Use it., Experiment with it. Break it. > Thats the best way. Read the source code its all available in > Python or C. > Hey can you please tell me which source code youre referring too? The initial files that come with Python? also the C code, where can i locate this? is C something worth learning? why is Python code available in C? > >> like how can i make my own custom container and not have it >> subclass list(), and still act like a list()? > > That's a more sensible option especially if you make it a type of container > that Python doesn't already have. Maybe a bag or a stack > or even a circular list. But there is no shame in inheriting from > list if that makes sense. That would be good software engineering - don't > reinvent the wheel! > When building reusable code start from the perspective of the user. Write yes i will try not to reinvent the wheel, a lot of tutorials ive read seem to always point this out. Just out of curiousity what is a bag, stack or circular list? what is needed to create something like this? i sort of heard about a stack its a C/C++ thing i think? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 18/02/13 17:30, Matthew Ngaha wrote: i can attempt to use these libraries/frameworks/modules provided but how can i build or get better at creating/building my own tools? practice. Just build a lot of stuff. Its the only way. and i did that!" or hey i built my own engine, my own language!! That doesn't happen all that often, usually people just extend the existing language. etc... i become absolutely lost and thought i would like to do that! What? Get absolutely lost?! :-) wondering if anyone could point me out to some good books or online tutorials that can teach me how to create my own modules, libraries that others could use. In python this is almost trivial. Just create a Python script that has functions or classes in it. That's it. Make it available for import by putting it somewhere in your import path. job done. There is a little bit more to creating a package rather than a module but its easy once you've got the hang of making modules. This is what is called software engineering No, its a part of software engineering. Software engineering is an attempt to apply traditional engineering discipline to software development in the hope that it will make the development process more predictable, reliable and consistent. So far it's pretty much failed because most "software engineers" don't really like doing hard math when they could be writing code, and doing hard math before building anything is pretty much what makes it engineering... (This is why some US states refuse to acknowledge software engineering as 'real' engineering.) But it also includes things like creating modular designs and performing comprehensive tests and documenting the design in standard formats etc. Those aspects have caught on in varying degrees. create custom instances and have these instances behave like normal python objects. Thats good. I want my program to basically do EVETYTHING that python already does but in my own way. On the objects i'd like to perform stuff like __add__ or __cmp__ on them, but without actually using __add__ or __cmp__, get it?. No, that's probably not good. I'll attempt my own built-ins also, And that's almost certainly even worse. like summed() instead of sum()... is this a constructive exercise or a waste of time? Its a waste of time given where you are on your learning journey. Maybe some day you will have a valid need to create your own language but this is almost certainly not it! understanding of how everything works. Use it., Experiment with it. Break it. Thats the best way. Read the source code its all available in Python or C. like how can i make my own custom container and not have it > subclass list(), and still act like a list()? That's a more sensible option especially if you make it a type of container that Python doesn't already have. Maybe a bag or a stack or even a circular list. But there is no shame in inheriting from list if that makes sense. That would be good software engineering - don't reinvent the wheel! would i need to use stuff like __next__ and __iter__ or could i create my own that acts the same way You need to implement all the special methods that give Python objects their built-in behaviour. Or at least all the ones that matter, or make sense, for your data type. ill drop the project if its a bad idea but if it isnt, its simply a work in progress(barely started). I'd forget trying to rewrite Python in python. Even as a learning project it has limited value and as a practical proposition no value at all. Better to build something meaningful that pushes the envelope with python. so please point me out to some good books or online tutorials that can teach me how to create my own software that others could use. Also what is the correct term for this type of programming? Just programming. Its what we should all be doing all the time! have any personal advice you could offer me, please do.. Thanks When building reusable code start from the perspective of the user. Write some tests that use the new creation even though it doesn't exist yet. Make the code as easy to use as possible. Once you know how to use it, start building the thing so that it can be used the way you want it to work. The hard effort should be in building the reusable code not in using it. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor