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.

No comments:

Post a Comment