Thursday, June 11, 2015

"Greed is good?"

Location: United States of America

"Greed, for lack of a better word, is good." said Gordon Gekko in Wall Street (1987).  But saying so is disingenuous.  Greed has no motives, no more so than any emotion.  Human beings, and likely every living thing, simply want an easier life, and we have no standard to compare to other than how other people live.  Greed can lead people to do bad things, or good things, and there lies the rub.  It is the people who decide to take actions that lead to positive or negative outcomes.

Capitalism, as we practice it in the US, is a tool.  Just as any tool, it has no motivation other than that which its users ascribe it.  One of the most amazing things about this tool is that it can focus a natural human trait, greed, into socially positive outcomes.  The examples are many, from a private transportation infrastructure that allows global travel within hours, to cleaning products that prevent disease and improve lifespans.  Unquestionably these enterprises produces great wealth as a byproduct of providing those goods and services.

Capitalism can focus greed to produce a positive outcome but a positive outcome is not inevitable.  That, in my opinion, is why Capitalism requires strong regulation.  It is only through strong regulation that positive outcomes are to be expected.  The examples of this are many, from the inevitable fraud and manipulation that result from deregulation campaigns, such as the deregulation of the energy industry in California, to the proliferation of pyramid schemes thinly veiled behind the term 'multi-level-marketing'.

The ability to create positive outcomes is the purpose of capitalism, the generation of wealth is the side effect, an amazing side effect in what it provides for human nature, but a side effect non-the-less.  It is when we begin to believe that wealth creation is the purpose that we risk slowing or halting the progress we have made thus far, and ultimately could lead to the downfall of our civilization.


Location: Marin County, CA, USA
This George Lucas drama is entertaining!  How often do you get to hear millionaires spout such unveiled drivel?  These people who are 'all for affordable housing', but not if it graces their field of view.  Those fantasy bound souls who believe that their hoarded wealth represents a contribution to society.  That sense of entitlement that only being disjoint from reality can provide.  The NIMBY crew!  Keep it up Mr. Lucas!  You've set your own bar!

Thursday, July 10, 2014


Location: Salt Lake City, UT, USA
So It's been quite a while since I last wrote (I guess my second hiatus).  I made the mistake of starting a multi-post technology entry, and after dealing with that stuff all day at work I mostly lack motivation to consume my free time with more of it.  So I don't plan to do much deep technology in the future, and if I do, I will try to stay topical.

So I'll get to a new topic, and break the ice with some talk of fishing!

Growing up in central Utah I was always close to the mountains, and always close to fishing.  At a very young age I was throwing salmon egg laden hooks into the local ponds and pulling out stocked trout.  In hindsight my technique was poor, I simply tied the hook to the end of the line, loaded it with eggs, loaded the line down with enough weight to get to the deep spots, and waited to feel a jerk on the line.  In those put-and-take ponds I caught fish after fish.  But I learned quickly that I didn't really like the taste of fish, and at theage of probably 7 in the mid 80's I'd never realized that there was such a thing as releasing fish.

It wasn't until I became a boy scout that my true love affair with fishing started.  My scoutmaster was as close to a mountain man as any I had known, or have known since, a consummate backpacking fly-fisherman and hunter with a deep respect for wild places.  One day in the park practicing the back and forth casting of the line and our troop was ready to hit real water, the Green River.  And I took to it naturally.  I loved it.

The rhythm of the casting was like meditation, almost hypnotic, clearing my mind; the effect multiplied by the babbling of the river.  And a purpose!  Not just idly standing in nature, but learning the currents and flow of the river, to place a little wad of feathers and thread so that it, and the line snaking back to you, float in unison in what is called a 'dead drift'.  And the fish!  No longer were you throwing out and waiting for a tug.  Floating flies the fish come to you, and when they come on a river, they almost always come extravagantly.  A surface strike is you luring the fish out of the water, oftentimes accompanied by a quick dart down, with the fins making a big splash as the tail-fin smacks the surface.  It's as exciting as fishing gets!

Close up of two strikes (not me)

I was hooked, and I fished a lot, all over Utah and some of Wyoming, all dry-flies just floating the surface.  And I released nearly ever fish I caught, and increasingly among fly fishermen this is the norm, and I hope it spreads even more.  I hold no animosity for those who keep fish, and I will do so on rare occasion, but we all need to be mindful of how many of us there are, and what the ecosystems can handle. <I'll try not to rant :)>  In 1995 my dad hand made me a fly rod for Christmas.  It is one of my most prized possessions, and sees regular use.

Then for years I didn't fish, taking a 13 year hiatus, but the past several years I have picked it back up and found it to be like riding a bike, the muscle memory persisted after so many years.  And I have embraced it as only an adult can, exploring much deeper into the waterways that avail themselves.  I plan to do much more frequent posting about my explorations for fish.

Friday, July 19, 2013

More geekyness - How is memory on a computer used?

Location: Salt Lake City, UT, USA
Since it had been a while since I had a geeky post, I figured it was time.  Following with the theme of the low level, I am going to delve into memory a bit deeper than I have in the past.  This will be a two-part post.  This post will cover the hardware and operating system view of memory.  My next post will cover the view of memory which programs see.

On your computer you have some amount of memory.  You might have 2-4 GB or a little less, or a lot more, but beyond the abstract idea that your programs go in there when they run, you likely have little idea what your computer actually does with this memory.  You may have seen something about virtual memory, seen something about swapping, or even heard people talking about locality (I'm talking spacial locality), and not understood what they meant.  I aim to clear up some of this confusion.  This post is from a programming perspective.

The memory on your computer, typically refered to as RAM (random access memory), is one large array of contiguous bytes.  If you have 2 GB of memory, you have 2*2^30 (two times two to the thirtieth power) total bytes, or 2147483648 bytes numbered from 0 to 2147483647.  This numbering forms an address system for the memory array, thought of as Physical Memory.  This is a very logical way to address memory, and lends itself to very fast hardware operations, however this method of addressing poses a problem for applications running on the computer.  To understand why, we must look at how programs are actually run by your hardware (I will go into much more detail on this subject in my next post).

When a program is run on your computer the code which makes up the program (called the code segment) is loaded into memory.  Spread liberally throughout this code are commands that jump to new memory addresses, load values from memory, save values to memory, and generally manipulate the memory in any number of ways.  If your computer is only running one program this is not a problem, but if you happen to run a second program, the computer will have to place it in a different part of memory.  Since all modern computers are able to run more than one program at a time, the programs will never know where in memory they are, and programs have no way to know ahead of time where memory values will be, something a program must be able to do because these addresses must be defined and resolved at compile time, before the program is run.  To resolve this issue Intel introduced a new architecture to their chips called Virtual Memory (not to be confused with your operating systems swap file, which is sometimes called Virtual Memory by Windows users).

Virtual memory is an addressing scheme where each running program is presented with its own address 'space'.  This is an abstract representation where each program running (or more properly put, each process) is presented with a memory space that appears to be its own computer.  This memory space is not real, in the sense that it does not directly correspond to the physical memory installed on the computer, it is a completely logical memory space as opposed to physical, an abstraction.  Since there is a disconnect between the physical memory, and what each program sees, a special piece of hardware, called a memory management unit (MMU) is added to the computer to translate these logical addresses to a physical space in your memory array.  Hardware translation is important because it is very fast.  This way each program can address its own memory as if it were the only program running, but your physical memory can be used to handle many of these programs running at once.  Virtual memory and the increasing use of multi-tasking operating systems are a large contributing factor to increasing memory requirements.

So on top of this physical memory we have a layer of abstraction giving us logical addressing.  But there is another traditional issue in computer memory which must be addressed before we can use (program for) a modern operating system, that is the issue of fragmentation and total space.  What do I mean by fragmentation?  When we are laying out programs in memory, we need to make sure those programs do not run out of space.  We also must ensure that all the memory for a program is near the other memory for that program, a concept called spacial locality.  This is important because many operations within a program will move much faster if the memory accessed is sequential (because memory is transferred in chunks), and cache schemes tend to depend to some degree on spacial locality.  To achieve this we over-allocate memory to each program leading to unused memory that is unavailable, fragmented.  Also there is the issue of running out of memory all together.  Programs regularly allocate memory.  There are many programs running on every computer which will cause it to crash if this request for memory is unsatisfied, and as we run more and more programs we use more and more memory.

To deal with these issues by making it appear that we have nearly unlimited memory (limited only by the address width) we turn to a vast but slow array of memory, your computers hard disk.  To accomplish this we introduce the abstract idea of a page, a limited range of memory of a predefined size which we can assign to a single process (program).  Pages could be of any size, but as with anything in memory are typically sized to be a power of 2, aligning properly in memory with addresses that are powers of 2.  We can then move this page (a limited range of memory) back and forth from the physical memory (via logical addresses) to the hard drive and vice-versa depending on how frequently it is needed and how full the physical memory is.  This memory paging is controlled by the operating system which builds and maintains a table of all the pages of memory allocated and manages the access and location of the data stored in that memory whether it be in physical memory, or stored on disk.  The file on the disk which holds the memory not located in physical RAM is called a page file (proper name) or swap file (descriptive).  Many people improperly or informally refer to this concept of paging as virtual memory, though this can lead to confusion as I mentioned eariler.

So if you made it this far, at the very least, the next time you get an error that refers to a page or paging you will know what is causing the issue...  Then you will restart your computer like everyone else!

The only other thing that I can think to say on the subject of virtual memory and paging is that they are working together.  Your computer, consisting of a CPU, MMU, memory and busses (which transmit data between places), handles the virtual memory translation, an address translation, and this logical view presented by the hardware is what is being manipulated by the software, or the logical system on your computer, including your operating system.  In fact, your operating system is responsible for talking to the hardware, and it is prudent to note that the OS can control how the hardware functions on this level (through user rings, and processor modes, I will not go into this here).  The operating system is what created pages.  So if logical memory is an abstraction of physical memory, pages are an abstraction of logical memory.

Computers are a collection of useful abstractions!

I will leave you with that thought, and I will follow up this post with another about how programs work with memory, and how applications are structured in memory.  If you had trouble following my post on switch statements and jump tables, this next post will help clear it up a lot!

Tuesday, July 16, 2013

Fast lane or passing lane?

Location: Salt Lake City, UT, USA
Something that irks me, and I know I am not alone, are people who monopolize the passing lane.  I know I am not alone because this is one of the few things I consistently complain about to those around me, and everyone I know immediately agrees and they commiserate with me.  However, where I will complain about misuse of a passing lane, most people I know will complain about misuse of a fast lane, and therein I believe is part of the problem.

Fast is an abstract idea.  Ask 10 people what is fast, and you will likely get 10 different answers.  By thinking of the far left lane as a fast lane you open this lane up to everyone's individual idea of what is fast.  This could be everything from what someone feels is the appropriate speed for conditions, to the speed limit, to as fast as a car can be pushed.  The result, the left lane becomes the same as every other lane, a mire of traffic to impede anyone who may want to travel faster than the slowest inhabitant.

This is the importance of defining this lane as a passing lane (which is often how state law will define the left lane in a multi-lane highway).  Passing is not an abstract idea.  You either are passing cars on your right, or you are not.  This creates a very clear standard, if you are not passing cars then you should not be in the passing lane.  If you are blocking the passing lane by not passing cars you are being an anti-social ass.

Short post today!  What do you think of people monopolizing the passing lane?  What do you call it?

Wednesday, July 10, 2013

Benefiting disproportionately from the common wealth

Location: Salt Lake City, UT, USA
Something that has been bandied around a lot for the past decade or so is this idea of 'job creators'.  This typically is used as a political term to describe an economic strategy that came about in the late 70's and early 80's, the idea of 'trickle down economics'.  This is the idea that the wealthy should be allowed to keep much more of their money than previously they had, the justification being that they would take all that money and invest it in things that would create jobs and raise the standard of living for everyone.

At first thought, this may seem like a logical strategy.  But it simply is a pipe-dream, as history has shown.  In fact, since that time the rich have gotten richer, and the middle class has stagnated, a fact that is clearly seen when one looks at the statistics over the last 30 or so years.  The reality is that the prosperity of our nation is fueled by the consumption of the middle class, and if the middle class incomes do not keep up with inflation, our economy cannot grow.  It can appear to grow, as we have now where so much wealth is created on paper out of thin air, but a stagnant middle class is a stagnant economy, no matter how rich the upper 0.1% appears on paper.  Not to say that means that the rich are all just as poor as us, far from it, this paper inflated wealth is spread nicely around among us all, many of us hold it through retirement accounts.

The struggle between income taxes is one that has been in the news recently, and I will not rehash it further, but instead I want to draw attention back to a tax issue which almost always is overlooked, the estate tax.  Opponents of this tax will refer to it as the death tax, but in honesty this would be similar to referring to a will as "the dead guys demands."  The reality is that the tax is leveled against the remaining estate of the most wealthy in our society.  These are imposed against estates valued at over 5 million dollars, more than twice what most people would make in their lifetimes.  This is important because most rational people understand the arguments against the estate tax, as they are not irrational arguments.

Why should someone be penalized because they are successful?  That is what all rational arguments boil down to on this issue, and it is a valid point.  I have heard many people attempt to respond to this question, and in my opinion, all but one group has failed to make an argument that acknowledged the moral question raised.  To understand why this argument is incorrect, I must show that the estate tax is not a penalization, but a repayment of a debt to the common wealth that we all create, own, and are responsible for.

I steal a statement from Bill Gates Sr. (yes, the father of the richest man on earth, at the moment), and assert that the rich deserve to pay disproportionately in taxes because the rich have benefited disproportionately from the common wealth.  What Mr. Gates is talking about here is important because it hints at one of the other true source of the wealth which we are capable of creating, the public infrastructure.

I have heard others talk about this.  Obama tried to point it out in a speech and was accused of being anti-business and saying business owners didn't work for what they have.  I am not a fan of Obama, and he has done his own defense against this, but his original point is quite valid.  He said that along with all the hard work that individuals put into their business, there is also work put in by the community.  The most obvious is the public system of roads and transportation that brings goods and supplied, as well as customers.  Obama talks about police, and firemen who protect businesses, funded by the public common wealth held by all of us.

It goes much deeper than that though.  We have a patent system which was created by and for all of us.  This patent system has been an enormous source of wealth for countless businesses, along with trademark and copyright law.  When businesses have their patents, written works, or trademarks stolen, they enjoy the services of another public sector entity, the courts.  When businesses seek to hire new talent, they do not have to invest significant sums in extensive ground-up training systems because they can walk over to the publicly funded schools in their area and find people trained in a myriad of skills which they require.

This is how those who are able to amass large amounts of money are benefiting from the common holdings of we the people, the common wealth.  This is why the rich are benefiting disproportional to the public.  They live in a society which has built an infrastructure that is the greatest generator of wealth in the modern world.  The wealthy shoulder a moral responsibility to return in proportion to their benefit to the system created by others to give them that opportunity.  This is indeed the moral imperative.  Some of the wealthy will return disproportionately to society if left to their own devices, however, this is by no means the norm.  Anyone who looks at the history of wealth distribution can see that this repayment to society cannot be voluntary.

Through most of our nations history of taxation the wealthy have been taxed at a much higher rate than the middle and lower classes.  Most of the time this meant effective tax rates of 60-80%, though tax rates on the top tier of the rich rose as high as 96%.  Tax rates now are effectively in the 12-15% range for the richest of Americans, and I believe my effective rate last year (which included a one time credit for money I spent on tuition) was 35%, I look forward to an effective rate closer to 40% next year.  I make almost exactly the median income at my current job.  If I pay taxes and don't spend a single penny of what I make, it would take me 142 years to make the 5 million dollars required to have to pay the estate tax.

If you look at where true economic prosperity comes from, the middle class consumers and the public infrastructure created through taxes, it becomes clear why the wealthy should pay proportionally more in taxes than the rest of the population.  I think the estate tax is a perfect tool in this quest because it ensures that the wealthy return to the system for the benefit they have received.  I think that humans are greedy beings, and that the estate tax helps to encourage people to create amazing things by allowing them to employ their money in their choice of pursuits, to hold their reward, but that at some point a portion of that accumulated wealth must be returned to the public which is charged with creating the infrastructure to ensure that future generations are allowed to enjoy the same prosperity that we can.

If humans were not humans and the world was perfect, perhaps this idea of trickle down economics would be viable, but the reality is that it is the job of government to structure markets in such a way as to encourage positive outcomes and discourage negative outcomes, and this idea of completely unregulated economies and markets is a daydream that is doing irrevocable harm to our society.

As always (and dammit, will someone someday take me up on this), tell me I'm wrong!  Or perhaps why I am right?

And here area few videos that inspired my post today:

Saturday, July 6, 2013

False equivalency - drinking Kool-Aid

Location: Salt Lake City, UT, USA
I have heard this one in lots of situations, but the one that really gets under my skin is how it is used in politics and business, and perpetuated by the news media.  The term I refer to is 'drinking the kool-aid'.  For this one a little bit of history is in order (apologies if you lived through this and know the story).

In the 50's an evangelical minister named Jim Jones founded a church called the Peoples Temple.  In the mid 70's Jones moved with most of his followers from Indiana to California.  The story of their time in California is too long to fully describe here, but to make the story short, though their membership continued to grow and Jim Jones had become politically well connected, the Peoples Temple had come under increasing scrutiny fueled by reports from former members, and current members families, through a group named the Concerned Relatives.  Under mounting pressure in the US, and increasingly socialist/communist aspirations for their group, Jim Jones negotiated with the Guyanese government for land in Guyana to establish a settlement, which would later be called Jonestown.

The story of the Peoples Temple in Jonestown is another long and involved story which I will skip here, but you need to understand that Jonestown was built on land deep within the Guyanese jungle on land that natives did not want because it was so difficult to work.  Life in Jonestown was hard, but the people there were (mostly) committed.  At its height there were around 1000 people living there, commune style.  However, back in the US, allegations were flying about people being held against their will, and crimes as serious as murder which left a lot of questions about the Peoples Temple and its leadership.  The allegations became so widespread that Congressman Leo Ryan, from California, arranged a delegation to visit Jonestown himself, accompanied by several members of the press, and family members from the Concerned Relatives group.  The meeting in Jonestown started out well, despite scheduling issues and trouble getting permission to visit the site when they arrived in Guyana.  Ultimately of over 900 present, around 8-12 requested to leave with the congressman, and were granted permission by both the congressman and Jim Jones.  This stirred up a very emotional scene as a parent who asked to leave attempted to take the children from a parent who was choosing to stay.  There was a small scuffle involving one such split family and a knife, after which it was suggested that the congressman and his delegation, which now included the defectors, should leave for the evening while tempers died down.  However, waiting at the airstrip where the congressman and his delegation were preparing to depart after having left Jonestown, several Peoples Temple members arrived and opened fire, killing around 5 including Congressman Ryan.

It is unknown if these killings were directed by Jim Jones (many accounts falsely report that Jones ordered the killing, any evidence of this is circumstantial), but there is no question that when the perpetrators returned, Jim Jones knew what had happened.  Fearing US retaliation for the killing, Jim Jones commanded his people to commit mass suicide by drinking fruit punch (flavor-aid or kool-aid) mixed with cyanide.  Over 900 temple members committed suicide that day, most by cyanide poisoning.  Jim Jones and his inner circle all died to gunshot wounds.  Something like 2 or 4 members who were present that day survived, one of them was hard of hearing and slept through the assembly bell.  Another saw what was happening and lied about needing to get something, then fled and hid in the jungle.  The Jonestown youth basketball team survived because they were elsewhere at the time.

This is the origin of the phrase 'drinking the kool-aid'.  It refers to a large group of people following an ideology or personality to the point of taking their own lives and the lives of their families.

Now, lets compare this to how the term is commonly used.

In 1984 President Regan used this term 'drink the kool-aid' to describe three civil rights activists,  Jesse Jackson, Vernon Jordan Jr., and Benjamin Hooks.  He went further to accuse them of dragging the country into a political Jonestown during the previous election.  Now, lets look at this.  Over the 20th century many black people were unjustly killed in America.  Civil rights leaders looked at the rule of our land, and held faith that in that framework was freedom for their people, and an end (or at least sharp decline) of the threat against their lives.  Perhaps you could see this faith in our system as blind faith, and though eventually the civil rights activists won, they certainly suffered greatly to win, and many were killed for their beliefs.  So in that regard perhaps Regan was right, for a while the civil rights leaders did drink the kool-aid.  They had blind faith that this country would protect them, and many died for that faith.  Unfortunately, this is not what Regan meant.

As the dot-com bubble burst, the New York Times indicated that the phrase was being commonly used to refer to the investors who thought the market would never stop going up.  So in this context we are comparing losing money to taking your life and murdering your family.  I'm not even going to elaborate on how ridiculous this comparison is.

The way this phrase is used in political commentary provides some of the worst examples.  Often it is bandied about by pundits, such as Bill O'Reilly, to simply denote that they find no logic in an alternative viewpoint.  He has some great quotes on the subject:
"Most talk radio is conservative-dominated, ideologue, Kool-Aid–drinking idiots."
You are a blind ideologue who even if somebody’s nice to you, won’t admit it because you’re… Talk about a Kool-aid drinker!
The first situation he is just talking about his competition, in the second he simply doesn't like this lady and finds her logic inconsistent.  Neither situation baring any resemblance to the events at Jonestown.  I pick on O'Reilly because he has got to be the absolute worst, but this issue pervades many other pundits.  O'Reilly has a whole reoccurring bit about kool-aid drinkers where he lambastes anyone who disagrees with him, complete with kool-aid-man graphics and all.

I see this used to describe people who voted for Obama, acceptance of a project at work, employee dress codes.  I even found a reference where it was used to describe a marriage...

One funny thing I found while doing a little research on the uses of this phrase were site after site of people asking what the kool-aid reference was in regards to Obama.  Many report thinking it was a racial slur, like a reference to fried chicken or watermelon might be.  I was saddened that so many would be ignorant of the origin of the phrase, but I couldn't help but chuckle at how revealing it is about our culture.

The sad part is that they do it knowingly.  Regan and O'Reilly lived through Jonestown, and both have a great understanding of the tragedy that unfolded there.  Yet they both made a choice to exploit those events for their own benefits.  They tarnish the memories of those who died at Jonestown by comparing their plight to that of a media star battling for ratings, or corporate executives losing money.  They are disingenuous with their audiences when they assume that their arguments are so weak that they have to be supported by raw emotions such as that brought up by references to tragic events.

This is not unique to Jonestown, just look at the comparisons in modern culture to the holocaust, Hitler, or communist Russia.  Few if any are appropriate, almost all are perfect examples of gross false equivalency.

As always, tell me I'm wrong!

Thursday, June 20, 2013

Judicious Process vs. Due Process

Location: Salt Lake City, UT, USA
Most people living in the US have heard of due process, and though few of us have probably studied the term, I think most of us have an idea what it means. Or so I thought, before I read Eric Holders speech where he outlines the legal justification behind sanctioned killings of US citizens, bypassing the courts.  I'll get to that a little later because the whole topic made me go back and do some reading, and though much of what I found was written in legaleze, I put the time in to try to figure out what it all said.

I don't think it helped though, because I am right back where I started.  I still think due process just refers to all the rights afforded to everyone.  Free speech, trial by jury, remaining silent, representation, among others.  There are a few different contexts in which the term is used, which can be confusing, but luckily, to address Mr. Holder's use of the term, we only need to look at how it is used in the constitution:
No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offense to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation.
This is, in fact, the entire fifth amendment to the constitution, part of our rights as citizens of the US.  I have bolded the section which references due process of law.  It's odd that the entirety of the amendment is quite explicit and direct, but the question of due process has always been more left to context than explicitly understood.

Now lets look at the meat of what Mr. Holder had said:
Some have argued that the President is required to get permission from a federal court before taking action against a United States citizen who is a senior operational leader of al Qaeda or associated forces.  This is simply not accurate.  “Due process” and “judicial process” are not one and the same, particularly when it comes to national security.  The Constitution guarantees due process, not judicial process.
Now, first I have to say that this paragraph is but one in a very long speech.  There is some context there.  He talks about the successes we have had in prosecuting terrorists, and all the plots that have been averted, and he even says a few things I agree with (damn few).  But the quote above is something I find very disturbing, and I think deserves a lot more attention than it got.

If you haven't deciphered it yet, he is basically saying that the 5th amendment doesn't guarantee that if you are accused of something serious, say killing someone, you will face a jury, or even get a court hearing.  That is what is meant by Judicious.  Instead, what Mr. Holder is saying is that due process is an abstract idea, that it simply means that some entity has to review it.  I would assume (perhaps hope is a better term) that there is some standard being applied, like that the entity given this power be impartial, at least I think that is being implied.  He goes on to make a historical argument that the president has traditionally been charged with maintaining national security.

THE ABOVE PARAGRAPH SCARES THE SHIT OUT OF ME!  In my mind we're basically being told that now the president has the legal authority to decide which citizens are a threat to our country, and summarily execute them.

To form a more specific rebuttal, I will start by pointing out that the entire 5th amendment is one sentence.  One cannot look at the term "due process of law" without also looking at the first few words, "No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury".  There is a clear call for an indictment (an instrument of the judiciary), and a Grand Jury.  I think this is probably a foundation for a legal argument that I just don't have the experience to produce.  But I think the implications of Mr. Holders opinion reach so far that we as citizens have an obligation to stand up and oppose it.

Some people may look at this debate and not understand why it matters so much.  They look at the context and think that killing al-qaeda is probably a good thing, and they may be right, but the implications of what Mr. Holder is saying go deeper, in fact they question a fundamental understanding of one of the underpinnings of our society, the need for courts.  This opinion invalidates the idea that accused people are guaranteed the right to a trial in a court and judgement by a jury.  Due process becomes this abstract idea that something somewhere will review the situation to make sure it is all nice and legal.  It's the main ingredient required to form a tyranny.

Since I am not a lawyer, I can't give the eloquent rebuttal that I'm sure Mr. Holder would, I certainly can't cite the precedents.  But I can tell you one thing.  We are having out rights stripped from us by people like Eric Holder, and we the people need to stand up and start making some noise because the deeper we get the harder it's going to be to climb back out.  If we don't fight to preserve the idea that we were founded upon, this incredible American experiment is going to fail.

Tell me why I am wrong!

Tuesday, June 18, 2013

Colorado River - Ruby / Horsethief Canyons - Floating!

Location: Grand Junction, USA
Again, we got a group together, loaded up the boats, and hit the Colorado River to raft through Ruby and Horsethief canyons.  We went for twice as long as our previous trip, and I took some video over two of the float days.  Below is the video.  If you are looking for more textual information about this trip, see my previous post on the area!

Feel free to leave feedback!

Monday, June 17, 2013

What are switch statements under the hood?

Location: Salt Lake City, UT, USA
If you don't know what a switch/case block is (often called a switch statement, or switch condition), then this post will likely not be of any use to you.  I apologize, and promise that this will be the last very technical post I make for a great while.  If you're a programmer and don't know what I am talking about, break out google and learn about switches, then come back so you know how they work and can properly take advantage of this wonderful tool!

Switches are great!  Any time that you have several 'if / else if / else' clauses chained together to represent a number of potential paths, you have a great candidate for a switch.  At the very least a switch statement will likely give you code that is much more clear and easy to read.  They are concisely and explicit.  When given the opportunity to shine, a switch can dramatically improve the speed of your code.

To see how switches can improve your code you need to understand how they are being performed 'under the hood', and to understand this we have to actually understand a little about the machine code that your source code is compiled into.  We do this typically with an assembly language, but I will not assume you are fluent in assembly.  Instead I will try to describe what is happening.

Everything in your program is stored in memory before making it to the processor.  Instructions (commands), variables, strings, everything.  Processors only understand rather simple commands, things like move this value from memory location A to memory location B, jump to instruction located at memory location B and continue processing from there, compare values in A and B, add two values, and other basic operations.  These basic operations can be stringed together to accomplish some higher level task.  For instance, you could write a basic assembly program to find the absolute value between A and B:

0Test if A is greater than B
1If test is true jump to address 4
2Subtract A from B (answer is in B)
3Jump to address 5
4Subtract B from A (answer is in B)
5Return to caller

When we are finished running this code, the result is stored in B (A and B both represent registers, memory on the processor to store things we are currently operating on, usually 4 to 8 bytes each).  We could have accomplished the same thing other ways, for instance, we could have just subtracted them, tested if the answer was less than 0 (negative), and if so we could have multiplied by -1, or even flipped the bits and added one.  In programming there are almost always several ways to do the same thing.

Now that we understand a little bit about how assembly works we can talk about something called a jump table.  A jump table is not something explicitly offered by assembly.  Instead it is a logical programming construction, something someone made up as a way to use assembly to create something useful.  To see how they work, it helps to lay out a scenario in which we would use them.  For our example we will say that we have a game, and the player should be able to choose between 6 different classes.  In C we might make some constants for each class to map the class name to a number which will be used internally to determine the class, in Java we may use an enum to do the same thing.  Regardless of how we represent it, we will abstract our classes to numeric codes 0 through 5.  Here's how this may look as an if/else if block:

if (chosenClass == WARRIOR)
    hitPoints = 50;
else if (chosenClass == MAGE)
    hitPoints = 15;
else if (chosenClass == WARLOCK)
    hitPoints = 20;
else if (chosenClass == ROGUE)
    hitPoints = 30;
else if (chosenClass == NINJA)
    hitPoints = 40;
else if (chosenClass == BARD)
    hitPoints = 10;

Note: ALL CAPS represent enums or constants, numbers, 0-5.

A switch form of the above code might look like this:

switch (chosenClass) {
    case WARRIOR: hitPoints = 50; break;
    case MAGE:    hitPoints = 15; break;
    case WARLOCK: hitPoints = 20; break;
    case ROGUE:   hitPoints = 30; break;
    case NINJA:   hitPoints = 40; break;
    case BARD:    hitPoints = 10; break;

So I hope that by looking at my previous example of pseudo assembly, you can see the obvious way that this may be implemented in machine code.  A few comparisons for equality and jumps to different addresses and you're done.  But since I am writing about it, there must be a better way.  Let me propose that instead of doing comparisons, we do some calculating.  We have 6 total choices, and the range is 0 to 5, this is important.  Note that there are no gaps, though this is not a necessity.  Also recognize that once we have made a choice, we have our 6 possible outcomes and that each of these in machine code is two operations: one to set a memory location or register value, and another to jump past our choices (the equivalent of break), twelve total lines of code.  We now can write something with this logic (the chosenClass is held in A, hitPoints is held in B):

00Multiply A by 2 and store the result in A
01Jump to address stored in (A + 2)
02Set B to 50
03Jump to address 14
04Set B to 15
05Jump to address 14
06Set B to 20
07Jump to address 14
08Set B to 30
09Jump to address 14
10Set B to 40
11Jump to address 14
12Set B to 10
13Jump to address 14
Our code has a really cool feature to it.  Where the logic in our C/Java style code using if/else blocks may have to test our condition up to six times, our assembly code is able to identify the correct code with two basic math operations and a direct jump to a new memory location.  No matter which choice is made, we will never execute more than four instructions.  In computer science we refer to this as constant complexity, and this is really the holy grail of algorithms.  Anytime you see complexity go constant like this, you know you are looking at something special.

So how is this working?  First we look at how large the commands that we are jumping to are, in this case they are each 2 instructions, Set B to a value, and jump beyond the switch (to instruction address 14).  To account for this we multiply A by 2.  We then look at where these commands start, they start at address 03, so we add 2 to A (2 because we are using 0 as a number), and this defines where we jump to in memory.  If the switch input is 3, we multiply by 2, add 2, and we find that we should be jumping to address 08, set B to 30, which properly corresponds to our ROGUE, which is correct for an input of 3.

But this is only a simplified version of a jump table, contrived to show just the basic logic and illustrate how jump tables avoid complexity and as a result can substantially speed up your code.  Our logic here is great to illustrate those points, but it is terribly limited in application.  What if the code that we executed on a matched condition was not uniform in length?  Suddenly our trick of multiplying by 2 fails!  What if the numbers don't start at 0, or 1, what if they start at 1430 and go to 1634, a range of 204?  Our code again breaks.  What if there are gaps in the numbers used?  Using my example code, this quite real possibility is completely undefined -- entirely unacceptable for computers.  Being undefined simply means that we have to define some behavior which will consistently generate correct results.  For our needs this is actually quite easy, but to reveal our strategy we first have to resolve the first issue, that of varying length conditional blocks, the code we want to run when we match is not of uniform length.  We can easily handle ranges that do not start at 0 or 1 by converting them to our range.  1430 to 1634 is the same as 0 to 203, so we can do a little basic subtraction and convert ranges, and again, all this is done in constant complexity!

We can solve the issue of non uniform lengths by using an intermediary list which has some information about how these different lengths impact the addresses at which each starts.  As with everything on a computer, our list goes into memory with each choice being a memory address (4-8 bytes), more specifically, the memory address of one of the instruction blocks.  We then can calculate a position into this list, and retrieve the memory address to jump to for the associated instructions.  We can count on the memory locations being either a multiple of 4 or 8 in our list, and we now can use our simple logic above to jump to the correct locations.  Let me illustrate this with code, using 4 as the multiplier to simulate a 32 bit system:

00Multiply A by 4 and store the result in A
01Retrieve the value stored in our LIST at offset A, store it in A
02Jump to address stored in A
03Set B to 50
04Set C to 12
05Jump to address 20
06Set B to 15
07Jump to address 20
08Set B to 20
09Set C to 18
10Jump to address 20
11Set B to 30
12Jump to address 20
13Set B to 40
14Set C to 100
15Jump to address 20
16Set B to 10
17Jump to address 20
18NO OPERATION (processor just does nothing for this instruction)
19Jump to address 20
Our LIST looks like this:

So again, lets say we want to pick class 3, we multiply that by 4, and get 12.  We look up the address stored at offset 12 in the LIST, and find address 11.  We jump to the address stored in our list, 11 and we find we should set B to 30 and jump past to the end.  Again, this corresponds to the ROGUE, number 03.  Our algorithm is correct, and we now have greatly improved the usability of our logic at the cost of a little extra memory.  We retain our constant complexity, which is key.  No matter how large a list of conditions we are working with, we will never had to run more than three instructions to get there, and never more than 5 or 6 to be finished!

Our last task is defining an action when the values have gaps.  This also allows us to handle a default case if we desire.  The first thing to notice about the code above is that we have more items in our list than we have possible choices.  We have added an address at offset 24, which would correspond to a 7th element.  This is a default case, and corresponds to instruction address 18, where we just do nothing and then jump to the end (our code has no default case).  Handling gaps is simple, we just add an entry in our LIST for that number, and set the value to be the instruction address after our code, in this case address 20.  That way if we reach a number with no corresponding instructions, we can simply jump right past our code and continue processing.  Again, all of this maintains constant complexity, our ultimate goal!

An astute observer may notice a flaw in this logic.  What if our range is huge with a lot of gaps.  What if we have conditions to match 0, 4, 10, 50, 945328, and 1 << 63?  We have 6 possible values, but a range that goes from 0, to some obscenely large value (2^63).  Not only does do our gaps occupy substantially more space than our valid options, but our list must have 2^63 entries!  You could never hope to hold all this in the few gigabytes (or event terabytes) of memory available to us.  Luckily modern compilers are smart enough to recognize the conditions which will lead to excessive wasted space like this, and will only compile code into jump tables when it can determine that the range and gap density is low enough to make a jump table efficient.  In other words, not all conditional chains or switches will result in a jump table.  Only those which will lend themselves to increased efficiency, at a cost that is not disproportionately large to memory, will be converted into jump tables.

I think that's about it, but if you think I left something out, notice any mistake, have questions, or anything at all, leave a comment!