paint-brush
Learning Python the Hard Way - The Why, Hows, and Whatsby@carloocchiena
3,878 reads
3,878 reads

Learning Python the Hard Way - The Why, Hows, and Whats

by Carlo OcchienaDecember 1st, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Python is a general-purpose language that can be used to build just about anything, which will be made easy with the right tools/libraries. Python was invented “for fun” by Guido van Rossum during Christmas Holiday in 1989. Python is an easy and intuitive language just as powerful as major competitors as well as competitors. It has tons of application, and should be relative easy to automate also everyday tasks at work or at home. Python is elegant, readable and easy to understand at first, especially for someone like me that has no solid background in coding.

People Mentioned

Mention Thumbnail
Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Learning Python the Hard Way - The Why, Hows, and Whats
Carlo Occhiena HackerNoon profile picture

“If the implementation is hard to explain, it’s a bad idea.”

1. FOREWORD:

In his “Outliers: The Story of Success”, Malcom Gladwell explains that the difference in learning experience between rich and poor kids in primary schools is not given by the kind of education they receive: comparing leading grades from both lower-income family kids and wealthy one, there’s no relevant difference during first year of school, even taking into account private and public institutes.

But then, starting the second year, things change dramatically: while middle-class and rich kids keep having good grades, poor kids show no improvement in their learning and in fact, their performance dropped.

Reason for that? Wealthy kids are able to learn even during summer, growing in a stimulating environment, having many books to read, being able to travel, attending summer camps, discovering new things and having proficient conversation with adults.

Poor kids, on other hands, spent their summer watching TV and playing with other kids in the neighbourhood. They have an all summer long break from learning.

And once back in school, the gap starts to widen. It’s the so called “Achievement Gap” (you can read an extract of this chapter here).

But does this work just for childern in primary school? Or could be true also for adults? May be the case we are more focused on making holidays plan and chilling than to learn new things?

Avoiding any doubts, I decided to challenge myself, setting the goal to learn a coding language from scratches during summer.

2. WHERE TO START:

My coding skills are basically null. I did some lame experiences with VBA and Matlab when I was like…25 (damn, I’m getting old geez!), so I have to set a challenging but also doable goal.

If you’re proficient in coding, please forgive me in advance; I’m using terms such as “learning”, “understanding”, “competence”, and I’ll surely look naive to someone that spent years properly learning the language. Fair enough!

The best time to learn to code was ten years ago. The second best time, is today.

At first I was oriented toward web development, something like HTML & CSS, or maybe Javascript, but then, after some reads on Quora and other websites, and also thanks to the hints of some friends (thanks Federico and Davide), I finally decided to approach Python.

3. WHY PYTHON:

Python is a general-purpose language, which means it can be used to build just about anything, which will be made easy with the right tools/libraries. Professionally, Python is great for backend web development, data analysis, artificial intelligence, and scientific computing. Many developers have also used Python to build productivity tools, games, and desktop apps” (Why Learn Python).

Python is elegant, readable, and easy to understand at first, especially for someone like me that has no solid background in coding.

Suppose you’re willing to print “Hello World” to your console:

C++:

int main()
{
cout<<"Hello World";
return 0;
}

Python:

print ("Hello World")

Persuasive enough, uhm?

Plus, it has tons of application, and should be relative easy to automate also everyday tasks at work or at home.

https://automatetheboringstuff.com/

Being completely open source, there are just tons of useful resources, tutorials, manuals you can get your hands on for free and learn from.

Do you know that the name “Python” is coming from “Monthy Python” and that the language was invented “for fun” by Guido van Rossum during Christmas Holiday?

“Over six years ago, in December 1989, I was looking for a “hobby” programming project that would keep me occupied during the week around Christmas. My office … would be closed, but I had a home computer, and not much else on my hands. I decided to write an interpreter for the new scripting language I had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python’s Flying Circus).”

In 1999, van Rossum submitted a funding proposal to DARPA called Computer Programming for Everybody, in which he further defined his goals for Python:

  • An easy and intuitive language just as powerful as major competitors
  • Open source, so anyone can contribute to its development
  • Code that is as understandable as plain English
  • Suitability for everyday tasks, allowing for short development times

4. GETTING YOUR HANDS DIRTY:

I am working full time, so I needed to schedule my learning mostly after works in the evening, or at best during weekends. I wanted a practical and effective approach, at the same time preparing to commit to an hard task (learning to code basically means learning to solve problems in a finite environment).

First thing first, I needed to understand the basics. My usual approach is to get a bit of theory first, so I headed to the Python Wiki and read as much as I can, trying to comprehend as more as possible and getting the basic dictionary of the language.

I was also lucky enough to have some friend supporting me along the journey:

Annalisa gave me an invaluable hint, suggesting to install the Anaconda Distribution, together with some advice on how to smooth my dirty raw code! While Davide gave me this book, that was indeed usuful to understand the basic of data analysis.

After this quick introduction to the language, was time to get my hands on code. Among the dozen of tutorials and courses, I started from the one proposed by Codecademy:

I found the course incredible effective: first of all their IDLE ( Integrated Development Learning Environment) is smart and readable. It really helps breaking the ice. Consider that the course is on version 2.7, and it’s 100% free of charge.

Exercises are easy, tailored for beginner for sure, but not stupid or obvious. You have to think and try many solutions before getting the green light from the computer (only one solution is accepted for each exercise, even if many could be theoretically possible). It also include a forum where you can post your question and in ALMOST REAL TIME receive feedback from the community. The people volunteering here are great: they never offer you the solution, but they gave you hints and suggestions, forcing you to think again and finally solve the problem on your own.

5. CREATING YOUR OWN WORK ENVIRONMENT:

After finishing the online course, I feel “competent” enough to install Python on my machine (I’m running on Windows) and try to develop some projects on my own.

Firstly I tried the raw Python install. But I don’t like the work environment.

After this unsuccessful trial, I proceeded with Anaconda Distribution.

Anaconda is a freemium, open source, distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. It comes with Spyder, an incredible effective and easy to use IDE. I liked it immediately:

My work environment on Spyder: so clean and simple ❤❤❤

Aside that, I wanted to have also an online repository for my codes. I picked the most basic yet likeable solution possible: Repl

Repl is a simple online IDE, not just for Python but for many languages such as JavaScript, C++, Ruby, HTML, and more.

I like it since it easily allows me to write, check and share code from any pc and mobile. I’m using it also as online repository for my projects. It’s effective and easy. I like it a lot!

6. WHAT I LEARNED:

0. Surely I haven’t learned “how to code”. That would have been a whole different learning process, I won’t claim this. But it was a very profitable exercise anyway! I also grown interest in Python and in programming languages in general and I’ll likely invest more time in the future to learn about it.

1.Firstly, I learned to read programming languages a bit.

While first, looking at a complex code, I would immediately discharge it, thinking “there’s no way I can understand what’s going on here”, now I’m thinking “ok, let’s see if I’m able to get something out of this mess”.

It’s a bit tricky to explain this, but it’s like I gave myself the “permission” to try to read and understand code. I am at least able to break a complex script or algorithm in little chunks I can understand, or at least search for their meaning on Stack Overflow or GitHub.

This is probably the most valuable lesson I get from the whole project.

2. Learning to code is hard, so, implicitly, I strengthen my problem solving attitude (even better: “the code is easy, it’s solving the problem that is hard”).

It’s a mindset: there’s this problem, and you have to rely on your expertise only to solve it.

Last week, my gf needed help to fix an issue with an HTML string on her website. Usually, I would have searched for a solution straight on Google. But this time, I patiently read thru the lines until I found a little “<” missing. Fixed and solved. It was like Xmas to me that day :)

“It’s not that I’m so smart, it’s just that I stay with problems longer.”

Albert Einstein

3. Then, I was able to develop some little project on my own.

The classic exercises for beginner, but very interesting nevertheless (click on the link to see and try the code on my Repl repository):

4. I spent also some nights on Pygame! Pygame is a free and open source Python programming language library for making multimedia applications like games built on top of the excellent SDL library.

In a week I was able to write my PONG! code…hell yeah! (I also read that a proficient student can write this code in 20 minutes, but ok that’s another story!).

High five for “Carl Pong”! (still have to find a way to beat the computer, I’m always losing!)

7. Ten facts that may ignite a spark on you about Python world:

1. There’s a version of Doom ported to Python: PyDoom. This port has been created and maintained by a girl, Kate Stone :)

2. There’s a random number of Python quests and trivia around the web. One of the most famous, and also pretty challenging, is this one: http://www.pythonchallenge.com/

3. There are tons of website proposing online courses; one of the most famous is https://learnpythonthehardway.org/ from which I also took inspiration for the title of this article.

4. You can find entire threads of people hating on Python.

5. I found, and more than once, terrific Python programs written by kids! Like “looks at this tool for predicting house prices I wrote at age 8”. Ridiculous.

6. Zen of Python is a thing, and it’s also pretty famous.

7. There’s a huge amount of Python pranks around the web. For example this one will make your CD-ROM goes crazy until you kill the application. It works :)

8. Spotify, YouTube, Instagram, Dropbox, as well as Civilization IV are mainly based on Python code.

9. Openstack (the cloud architecture adopted by NASA and CERN) is reasonably the most complex Python code ever: it counts 2'400'000 lines. Good luck for debugging that beast then…

10. But it’s also possible to wrote a very complex algorithms in less than 50 lines: here’s how you can predicting Stock Prices in 50 lines of Python.

8. And what about you?

I liked very much the idea of having a summer goal, probably I’ll have again a similar project next summer.

And you? Do you worked on a special project this summer? Or did you learn something new? Let me know in the comments.

And remember, “it’s not a bug, it’s a feature”. :)

(9.) Edit:

I wrote this article in 2017 for my Medium stream (at the time, I thought Hackernoon was a Medium product, too). So far, some of the statements expressed here may looks naive or redundant. But I believe keeping the original "first time on Python" feel could be of some value for someone trying to start the topic from the very zero point.

Code everyday!! :)