Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Python: What to do after you've finished Code Academy?

One of the most common beginner questions I see in Python programming forums is from people asking what to do once they’ve completed Code Academy’s Python training course. The possibilities are virtually limitless and may seem overwhelming at first, especially if you have little prior programming experience. It’s a bit like finding yourself in a foreign country where you know enough of the local language to just get by, but not enough to really find your way around. I certainly don’t claim to have the map, but in this post I’ll try to point out a few landmarks that might help some folks get their bearings. 

The Code Academy course covers the basics of Python syntax and data structures, and provides a quick introduction to more advanced topics like the use of list comprehensions, bitwise operators, classes, file input/output etc. Along the way, the student also completes a handful of small projects to demonstrate how this newly acquired knowledge can be put to use, for example, a pig latin translator, a Battleship game simulator and so on.

But the big question is: what next?! There is no straightforward answer to this question, as it depends on a number of highly individual variables such as your level of prior programming knowledge and experience, your interests, your goals and motivations for learning programming in general and Python in particular, not to mention the amount of time you are able to devote to study and practice, to name just a few. For the sake of simplicity, what follows is targeted to a beginner who has recently completed an introductory Python crash course such as Cody Academy’s Python Track, or Learn Python the Hard Way, has little or no prior programming experience, and can devote a modest amount of time to study and practice on a regular basis. 

As a natural language instructor, I can almost always tell when a student has not done any homework or practice over a long weekend: they are already starting to get rusty! Probably the single most important thing to do after an introductory course like Code Academy’s is to reinforce the lessons learned, and to do it on a consistent basis. This will help to shore up all that newly acquired knowledge and provide a sturdier basis to extend it and expand on it. This could be anything from reading a textbook to watching a series of lectures, or following along with another tutorial, exploring other areas of the Python universe, tinkering with your own little programming projects, or some combination of these, or even all of the above. 

You’ll likely also find that these activities are themselves mutually reinforcing: while working on your own projects, you’ll realize when you’ve hit a wall and need to consult some documentation or a textbook, or seek out a new library or framework to help achieve your goal; reading through a textbook you’ll be exposed to new ideas that you can experiment with in the interpreter or in your own little projects; working through a tutorial, you might find a piece of code that interests you and which you start to tweak on your own to see how it works and to experiment with extending it or expanding on it in some way, shape or form.  

If Code Academy was your first exposure to programming in general, it might be a good idea to consider working through a general introductory textbook (or even an introductory course!) on computer science. This will provide you with a basis in the fundamentals of the discipline as a whole, things that are more or less the same across all programming languages. 

So far as introductory textbooks go, many people, myself included, highly recommend Think Python: How to Think Like a Computer Scientist, which is freely available online.   This book is required reading for a number of well known introductory computer science courses such as MIT’s Introduction to Computer Science and Programming, and was written for the express purpose of introducing students to the field. It is highly readable, provides a review of basic syntax and covers intermediate as well as more advanced topics, along with a series of chapters on object-oriented programming and design. 

Along similar lines, if you have the time to devote to it, I highly recommend MIT’s Introduction to Computer Science class. All the lectures, recitation sections and course materials are freely available online in their entirety, and the course uses Python as its pedagogical language of choice. For more information on this course, see our previous post Teach Yourself Python in Less Than Four Months, which provides a learning plan that uses the MIT course as its guide.  

Okay, but what if you are not the type who likes to curl up with a good textbook, and don’t have the time to slog through a college level introduction to computer science course, but want to delve more deeply into Python itself? What then? In this case, you might consider working through another general introductory tutorial on Python programming, this will help consolidate the knowledge you’ve already gained and also likely expose you to more beginner and intermediate level aspects of the language and the programming process. There are tons of such resources available online. Here are a few that I've found quite helpful:
"Bah," some may say, "I'm bored of mechanically typing out tutorial code! I want to experiment, but I'm not sure where to begin!" Not to worry, there's tons of stuff out there, you just have to know where to look. For those who want to jump right in to real problem solving, your first stop should be the Programming Mega Project List. This is a list of around 100 practical programming projects that can be solved in any programming language. The difficulty level of the various projects ranges from beginner to advanced and the list broken down into basic categories such as math, algorithms, networking, text, web, and so on. Find one that interests you, tackle it and repeat.

Other people may find it rather uninteresting to solve problems for the sake of problem solving, and would rather explore Python itself. The standard library is your friend! One of the great things about programming is that it can make your life a whole lot easier. If you stick with programming, one thing you will learn rather quickly is that programmers are lazy and proud of it. If I had a dime for every time I’ve come across a talk or article on programming which proclaimed that programmers are lazy, I’d probably have like $10 by now.  I guarantee there is some absurd, repetitive task that you have to complete on a regular basis that can be automated with a relatively simple Python script. For these everyday routines, there is also very likely a standard library module that can aid you in your endeavor. Relevant xkcd:


Maybe you work in an office and have a tedious spreadsheet task you have to complete on a regular basis. Automate it with the csv module. Perhaps you’re in a band and hate writing up set lists, write a random set list generator with the random module. Maybe you like sports or finance, and are constantly looking up scores or quotes. Write a command line app to grab them from your favorite online source using urllib without having to open a browser.  If you’re a news junky, you could consider writing your own RSS headline aggregator with urllib and one of the XML modules. The possibilities are literally limitless. 

Last but not least, as a beginner Python programmer, you will most definitely want to begin checking out the many great frameworks that have been built around the language.  "A software framework is a universal, reusable software platform to develop software applications, products and solutions," says Wikipedia. At the most basic level, a software framework is a library or set of libraries that provide generic functionality for routine tasks to aid in the development of applications and programming projects. In the Python universe there are tons of frameworks to explore, such as web frameworks for the development of web applications, GUI frameworks for development of graphical user interfaces for desktop applications, and so on. Some of my favorites:
Well, that concludes our tour of some noteworthy landmarks in the Python programming space. As always, feel free to provide your own favorite resources or suggestions in the comments.

Unit Testing and Test-Driven Development in Python

There are both advantages and disadvantages to being self-taught in any given discipline. In certain cases, the advantages and disadvantages can overlap or even coincide. For example, when you are self-taught, you are not confined by institutional structures and courses of study. On the one hand, this allows for a distinct measure of freedom to pursue one’s own interests in the field, which would not necessarily be afforded to a person following a traditional disciplinary curriculum. On the other hand, this also means that it can be quite easy to develop gaps in one’s basic knowledge of the discipline, for the simple reason that these areas of study did not fall within your area of interest.

I discovered one such gap in my study of programming in general, and Python in particular, a number of months ago when I came across a quote online that went something like this: “Code that is not tested is broken by definition.”  Testing? “You mean running the code to see if it works?” I thought to myself. Within the next hour I had my first exposure to the method of test-driven development and the Python unittest module.

This was literally the exact opposite of how I had approached my own programming projects up until then, which might be termed “error-driven development”: write some code; run it; see if it works; if it doesn’t work, tinker at random until it does; write some more code and repeat. I quickly realized that, according to the above quote, all my code was broken, by definition. 

The test-driven development model is the reverse of this: write a test, run it and watch it fail; write some code to make the test pass; refactor; write another test and repeat. It was an enlightening experience to attempt writing even a simple program under a test-driven model, as it was immediately obvious that I had only the vaguest notions about things that I thought I knew fairly well.

Since then, I’ve re-written a number of programs I’d created for myself under a completely test-driven developmental model, and have integrated testing into my everyday coding practice. I’ve also collected a bunch of resources that I've found helpful along the way, which you can find below. Also, as you may know, of late there has been something of a controversy brewing on the merit and value of test driven software development. Some links on this are supplied at the end. As always, further recommendations are welcome in the comments!

Overview of Test-Driven Development (Video Lectures)

Unit Testing in Python (Video Lectures)

Python Unittest Module Docs

Python Unittest Intro Tutorials

Test Driven Development in Python

Unit Testing Today

An Interview With Al Sweigart, Author of Three Introductory Books on Python

Albert Sweigart is a software developer who lives in San Francisco.  To date he has published three introductory books on Python, all of which can be downloaded for free from his website Invent With Python.  Readers may recall the review of his most recent book, Hacking Secret Ciphers with Python, that I posted here last month, which was one of the most popular posts to date here at the aGupieWare blog.  Over the weekend, Al was kind enough to answer a few questions via email for an interview.  

Q: First, thanks for taking the time for this interview. Could you tell us a bit about yourself and your programming background? 

A: I started programming in BASIC when I was in the 3rd grade, which I always hate to say because it makes people believe that you have to start programming at a young age to become proficient in it. All of my programs up until college were pretty much variations of the same program. I didn’t really teach myself all that much, and these days anyone could do in a few months what I did in those several years.

Q:  You've published three introductory books on Python, all of which are available on your website inventwithpython.com.  The first two, "Invent Your Own Computer Games with Python", and its sequel, "Making Games with Python and Pygame," are geared toward kids, while the third, "Hacking Secret Ciphers with Python," seems to be intended more for an adult audience.  How have the three books been received? 

A: Altogether, the books seemed fairly well received. I was surprised that people liked my first book, which led me to continue writing. The Amazon reviews are almost exclusively 5 and 4 stars, and I get an occasional Thank You email from readers. “Hacking Secret Ciphers with Python” is probably a bit much for young kids, but I think teenagers and adults would be able to digest it.

Q: Do you see the cryptography book as a step in a different direction, or as an extension of the puzzles and games introduced in the earlier works? 

A: I saw it as a different direction. Video games are a great way to get people involved in programming, but I wanted something else as well. I noticed that there were a lot of code and cipher books that talked about the classical ciphers the book covers, but very few that explained how to break them and none about how to write programs to break them. I saw it as an opportunity to reach a broader audience. The book itself is also aimed at people with absolutely no prior programming or cryptography experience.

Q: What has drawn you to python?  What do you think are its strengths and weaknesses?   
A: Python is a very readable scripting language. Unlike Perl which has very obtuse use of punctuation characters for different language features, and unlike Java which has an overwhelming amount of boilerplate code, Python seems to be a very direct, “get it done” language. It also has a very gentle learning curve. I’ve written a blog article before about how Python isthe new BASIC.  I use Python for both my own software projects and for teaching programming. At this point, I’ve become so accustomed to Python and its idioms that I’m afraid I’ve become blind to its weaknesses, so I really couldn’t think of any.

Q: What are your favorite python modules?

A: Pygame is excellent for creating games and 2D graphical applications. I’ve written a couple modules that work on top of Pygame called Pygcurse and Pyganim, which add a curses-console for text games and sprite animation, respectively. Lately I’ve started using Requests and Beautiful Soup for downloading and parsing web pages for my Python script. (I’ve written a simple Reddit bot that automatically checks several different web comics and posts them to the r/comics section of the site.) I have some experience with wxPython for creating GUIs for traditional desktop apps, but I’ve heard good things about Qt bindings for Python as well.

Q: Do you currently have any new python books in the works?

A: I’m writing a new Python-for-beginners book with NoStarch Press, which tentatively has the title “Automate with Python”. I’ve described it as “a programming book for people who don’t want to become software developers”. I noticed a lot of office workers, administrators, and academics do a lot of computer-based tasks that involve a lot of mindless, repetitive clicking or compiling of data. This book aims to teach them just enough programming so that they can automate these tasks. It covers basic Python, and then goes into several different modules for text parsing, web scraping, moving and renaming large amounts of files, updating spreadsheets, or sending automated emails and text message alerts. I’m hoping to have it available by summer of 2014.

Q: You accept bitcoin donations through your website.  Have you worked on, or are you currently working on, any Bitcoin related projects?  Can you speak to the intersection of Bitcoin and Python? 

A: I had only added it to the site after other people on the internet suggested it, but I’m glad I did. As with many people, bitcoin had been in my periphery for a while. But setting up the wallet for the donation link forced me to learn more about it. Although as of yet I haven’t worked on any bitcoin projects (if anything, the Tor Project will get my focus once I’ve finished the next book). But for all the negative publicity that bitcoin gets regarding its use to buy drugs and illegal things (all of which, by the way, can apply to cash) I’m really excited about it. It allows minors and people in third world countries to conduct commerce over the internet, and that is a Big Deal.

As to Bitcoin and Python, I think that having a new ability to receive and send money over the internet without middlemen (e.g. Visa) along with open source software like Python really lowers the barrier-to-entry for software development outside of America and traditional software-producing strongholds.

Q: Like your other works, the cryptography book can be read online or downloaded for free.  But if a reader purchases it, you donate all proceeds of the book to the Electronic Frontier Foundation, Creative Commons and the Tor Project.  Why did you decide to donate the proceeds for the book on cryptography?


A: It was the suicide of Aaron Swartz, to whom the book is dedicated to, that made the decision for me. I hadn’t met Aaron, though I have friends who were friends of him. His passing was a tragedy, but also a wake-up call for myself. Looking at his life really made me start looking at mine and how I wanted to make contributions like he had. At the time I was, after two years of off-and-on writing, a couple months away from finishing “Hacking Secret Ciphers with Python”. The other books were selling well, and I had a day job that gave me a comfortable middle-class lifestyle. So I decided that I would turn the proceeds from the books over to help organizations that are doing some really wonderful and necessary things to protect the internet.

Q: What advice would you give to young and not so young beginning programmers?  


A: My main piece of advice is that you suck at coding and will continue to suck for the rest of your life. Once you’ve accepted that, you’ll be able to move on and write some interesting software. Don’t worry about the nagging feeling that you aren’t good enough or know enough, because that feeling will be permanent no matter what you do. And if it doesn’t, it’s because you’ve given up on forcing yourself to learn new things (which is the real danger.)

Also, you’re never too old or too bad at math to learn to code. Most programming doesn’t even require mathematical knowledge beyond arithmetic, and unless you’re in your sixties or seventies you aren’t even too old to become a professional software developer. Programming isn’t something that requires you to be a super genius to do. More than anything, having an interest and motivation to act on that interest is all you need to be set on the right path.

Q: Thanks for taking the time to answer our questions!

Book Review: Hacking Secret Ciphers with Python

Hacking Secret Ciphers with Python is a free introductory textbook on cryptography, computer programming and the Python programming language written by Albert Sweigert, a software developer from San Francisco.  Hacking Secret Ciphers with Python is Sweigert's third book on Python, and the first that teaches the programming language through cryptography and traditional cryptographic protocols.

Published under a creative commons license, the work can be read for free online, downloaded as a .pdf or purchased from Amazon, with all proceeds going to the Electronic Frontier Foundation, Creative Commons and the Tor Project.  From the book's description:
“Hacking Secret Ciphers with Python” teaches complete beginners how to program in the Python programming language. The reader not only learns about several classical ciphers, but also how to write programs that encrypt and hack these ciphers. The full source code is given and explained line-by-line for ciphers such as the Caesar cipher, transposition cipher, simple substitution cipher, multiplicative & affine ciphers, Vigenere cipher, and hacking programs for each of these ciphers. The final chapters cover public key cryptography and the modern RSA cipher.
Clocking in at 416 pages, the book is broken down into 24 chapters covering virtually everything from the ancient Caesar Cipher to modern public key cryptography.  It thus provides a practical overview of the history of cryptography, while simultaneously introducing the reader to progressively more advanced aspects of the Python programming language. 

The book begins at the beginning, showing the reader first how to create rudimentary ciphers with paper and scissors.  It then gives a quick introduction on how to install Python, how to work with the interactive shell, and provides a quick overview of Python basics before jumping in to its first major coding chapter on the Reverse Cipher.  For each cipher covered in the book, it provides the Python code to run that cipher, followed by a chapter covering a second program that can be used to hack that cipher.  Python basics are covered in the analysis of the code used to create and then hack the given cipher.

Highly recommended for beginner to intermediate Python programmers who are interested in cryptography.  And since it is available free online, you can dive right in.

Online Learning: Three Free Introduction to Computer Science Courses

These days, with a bit of perseverance and discipline, it is entirely possible to receive a world class education in computer science for free online from the comfort of your own home.  Many of the top computer science departments at US universities make their course lectures and materials freely available on the net, providing motivated individuals with a range of choices that is almost unbelievable in its scope.  In this post, we'll take a look a three Introduction to Computer Science courses that have been made freely available online from Harvard, MIT and Stanford.  The Harvard course provides an introduction to C, PHP and JavaScript.  Stanford focuses on Java. And MIT utilizes the Python programming language. 

Harvard's Intensive Introduction to Computer Science
Course site and description:
This free online computer science course is an introduction to the intellectual enterprises of computer science. Topics include algorithms (their design, implementation, and analysis); software development (abstraction, encapsulation, data structures, debugging, and testing); architecture of computers (low-level data representation and instruction processing); computer systems (programming languages, compilers, operating systems, and databases); and computers in the real world (networks, websites, security, forensics, and cryptography). The course teaches students how to think more carefully and how to solve problems more effectively. Problem sets involve extensive programming in C as well as PHP and JavaScript.
Stanford's Introduction to Computer Science and Programming Methodology
Course site and description:
This course is the largest of the introductory programming courses and is one of the largest courses at Stanford. Topics focus on the introduction to the engineering of computer applications emphasizing modern software engineering principles: object-oriented design, decomposition, encapsulation, abstraction, and testing. 
Programming Methodology teaches the widely-used Java programming language along with good software engineering principles. Emphasis is on good programming style and the built-in facilities of the Java language. The course is explicitly designed to appeal to humanists and social scientists as well as hard-core techies. In fact, most Programming Methodology graduates end up majoring outside of the School of Engineering. 
MIT's Introduction to Computer Science and Programming
Course site and description:
This subject is aimed at students with little or no programming experience. It aims to provide students with an understanding of the role computation can play in solving problems. It also aims to help students, regardless of their major, to feel justifiably confident of their ability to write small programs that allow them to accomplish useful goals. The class will use the Python programming language.  Many of the problem sets focus on specific topics, such as virus population dynamics, word games, optimizing routes, or simulating the movement of a Roomba.

PHP vs. Python vs. Ruby

From Udemy, here's an interesting infographic comparing PHP, Python and Ruby according to a few different metrics:



Programmers Beware: Any Code You Write May Be Used Against You in a Court of Law

From Wired:
In a criminal case sure to make programmers nervous, a software maker who licenses a program used by online casinos and bookmakers overseas is being charged with promoting gambling in New York because authorities say his software was used by others for illegal betting in that state. 
New York authorities say that about $2.3 million that Robert Stuart and his company, Extension Software, received in cash and money orders for licensing his software constitutes direct proceeds of illegal, U.S.-based bookmaking operations. . . .

“It’s overreaching where they’re going after a software developer who sells the software with a legal license, and yet we’re still being prosecuted on how it’s being used,” Stuart says. He notes that authorities have not told him yet who exactly he’s accused of aiding and abetting.
It appears the government is prosecuting Stuart because he refused to be blackmailed by New York State authorities:
Stuart asserts that New York authorities only came after him because they wanted to use him as a conduit to uncover illegal gambling operations in that state. He says the New York district attorney’s office tried to strong-arm him into a plea agreement that would have had him hacking into the systems of his software clients in order to obtain the usernames and passwords of gamblers and their bookmakers to help authorities gather evidence of illegal gambling. 
Although Stuart initially agreed to the terms of the plea, he later recanted because he said he was uncomfortable being used as a pawn to secretly collect information on his customers. He claims authorities are charging him now in retaliation for refusing to cooperate with them.