This is where your money is going folks.
link
Sunday, December 28, 2008
Top 10 Outrageous Earmarks
Wednesday, December 24, 2008
Happy Holidays to Everyone!
To my fellow UR bloggers Alex and Evan, I hope you guys have a great holiday -- tell your families 'hello'. To everyone else, happy holidays from the Utopian Realists blog!
Saturday, December 13, 2008
Computer Concepts Part 3
I'm back for Part 3 of my Computer Concepts series. If you missed Part 1 or Part 2, click the links and have a read. Last week I described the role of an operating system (manage resources) and touched very briefly how the OS does this. In this post I'd like to include some basics on functions and algorithms that I'll use to elaborate on how the OS manages resources.
We'll start with functions. A function is a chunk of code, typically written to reduce the amount of repeated code in a program. Let's say you want to display a greeting to the user when they start your program. Let's also pretend that the code looks like this:
print "Welcome to Calendar Program version 1.0"
print "written by [name]"
If every time you wanted to show that menu you had to rewrite that entire snippet, your code could start to become very messy, very quickly. In order to reduce the amount of clutter while programming, programmers often write useful pieces of code into functions, like this:
define show_greeting
print "Welcome to Calendar Program version 1.0"
print "written by [name]"
end
That's it! We defined a function called 'show_greeting'. If you ever needed to show your greeting to the user again, you'd simply call the show_greeting function and it would print the necessary text. Seem kinda trivial? It's not. The beauty is, you only have to define it once then you can call it as many times as you want with just a single line. Many functions are complex, and typically involve calls to other functions. What if we had several different greetings for the different types of users (free version, pro version, premium version)?
define show_free_greeting
print "Welcome to Calendar Program version 1.0 -- Free edition"
print "Your trial expires in 10 days!"
end
define show_pro_greeting
print "Welcome to Calendar Program version 1.0 -- Pro edition"
print "Upgrade to the premium version to get access to new features!"
end
define show_premium_greeting
print "Welcome exalted one to Calendar Program version 1.0 -- Premium edition"
print "You are indeed a most wealthy person, as you could afford the premium edition!"
print "Thank you for purchasing Calendar Program!"
end
Now that we have our greeting functions defined, we could check which version of our software the user was using (stored in the 'program_version' variable), and then display the proper greeting, like so:
if program_version == free
show_free_greeting
if program_version == pro
show_pro_greeting
if program_version == premium
show_premium_greeting
Much cleaner, don't ya think!
Ok, on to algorithms. An algorithm is a recipe, plain and simple. It typically has an input and an output. Think of algorithms -- they are the part of the function that does the work. An example of an algorithm might be something like this:
total = x ^ (1/2)
This algorithm simply raises x to the (1/2) power, also known as taking the square root. But wait. I don't get it. What is the value of x? Where did IT come from? To fully understand this we can to put the algorithm in a function, like so (the stuff in the parens after the function means "give the variable 'x' to the function":
define sqrt(x)
total = x ^ (1/2)
print total
end
The function 'sqrt' computes the square root of a number and prints the result. So calling 'sqrt(25)' would print "5". Now that we've defined out sqrt function, we can avoid writing 'total = x ^ (1/2)' every time we need the square root of a number. It's a relatively mundane example of an algorithm because there exists all sorts of algorithms that are much more complex and useful -- sorting algortihms, searching algorithms, etc. In fact...
It turns out there are some pretty useful scheduling algorithms for managing the psuedo-simultaneous excecution of many programs, like First-in-First-out, Last-in-First-out, Round-robin, Lottery, etc. You can probably guess pretty easily from their namse how most of these work. FIFO algorithms are akin to a first-come-first-serve management style. LIFO algorithms are more fair and always execute the program that has been waiting the longest (the last one in). A Lottery scheduling algorithm simply chooses one at random. And so on.
This concludes my Computer Concepts series at least until I can think more topics to cover. If you have any questions, certainly don't be afraid to ask. Likewise, if there is a topic or fuzzy area you'd like to a post about, put your request in the comments. Happy holidays everyone!
Monday, December 8, 2008
Exponential Reality
I think I've posted this before, but it's worth a re-post -- a little clip with some great statistics about the times in which we live. Things move fast folks, mind-bogglingly fast. This helps put things in perspective.
Thursday, December 4, 2008
Computer Concepts Part 2
Finally getting a break from school-work this week, I'm back for the second installment of a little series on the basic computer concepts I've picked up from my studies. If you missed Part 1, hit the link and have a read. Given our new computer hardware fundamentals from Part 1, I figured we'd cover one hardware concept called context shifting and the software that manages it.
Context switching. It sounds important. And it is. Context switching allows the CPU to juggle the many programs that run on a computer. You see, CPU time is valuable. If you recall from Part 1, a CPU can only do one thing at a time. In order to create the illusion that your CPU is working on everything, it switches between all the different things it needs to compute, thousands of times per second. For instance, your CPU constantly switches between running your operating system (and its many background processes), your instant message client, music player, and whatever else you're running. The steps for a context switch are these:
1. Save any important data about the process currently running.
2. Load any data for the to-be-runned process into memory
3. Run the new process
By looping through this set of instructions, the CPU can do a little work for your music player, then switch and do a little computing for your spreadsheet document, then switch to your operating system and do some work for it, then back to your music player, etc. The feeling of a seamless, uninterrupted experience on a computer is a complete illusion. The reality is that context switches simply happen fast enough and often enough that you, the user, don't perceive them.
So who decides when a context switch happens? Is it random? While switch itself is done entirely by the hardware, turns out the operating system is the primary manager of context switches...
An operating system is "a collection of software that directs a computer's operations, controlling and scheduling the execution of other programs, and managing storage, input/output, and communication resources" [Dictionary]. It's all about resource management. But don't fool yourself. This massive collection of software, typically around 2 million lines of code, is just a big program. Your CPU treats your operating system just like it treats all other programs, for the most part anyways. The unique thing about an operating system that is different from all other programs on your computer is that it has special privileges. It gets to operate the CPU in 'privileged mode'. See, your CPU actually has two modes: privileged and non-privileged. These two modes exist because like all systems where there exists a scarce resource, things will compete for those resources. An entity must be present to manage those resources. The most important resource is the CPU, and the things trying to dominate that resource are all the processes that run on your computer. See, processes/programs are dumb, incapable of knowing how to say 'oh, another program wants to run, we should let it!" The operating system acts as a manager (being the only program with privileged access to the CPU), deciding which program gets the precious CPU time, and which ones have to wait. This is one of the most important tasks the operating system handles. Without this sort of process management you'd only ever be able to run a single program, and you'd always have to run it to completion before starting a new program.
While mocking up this post I had originally planned on including an explanation of algorithms, functions, and a few other programming paradigms. It grew to be quite the lengthy post. Lengthy enough that I decided to save it for Part 3. I hope this gives you some idea how your computer/CPU is able to manage all the different things going on in its guts. Check back for Part 3 in a week!