September 2018

Python Programming Fundamentals teaser image
This post is a beginner Python developer resourse dump, and also loosely follows the content of Programming Foundations: Fundamentals on Lynda.com except in Python instead of JavaScript. I only recently discovered that one of our many perks as Aggies is access to Lynda.com's video library, when Dr. Jasperson recommended it for ISTM 615 Business Database Systems. Did you stumble on to this post when you're not an Aggie yet? Don't fret, mosey on over to grad.tamu.edu/academics/program-directory or for more information read about our offerings. I was a distance education student myself working full time, and I highly recommend for anyone in a similar situation.

This post was inspired by Hadley Wickham's notion that "Context-switching is expensive." I have found that statement painfully true from my own experiences as well. To quote from his book, R for Data Science,
You will get better faster if you dive deep, rather than spreading yourself thinly over many topics.
Programming Foundations: Fundamentals, chooses to use JavaScript in its examples. I understand how it would be difficult for a beginner to context switch from JavaScript to Python (once the semester starts). I figured since I am learning Python as well, why not document what I've learned as I go? So here goes. Please note that I am loosely following the videos and this is a learning experience for me as well.

To start, I know that not everyone here is going to be in ISTM 615 or an Analytics major. So here are some free, highly recommended Python resources if you just want to learn Python:
  • Python's documentation - an up to date and freely available resource. The secret to success in any technology field? Read the manual! The documentation is almost always the most current and accurate source of information.
  • Al Sweigart's Creative Commons books, most notably Automate the Boring Stuff with Python is recommended often.
  • One of these days I'll do a comparison between his selection.
  • Welp. I take that back. Learn Python the Hard Way USED to be free. Luckily for us we have library access to the full version of the book.
  • While it's not exactly Python, I have seen edx.org's CS50's Introduction to Computer Science highly recommended on the internet among beginner programmers. My favorite thing about the course is it appears to be updated yearly.
Before We Begin: The purpose of this post is supplement, not replace the Programming Foundations course, so the code snippets probably won't mean anything to you out of context. Please follow along with Programming Foundations: Fundamentals if you are going to continue. To run the code snippets, press the green "Run" button to see the code in action. If you open the snippet in repl.it, you can edit and run them to your heart's content. If anyone sees something that they think could be done better or if anyone has other favorite Python learning resources please share in the comments below!
 

Chapter 2: Core Programming Syntax

Reference: https://docs.python.org/3/library/functions.html#input
 

Chapter 3: Variables and Data Types

Reference: https://docs.python.org/3/tutorial/introduction.html
 

Chapter 4: Writing Conditional Code

Reference: https://docs.python.org/3/tutorial/controlflow.html

Chapter 5: Modular Code

Reference: https://docs.python.org/3/tutorial/controlflow.html#defining-functions

Chapter 6: Iteration: Writing Loops

Reference: https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

Chapter 7: More About Strings

Reference: https://docs.python.org/3/tutorial/introduction.html#strings
Regular Expressions: https://developers.google.com/edu/python/regular-expressions

Chapter 8: Collections

Reference: https://docs.python.org/3/tutorial/datastructures.html
See Also: https://docs.python.org/3/library/array.html

Chapter 9: Style Guidelines

Reference: https://www.python.org/dev/peps/pep-0008/
We already talked about Pythonic code. PEP 8 is currently accepted style guide. Brace style is a hotly debated topic and IMO it just depends on your personal preference. Usually a good text editor or IDE will minimize confusion and maximize readability despite your personal preferences.

Chapter 10: Input and Output

Reference: https://docs.python.org/3/tutorial/inputoutput.html
JavaScript is more commonly used than Python in web development (and my preferred scripting language for web dev as well). Nothing to add for the web development section. I'm going to skip this section as well since repl.it is a cloud IDE.

Chapter 11: Into to Debugging

Tracing and commenting are certainly useful. But debug mode and unit tests are so involved that they are their own topic (and even career). I don't know which IDE we will be using in class yet, so no point in elaborating too far. I enjoy Visual Studio Code a lot but it seems like Jupyter Notebook is more widely used in the data science field.

Chapter 12: Into Object Oriented Languages

Reference: https://docs.python.org/3/tutorial/classes.html

Chapter 13 & 14 Advanced Topics

As mentioned in the course, when done well C is incredibly useful for efficient memory management. One of SAS's greatest advantages is its ability to handle big data and large data sets. I recently discovered that SAS is written in C, which would explain its speed advantage over its competitors.
In 1985, SAS was rewritten in the C programming language. - https://en.wikipedia.org/wiki/SAS_(software)

As another example to illustrate these last two lectures, Hadley Wickam, prolific author of wideley used R libraries, published freely available books Advanced R and R Packages. Both books cover techniques that connect R and C++. His libraries (my favorite is a package collection called tidyverse) is incredibly efficient.

To highlight the importance of packages, R will choke/freeze/take forever on large data sets but teams of programmers are constantly working on R to make it better. Matt Dowle et all's library package data.table package reads large files in a fraction of the time using the fread() function.

You may wonder why I'm not using SAS even though I love it so much. SAS is expensive, closed source software that my current employer doesn't own. Regarding concerns that open source R and Python will overtake SAS in popularity... You heard yourself in the video series established languages like Fortran and Cobol are still widely used despite their waning popularity. I anticipate the same will hold true for SAS. SAS has been the industry leader for decades and other languages will have a lot of catching up to do both in infrastructure and maturity. SAS's power and complexity is one of the reasons why it is still the industry standard and a valuable skill to have. Regardless, one can never have too much knowledge. Even experienced SAS programmers will sometimes go to R for certain tasks, and it is beneficial to know the basics of all three of these languages.

Quick learning resource honorable mentions (paid resources), Muarch's Python Programming is oftenly highly recommended as a great Python resource, and it's unfortunately not in TAMU's library. Learn to Code the Hard Way's recently released C programming book has the description Learn to think like the computer hates you, because it does." Which is simply hilarious. You'd understand if you've ever worked with C. I'm notoriously bad at finishing all the programming books I horde but if I ever get around to them I'll definitely write about it.

I hope this post was helpful! I'm also a Python newbie so feedback is appreciated from anyone more experienced.

---
Jennifer Cai
Jennifer is a Masters student in the College of Science's Analytics program.

Related Content

Explore Grad Aggieland

News

Zahra Ghiasi Wins 2024 Three Minute Thesis Competition

After stellar presentations on research ranging from the irrationality of group-thinking to immune system treatments for PTSD, chemical engineering doctoral student Zhara Ghiasi emerged victorious at Texas A&M’s 12th annual Three Minute Thesis (3MT®) competition on Tuesday night.

View All News
Blog

Resisting the Hustle

After talking with seasoned graduate students in my department, I see that most of us carry a sense of urgency regardless of where we are in the program. I was working inefficiently by pushing myself past my wall of productivity to prove to myself that I was working hard to earn my keep. However, after digging a little deeper into the colloquial understanding of the hustle, I see where my rigidly negative view of hustling hindered my ability to make peace with myself.

View All Blogs
Defense Announcement

High throughput phenotyping in sugarcane using an unoccupied aerial systems

View All Defense
Announcements