Thursday, June 30, 2016

Python Packages, pip, and Other Perplexing Problems

I finished the course on Treehouse about using timezones in Python. Don't get me wrong, it is a good course. I can't say I like using workspaces (Treehouse's IDE) but I can see certain benefits of using it when starting out. So far I have been using PyCharm while following along with Treehouse and for my current Python coding projects (Hockey Shootout). I have no problem with JetBrains, although I hear Sublime is very good.

That sounds like it should be a discussion about bands...

Anyway, everything was progressing fine until the course said to use the pytz package which was already installed on workspaces. The video started by saying how to install it if not using Workspaces. Problem is the instruction was showing on the screen a single command to type to install it on your local machine. Understandably I went to the Terminal (I use a 2014 MacBook Air with El Capitan) and typed the command. Obviously that didn't work. I Googled "pytz install" and ended up downloading a .egg file from Python's website that was mentioned on another website (likely StackOverflow).

Countless Google searches later about errors I was getting I found myself stymied by this pip install that was so simply referenced in this Treehouse video. Some searching on my machine led me to find why I think this is so difficult. I used to use a Windows machine I bought so I could mess around and try programming. Once I tried some SQL and discovered the queries ran twice as fast on the Mac I quickly transferred and forgot about my Windows laptop (save for loading the original Starcraft and playing that for a bit). I remember programming on my Windows machine last year using a book on Python. The book used a graphics library in its lessons to demonstrate some principles. That was very simple. Download the file and save it in the folder with the other preinstalled Python libraries. From there it can be imported in the code. That is not the case with my Mac. At least not within my current computer understanding.

Python 2.x is preinstalled on my Mac. Some time ago I downloaded Python 3.x and that's what I use with PyCharm. Because I read not to uninstall Python 2.x from my computer I aliased Python 3.x in the Terminal and access it using 'python3'. Everything had been going swimmingly, that is until I tried installing this elusive pytz package. I never heard of a .egg file but I think it's what I need. I tried so many commands in the Terminal to install this package, all to no avail. Things I read on StackOverflow do not seem to work as their suggestions usually do. Commands such as 'python3 -m pip install dir/file'(and so many more) always come back with errors. Apparently I also have an outdated pip. I still have no solution.

I am ok with not understanding this. I don't fully comprehend timezones, and not just when it involves programming but that's a different story. I completed the course and am moving on to the next (regular expressions...). When I need dates and times in programming I will try harder to get it and I think I will be able to use them. I know when I start using Python databases it will surely be necessary to know how to use datetimes.

Thus this post is mostly how I've accepted that there are some things I won't understand. It is my impression that it is ok not to understand something. It reinforces the fact that there are many things I don't know and no-one has a monopoly on knowledge. I will draw on my lack of knowledge to bolster my motivation to continue learning.

25 words or less: When something causes too much frustration learn something else and return later to reexamine the problem with fresh eyes and a fresh mind.

Thursday, June 23, 2016

What Developing Means

This post is written in the context of myself working on coding projects alone (and with the help of things like Stack Overflow and Treehouse). I have never worked on a software or web development team and thus cannot write about how that process would work. I think though that the underlying principles would transfer.

For awhile now I never thought much of certain terminology. To me programming, coding, and developing could all be used synonymously, as well as those words' noun counterparts. The past few days, after working on my hockey shootout game more extensively, I have realized that development (of a program) is different, though not totally independent, from coding and programming.

The definition of develop is "grow or cause to grow and become more mature, advanced, or elaborate." Like people. We develop and grow both physically and mentally eventually optimizing ourselves for specific tasks, just like a computer program does. (Not to get all Matrix-y on you)

That makes perfect sense in relation to what I was doing! Previous projects I created, such as a way to organize parts I ordered for work and a simple bouncing ball program, I think I tried to write the whole program at once. I thought of the program as one giant thing and not many smaller parts that worked together to solve a problem. I believe approaching those tasks in that fashion caused me to not understand development the way I should have. As I worked through the hockey shootout game things changed.

I realized that the overall game was made up of many smaller parts. Various functions that performed certain tasks could be called from a main function that would call them in the correct order and frequency. For example in my game the first thing needed is to ask if the user wants to play so I wrote that first. For a short amount of time all the program did was accept the input if the user wanted to play or not. It then had to verify the user entered a 'y'. Then it had to ask what player you wanted to use. To do that there would have to be players to choose from. Thus I had to make a player class that would initialize different players with specific attributes. And so on and so forth.

Continuing to create how the game would function and thinking of new features showed me the value of Trello. I learned about Trello through Treehouse but I didn't realize fully how to use it until I was working on this latest game. As I thought of new features to add I could record it on my Trello board and I could visualize how the game would develop, or become more advanced. I could then sit down later and write it into the program. Thus I continued to add depth to the code, such as a way to select two players instead of one where player two would be the goalie, a way to increase a players stats through using different equipment (its own class), and a way to have a computer goalie make its own moves when a one player game is played.

So what started as one input from the user developed, grew, and became more elaborate. And I was the one that caused that growth.

I think the Karaoke Machine project from the Java course on Treehouse highlighted this process well. The teacher used a Trello board to document what he needed to do, what he was doing, and what had been done so he knew what the program would need to develop and what stage of development it was currently in. It continued to grow. The program would need a song and record aspects of song such as the title and artist. Then it would need a whole songbook, or collection of songs, have a way to add a new song, a way to see the whole songbook, and select a song that someone wanted to sing. He "developed" it.

I think that is a good lesson that course taught and I didn't realize it until I wrote my first program in a way where I could say I actually "developed" it instead of trying to write it all at once.

I realize maybe I should have understood this sooner but I think it's a good point for a new programmer to recognize early. You can think of the end goal of what you need the program to do, but it is usually too difficult to write all at once.

A journey of a thousand miles begins with one step.

I plan on uploading my hockey game to Github soon and I will post on here when I do. I think I have it complete, save for a few features I would like to add but don't know when I will add them.

25 words or less: Write a program piece by piece and build on what you have. It's easier to start small and grow than writing it all at once.

I realize I bent the rules by using a contraction, but I still think it was as succinct as possible.

Thursday, June 16, 2016

Python's Simplicity

I did not post last week, but for good reason. I was involved in some volunteer work that took some planning and forethought so that took up most of my time near the end of last week. Thus I was not able to post here. I was also not able to program either as so many other necessary things required my time, not to mention Stanley Cup playoffs. Go Pens! (I was born and raised near Pittsburgh)

I will admit I had a little programming withdrawal...

So what have I been doing these past two weeks then? I wanted to try my hand at a simple text based RPG. I have been learning Python again so I was thinking of trying to write the program using Python. However since I more recently got into Java I thought I would attempt using it instead. Failure ensued that endeavor.* It seems the two weeks or so I was removed from Java learning (and the re-inputting of Python syntax into my brain) had caused some confusion as far as how certain objects and things interact with each other in Java. So I thought I would just use Python. Here are two things I noticed are more simple in Python. (I don't think simple is the right word)

-----------
User Input
var = input("Input something: ")
Python is quick. You just assign input from the user to a variable and that variable becomes a string of what is entered. Apparently that was upgraded from Python 2 and there is no longer a need for using raw_input. That confused me for a little when I was searching on Google.

Java is more detailed. You must have a scanner or buffered reader imported and it takes at least two lines instead of one. You must have a System.out to show a line of text, then the scanner or reader and readline to get the input from the user and assign it to a variable. I know the details for this are not exact, but it helps to know that more is needed for input when Java coding

-----------
Variables
var_list = ['one', 45, [4, 3, 2], True]
Python does not care what type a variable is when it is assigned. It will recognize it itself what kind of variable it is. I used the above example because this shows a list can be any length and be of any type.

int[] var = new int[5]
Java requires variable type declaration and, for lists, list size declaration. I believe there are ways to adjust the size, even later making it larger or smaller without pop(), but that would require a little more searching on Google.

I am not criticizing or praising either of these languages. I like the precision and the memory allocation in Java. The usage of public and private variables for classes is also vary beneficial. Python's simplicity cannot be underestimated. The writing and debugging is supremely easy to follow. However I'm not totally sure how to allocate the memory better in Python. Will have to research that more at some point.

I know there is no revelation here but I hope this serves as a kind of reference for me if I want to try my hand at Java coding later. At least a more detailed reference than my last post about some differences between Python and Java.

The simple RPG I am writing is a text based hockey shootout. More on that later and soon I will upload it to Github but I want to tweak it some more before doing so. My biggest struggle was how to get a random key from a dictionary. I eventually just searched and copied and pasted some code from Stack Overflow.

25 words or less:
I am going to stick with Python for awhile.

* Failure is not a bad thing, especially in programming.

Thursday, June 2, 2016

Back to Python and my first GitHub commit!

As a quick update to last week, I did upload my first project to Github. It still has work to be done on it, but I hope to expand on it soon.

Anyway, I recently found out a place I would love to work uses Python for much of their software. They produce a lot of animation, among other audio/video products, and many other things. So I decided to revisit Python. Just watching the introduction video on Treehouse and what Python can do helped me understand why this place uses Python for animations, etc. Thus I began the Python track on Treehouse. And a little bit of Javascript, still really need to learn more web development.

Many things are a review as I went through almost a complete book on Python. Things such as data types and methods are all things that came back to me quite quickly. I don't, however, remember some of the things discussed being in the book. So it is nice to have some new methods for certain data types. Things like using .pop() and .remove() on lists seem to be useful. Also having someone explain it while I code in the Terminal or PyCharm is nice too.

The differences between Python and what I've been learning in Java have really been apparent now that I am tinkering with Python again. Not having to declare variables and their type is a little difficult to get used to. In some ways I think I'd almost prefer declaring what type they are so as to keep them clearer in my head and maybe easier for someone to read my code. That may become clearer as time goes on though. Also not ending the line with a semi-colon is proving to be annoying as my right pinky finger tends to press that key before pressing the return key. But that is a minor inconvenience when it comes to the simplicity which is Python.

I used to think programming languages were the same with different syntax and I think that's still true to a large degree. However certain things just seem to feel different. It's difficult to describe at this time and may be easier to explain later.

But at this time I will just leave this post since I'm late this week due to being so busy, and committing to GitHub taking a little more time than I originally thought it would.

So 25 words or less:
First commit to GitHub. Python simple. Java more precise.

Less than 10 words! I will try to make a more meaningful post next time. Then I can have more information for reference in the future.