Friday, November 20, 2009

Linux = freedom : part 1

I finished the programming assignment I gave for myself and realized that I really needed to update my blog.

so I just typed into the console, "firefox www.abstract-code.blogspot.com"

and whoop, there I was!

If I was on Windows, I'd have to have double-clicked on firefox, go to my homepage, and then type in my webpage. This might have meant minimizing whatever I was doing at the time, which takes more precious seconds.

People complain about computers trapping them into working more and having less free time to do what they need. However, I don't think the computer is the culprit, Well, it is, but it's not the system itself so much as it is people's unwillingness to seek out and learn how to free themselves of the shackles technology has placed on us.

Technology is created to free our lives. Unfortunately, so many people feel one must be truly gifted to understand and use technology effectively, that they settle for less useful, but more intuitive versions of it, for various reasons. They're not happy, but they feel a need to use it, so they stick with it.

I wasn't much of an exception. While I had access to DOS as a kid, I never used it much. A GUI where I could click around in was a lot simpler, and my own personal reasons for using Windows for so long was because I was never exposed to anything different. My exposure to linux came in college, where so many people used it that I decided to give it a shot. I played with it for awhile, then went back to Windows.

But Windows is very limiting in its power. It's useful, but I feel that I can do more in linux with a few basic commands than I ever was able to in windows.

For example

cd folder1 ; mkdir folder2 ; cd folder2 ; mkdir folder3 ; cd folder3; touch file.txt ;

is a series of commands goes into a folder, makes a folder, goes into that folder, makes another folder, goes into it, and then creates a text file.

There's another way to do this

such as

mkdir folder1 ; mkdir folder1/folder2; mkdir folder1/folder2/folder3; touch folder1/folder2/folder3/file.txt

that seems to be faster, and accomplishes the same thing. Except that you're not really moving anywhere in the system (to do anything in windows, it seems, you have to be in that location physically). Being able to do this is pretty amazing to me because it's a lot faster and a lot less clicking. I feel like I'm actually in control.

Make change in your life

Currently Reading: Data Abstractions and Problem Solving with C++: Walls And Mirrors (fourth edition)

I just finished reading the first chapter of this book, and did the first programming exercise it wanted me to do (the fist of two or three I will do, likely), even though I had a basic idea of how to solve it because I actually did write this before.

The problem is to write a function that computes the change a cashier needs to give to a customer. While this is something given to any first year CS student, because it is an awesome way to test a student's division and critical thinking skills, as well as his ability to code leglibly, it is also a real world problem because depending on where a cashier works, it is his till that might be handing out change. Some stores have self-checkout, and with the popularity of cash, not only must a computer register which dominations of coins to give change to, but also what denomination of bills to give change in.

I've solved this problem three times. The first time it was in illegible piece of shite that while I understood it while I was making it, I honestly couldn't understand it today even if I tried (and I have). Granted, I was a first year CS student at the time writing spaghetti in Java and calling my shit gold because it worked. I probably hadn't been coding for more than three months at the time. The concept of maningful variable names or well thought out code was unknown to me at the time.

The second time I solved it was when reading this book the first time (I had gotten to the end of chapter 2 before school got out), and I solved it for change, but not bills, and had used a different function for each computation, when one function would have done just as well. It worked. Except change for anything other than coins was given in a lot of coins. What I mean is that the second version would give 70 dollars worth in quarters when the person should get back a 50 and a 20.

The third time I solved it right, I think, because it includes bills and coins. I know the first one did this too, but it wasn't very well written. Actually, solving it is a simple task, requiring only a few steps

1) Take the amount owed and divide it by the value of the denomination (e.g. $75 / $ 20 = 3).
2) Subtract the denomination, times the quotient from the amount owed. This becomes the new amount (e.g. new amount = $75 - ($20 * 3).
3) Repeat step 1 with the new amount and the lower denomination (e.g. $15 / $10 = 1) until you reach the lowest denomination (which for Americans, is pennies. Unless we do away with them, and then we've fucked ourselves basically).

Design questions of course could be how to handle the data coming in. Since money consist of dollars and cents, it is common to think of handling money in terms of a float (32 bit number that can hold a decimal value, like 2.75, or 1.69, or 13.37, as opposed to integers, which are whole numbers), but this can be prone to roundoff errors and loss of precision. Another way to think of money is in terms of whole numbers, where a penny is 1, and a hundred is 10,000. I suspect this is how modern systems that handle cash deal with money, and while more complex to deal with, it offers a few advantages in that it would be less prone to errors (I remember the first time I solved this problem, I had to add 0.003 to the number just to make sure the correct amount of change was given, every time) because both dollars and cents are being treated as the same data type (in this case, ints, or whole numbers), which would mean the possibility of truncating a float's decimal value when converting to an integer would go away, and the problem is reduced to one of simple place-value.

Wednesday, November 18, 2009

It took me long enough

From about May until November.

Five months.

I got out of college and took a shit job for minimum wage. A job so easy that they hire retarded people to do it. The lack of mental stimulation combined with a high amount of stress from failing college shut my brain down, and when it woke up, it woke up to a hell that it determined to get itself out of.

It's very close to that now. I have a new job, which is ever more stressful but also mentally challenging and well paid. If I was full time I could be out on my own. I've also been slowly getting back into programming. I feel like I've forgotten a lot, but I know if I keep working at it i'll be able to dive as deep as I was in before college let out, if not go further. I don't want to be stuck doing shit jobs for shit pay for the rest of my life.

I did a few programming exercises from www.javabat.com today, and one from a programming challenge website. The problem is there are uninteresting, and reading my beginner C++ book is leading me to things I already know.

I know there are things I've forgotten, but there's a lot I still know how to do.

When I was in college, I was slowly working my way through a data structures and algorithms book. I have decided to pick up this book again, and start from the beginning. I haven't read but a few pages yet, but I think this is where I need to be. If anything is unfamiliar I can use the internet. There are also a lot of other textbooks I've picked up that I need to read through, as well.

Introduction

My name is Chris, and this is my programming blog. I run one other blog here, which is a personal one.

I have been a programmer for two years. One year in high school, where I studied Java, and another year in college, where I studied C++. In High School, learning programming sucked. While I have always been a very careful speaker, programming languages demand a level of rigidity in expression that is not found in the modern languages we speak today. Getting used to the rigid syntax was the biggest hurdle I had faced, but once I got over it everything got easier.

In college, I learned C++. The first semester of college was boring because the syntax, while similar in most cases to Java, requires a different method of thinking but offers several advantages that Java does not. It is these advantages that allow me to express myself simpler than Java could, and I eventually saw the raw power of expression that C++ has that Java does not and fell in love with the language.

This is not to say that Java is not beneficial. Arguably, it can be easier to learn, and use. Perhaps the reason it's more widely used is because it's safer. While abstracting pointer manipulation out of the hands of the user takes away a lot of power, the security in not possibly accessing data that the program is not supposed to (and either crashing, or altering something important, or reading in garbage, or any other problem that illegally accessing a memory address can lead to) can be quite an advantage to business applications that must run stably.

My first semester of college was boring. I had been through java, and was essentally learning to do in C++ what I already knew how to do in Java. I passed with an A. The final exam was 2 or 3 free-response questions on a fresh mind with 2 hours to think. The final exam in High School was 4 free-response questions with an hour to think on a mind that just finished churning over 45 multiple choice questions, and the AP multiple choice questions are not easy.

My second semester of college saw me learning new things, starting from the simple and moving on to to a level of complexity that was too much for my mind to process, and so I took a break to wonder if this is what I really want to do in life.

I didn't look at code for about three months after college got out, and when I looked at some, in boredom, the sudden mental stimulation that I realized I was missing made me depressed, and I vowed to get back into the game, and that is what this blog is all about.