Saturday, September 21, 2013

Ender's Endeavours

In my experience, not everyone has a favorite book.  Sure, the general population has a generic, societally approved, run-of-the-mill book in the back of their mind for dinner parties or interviews, but hardly anyone has really connected with a book in the same way I have with Ender's Game by Orson Scott Card.  It is the ultimate example of overcoming adversity and rising to a challenge, it paints a vivid picture of its characters, and it offers a powerful message.  It is, quite honestly, the best book I have ever read.

Andrew "Ender" Wiggin, the protagonist, is unwanted by society.  He is a "thirdie", a third child, in an overpopulated not-too-distant future world that permits only two children per family.  He is horribly downtrodden in much the same way as modern-day minorities.  Outwardly meek and small for his age, he is constantly tortured physically and mentally by his peers and his psychotic-but-genius older brother.  In spite of his underdoggish appearance, he is recruited by the military to be a commander in a genocidal war against an alien race known as "the Buggers".  Training proves even worse than normal school.  The other cadets recognize his commanding brilliance and hate him for it.  After many fights and bouts of severe depression, he eventually convinces the entire military organization (fellow trainees included) through his remarkable tactical acumen that he has what it takes to save humanity from the alien menace.  When he is only ten years old he is given command of the military's interstellar fleet and destroys the Buggers' homeworld and is immediately rendered a hero, but he could never have done it without his family, instructors and supporters.

Ender was only able to conquer the enemy because of the people close to him, and this is made evident by how much attention Card gives to almost every character in the book.  Through the use of snappy dialogue, subplots, and sight into each character's mind, the reader becomes intimately familiar with Ender's immediate subordinates that double as friends, his siblings and his instructors.  A good piece of writing should make its readers care about not only the main character, but all of the characters around him; in Ender's Game the reader is moved to care about even Ender's psychotic older brother.  The secondary characters in the novel are astoundingly three-dimensional; it is obvious Card loved them just as much as he loved Ender.  The book is made intriguing because the reader empathizes so well for all of the characters, but the true power and universal message of the novel is revealed when this empathy is cast upon the race that Ender exterminated.

The Buggers are revealed to be simply different from humanity, and not evil at all.  Initial clashes between Humans and Buggers came about because Buggers communicate telepathically and have no concept of writing, speech or any other form of human communication.  Humans feared their nightmarish appearance and ascertained from their silence that they intended us harm; the Buggers drew a similar conclusion and total war was initiated.  Through a stroke of luck humanity defeated the Buggers, but always lived in fear that they would one day return, so we sent a fleet of starships to destroy the Bugger homeworld before this attack could be launched.  The Buggers never intended to attack again when they realized that Humans were sentient and did not deserve destruction, but humanity pressed onwards with no reflection on the nature of their enemies.  Thus an entire race was exterminated because of rash decisions and lack of empathy.  This lesson is applicable in every context, not just in fiction or even in war.  Empathy should always be used before aggression.

A truly great book should hold a timeless lesson, be intriguing and fast-paced, and should have an entire host of characters to care about rather than just one.  Ender's Game embodies all of these parameters and more.  It's underdog premise and sci-fi setting supply a page-turning and remarkably original plot, its characters could all have stories of their own and it teaches us to feel for others.  Ender's game is a masterpiece, and everyone should read it.

Friday, September 6, 2013

Intro to Java

A while ago, I wrote a series of Java tutorials.


To see the rest of the tutorials, navigate to https://drive.google.com/#folders/0B11WQbRQEj5FREllbmJoX2VGaEk.

Python Intro

repl.it
So you've finally decided you want to learn to program.  Or maybe you know how to program but you want to learn Python.  In either case, this tutorial is for you!  This is for complete Python beginners.



Python logo
Before you can write and use any Python, you need to find an application that will run your code.  For expediency's sake I will skip over installing and running Python natively; we'll use repl.it (a free online interpreter) instead.  This guide is written for Python 2, so if you have Python 3 installed just use repl.it.  Navigate to repl.it, click the languages button (the leftmost button in the top right corner of the screen) and set it to Python, then click anywhere in the area of the screen on the right side with the blue background.  Now let's write some code!

To start off, type:
print "Hello world!"
and press Enter.

You should see this:






You just added to a 41 year old tradition and wrote your first Python program!  Well done.
The "Hello World" example illustrates the usage of Python's print statement.  To print a string (a collection of zero or more characters delineated by quotation marks, like "Yolo swag", "hello", "5.24" or "D"), type print followed by the phrase you wish to print enclosed in quotation marks.  Here are some more examples of print:
print "Size matters not - Yoda"
print 42
print "It's a great day to be alive!"
Play around with the interpreter.  See what works and what doesn't.  Try printing numbers, fractions or punctuation.  Try using single quotation marks on strings.

Python (like every other good programming language) lets us save values to variables for later use.  Think of a variable like a box.  A box can hold books, toys or video games and a variable can hold strings, integers and doubles (plus much more).  To save a value to a variable, type a variable name followed by an equals sign (=) followed by the value you wish to save.  For example:
x = 42
Now the variable x holds the value 42.  We can verify this by printing x:
x = 42
print x
You can print variables in much the same way that you can print numbers or strings.  Try the above example, then play around with the interpreter.  Here are some more examples to help you get the hang of the syntax:
the_answer = 42
price = 1.95
userName = "macsj200"
x = price
elephant_name = "Dumbo"
Try setting x to a different string, or a number.  Try creating other variables.  Try setting x equal to another variable.  Try printing variables before you create them.  Use the print statement to see the results of your actions.

Python variables must start with a letter and be only one word, but other than that name then whatever you want.  It is a good idea to get into the habit of giving your variables meaningful names, like speed or priceOfIitem or number_of_cans instead of x or zs.  Food for thought: what is the difference between print x and print "x"?

Click here to go to Part 2

List Comprehensions in Python

Python logo
Why hello there fellow netizens!  It's good to finally have been forced to start a blog because I certainly have a lot to share with the world.  This post will serve to be a short expose on a wonderful feature of the Python programming language (named after the t.v. show "Monty Python's Flying Circus") called List Comprehensions.  It's essentially a severely under-appreciated extension of Python's famous lists.  Before we jump in to the rest of the post, I suggest you familiarize yourself with Python lists using my demo on repl.it or the official Python docs if you don't already know how they work or need a refresher.


Ok, now let's start comprehending some lists! Say we have a list, x_list, that contains [1, 2, 3] and we want y_list to contain the value of each element of x_list squared.  That is to say, we want y list to contain [1, 4, 9].  Python makes this a very easy task indeed.

We could do it the schmuck way with a for loop:
x_list = [1, 2, 3]
y_list = []
for n in x_list:
    y_list.append(n * n)
print y_list

But, of course, Python supplies us mortals with List Comprehensions (a delightfully abbreviated syntax):
x_list = [1, 2, 3]
y_list = [n * n for n in x_list]
print y_list

Both versions print [1, 4, 9], but the List Comprehensions version is indisputably more elegant.  One thing I fail to understand is why the developers decided to make "Comprehensions" plural, but such is life.