Subscribe. Follow. Stalk.

Monday, June 24, 2013

Java vs Objective C

I often get the question: What is the difference between Java and Objective C? Well, I then give the same explanation I've given people over and over again... :/

They really are quite similar. Once you know one the other one comes to you quite easily. But they do have their own quirks.

  • Java is static. Objective C is dynamic. Basically, Java is a control freak bureaucracy that makes sure everything at compile time is ready to go. I won't say the same about Objective C
  • Objective C is based on C. Pretty obvious, but has some pretty annoying implications. Pointer problems, memory leaks and whatever else that you hate about C will likely apply here.
  • Objective C classes need more than one file (header + implementation). Kind of annoying at best. Really annoying at worst.
  • Objective C has categories. Remember how I said Objective C was dynamic? Well, you can even add methods to pre existing classes w/o the need to subclass
  • Java is garbage collected. Honestly, the time saved from finding annoying memory bugs is worth the overhead for GC.
  • Java can be compiled and run anywhere. I don't really care for this one, but it is a difference between the two.

Thursday, June 20, 2013

How to pronouce char

Throughout all of my life I was intent on calling 'char' as char (rhymes with bar). I few months ago a heard someone say 'care'. It was the most horrifying moment of my life. I didn't know what to make of it. How could someone say something illogical!? Anyway, I didn't really care, but I still maintain that my pronunciation is better.

Here's why...

  • Charred. That burned blackened stuff. See? Nobody said care.
  • Char star (non-C people won't get this) Care star sounds like it belongs in a pink pony book.
  • Char sounds like slang for 'character'. But characters != char. Char is a numerical value, while character is something dragged out of some (human) language.

I also know people who pronounce char like 'car'. Those people don't bother me as much as the ones who say 'care'. Anyway, I wrote this blog post mostly because I didn't know what else to write.

Wednesday, June 19, 2013

Linux is great. Linux is high maintanance

Ok. So I've used Linux on and off for roughly the past ten years now and I have to say that while Linux is a bit better than it used to be, I find that using windows is a much better experience. That being said, I prefer the bash shell to whatever that cmd crap is. Honestly, the biggest annoyance of Linux in my mind is maintenance. For some reason or another, I have never had a successful installation of Linux (except Fedora 13) where it didn't freeze up on me and I would have to restart gnome.

A few years ago I thought my solution to this was to use a mac. After all, they couldn't be as unreliable as linux and it would be nice to have a shell that behaves more like the ones in linux distros. Sadly, that didn't work out too well (hardware randomly started failing... I felt each event was like a mini heart attack)

So here I am back on windows. I now ssh into my VM whenever I want to use a linux box. To make my own physical box closer seeming to windows, I use cygwin. The installation thing is kind of strange to use but it works well and I'm happy.

Saturday, June 8, 2013

Learning Java Part 0

This is going to be part 0 of a three part series. I hope everyone learns why I chose to start with 0 rather than 1 by the end of the series.

Java. It's everywhere. In phones, robots, and toasters. Most of the challenge with learning a language when you've never programmed before is the underlying logic and the strange subtleties of the syntax. That's why I'm not going to teach general syntax first. Instead, I'm just going to go over a few language constructs that are commonly seen in nearly any language.

Variable - something that stores a piece of data. Variables often come with types that tell the computer what kind of data that you are storing. Some of the types include

int - for most intents and purposes, treat this just like you would if it were a regular integer
double - it can store values with a decimal point. 123 or 12.3
boolean - only has two values: true or false
Object - stores a object reference. We will look at objects more in depth on another day

These are the four data types that you will work with the most when programming. There are a lot more that I have not mentioned but they are not hard to learn. Generally speaking, you can do math on these operators such as + - * /. You can also find the remainder using %, which you will hear some people call mod. The order of these operations follows PEMDAS, so use parenthesis if you are unsure that your ordering is correct

Here are a few examples of variables...

int a; // The '//' tells the computer to ignore what goes after it on that particular line. This way you can comment your code.
/* both of these are commenting styles
This one can span multiple lines */
double b = 1.7; // we can also set values to these variables
boolean c;
Object d;// Notice the semi-colon at the end of each line, this tells the computer where one instruction ends and where the next one begins

Great, now that we have figured out variables, lets go on to two basic constructs: ifs and loops

Before we can start talking about ifs and loops, there are a few things we need to clear away first. Remember how we talked about boolean? Well, it turns out that boolean is actually pretty important. There are times when we want to test whether something is true or false, such as testing if int a is equal to 5.
The most important boolean operators you will need to know are these:

Equals ==, it has two equal signs because the single equal sign = is used for setting a variable.
Not equals !=
Less than a < b This returns true if a is less than b
Greater than a > b This returns true if a is greater than b
Greater than or equal to >= same idea
Less than or equal to <= you get the point.

AND &&, this returns true if both conditions are true
OR || this returns true as long as either condition is true
NOT ! changes from true to false and vice versa

Here's how if's work.
if (something here is true) {run this code}

Sometimes there might be else attached. This is optional and run when the condition is false
if (something here is true) {run this code} else {run this code instead}

Here are some examples:

 int j = 2;
 if (j == 3) {
 // this code will not get run because j is not equal to 3
 } else {
  // this code will run!
 // carry on with rest of program
 int d = 5;
 if (d == 5) {
 // d is equal to 5, so this code runs!
 // carry on with rest of program

Hopefully you can now see how easy this is. Lets move on to loops..

There are two kinds of loops that I want you to be familar with: for and while use them when you have code that repeats itself

I've gotten addicted to this song