Tuesday, October 7, 2014

I'm a Wingnut and a Moonbat: Part 2

In an earlier post, I explained why I might be considered a “wingnut”. Briefly: I don't support the California assault weapons ban because it restricts access to certain firearms based on their cosmetic appearance rather than their functionality. Now I have to explain why I'm a “moonbat”.

When I say that the difference between the murder and assault rates in the US and the analogous rates in Western European countries can be explained almost entirely by economic inequality, I get accused of being a socialist, which I am, although not in the American sense of the word (where socialism is conflated with communism, totalitarianism, and oppression).

The evidence, however, is clear: about three quarters of the variance in murder and assault rates is explained by income inequality. This means that if you want to reduce violent crime in the US, you can address at most one quarter of the problem with all other measures combined: neither harsher sentences, favored by the right, nor gun control, favored by the left, are nearly as strongly correlated with violent crime as income inequality. Neither gun control nor prison sentences are statistically correlated with violent crime rates to a significant degree.

So, if you actually want to address violent crime, the elephant in the room is that you must address poverty, and not just absolute poverty, but relative poverty. To do that, you need to ensure that the distribution of wealth between rich and poor favors the poor more than it has in the past.

What policy changes ought to be introduced to ensure that the poor get a greater slice of the pie, and the rich a smaller slice, is open to debate, but any way you cut it, this sounds far too much like redistribution of wealth for any right-winger to resist the temptation to call me a “moonbat”.

Friday, October 3, 2014

I'm a Wingnut and a Moonbat: Part 1

For those unfamiliar with American political discourse, a “wingnut”, so the stereotype goes, is a gun-totin' redneck Evangelical Christian Republican-voting moron who gets all of his/her opinions straight from Rush Limbaugh. A “moonbat”, by contrast, is a gun-grabbin' city-dwelling atheist Democrat-voting commie who gets all of his/her unconsidered opinions straight from The Daily Show.
Now, you might think that an advocate of evidence-based policy might end up somewhere in the middle and would be neither a wingnut nor a moonbat, but it turns out that such a person is actually both.

Here's one example (I'll address the other side in Part 2)...

California has, arguably, the strictest gun control of any state. I come from a place where firearm licensing is immeasurably stricter, basically the strictest in the world. There is no legal provision for a license for a handgun or a center-fire rifle. You can get a license for a shotgun, double-barreled or pump with a 3 round magazine, or a .22 rim-fire rifle, but that's it and it's not easy. Broadly speaking, as a people, we have no tradition of firearms ownership and we neither need nor want firearms. Our police are mostly unarmed, and we like it that way.

As a person living in the US on a visa, I can't legally own buy (see edit note, below) a firearm. I find them interesting, of course, as any kid who played cops & robbers patterned after American TV shows might, but basically, I have no dog in this fight. I'm undecided whether, if I were allowed, I would end up having a ridiculous arsenal of firearms just because they're cool and fun and I'm a big kid, or I just wouldn't bother because they're dangerous, expensive, and the likelihood of ever actually needing to use one in the wealthy suburban part of California where I live is essentially zero.

But here's the thing. I read California's so-called “assault weapons” ban, and it is, by any objective standard, absurd. It is absurd, not because of its abuse of terminology (it actually bans some facsimiles of assault rifles), but because it regulates the appearance of the firearm, not any feature of its operation. In short, it regulates only the cosmetic appearance of the firearm. Don't believe me?

OK...

This is illegal to buy, sell, import, etc. in California (legal to own if grandfathered in). You will probably be charged with a felony (technically, it's a “wobbler”) if you are caught with one of these and can't prove that you bought it before the ban:
Illegal “Assault Weapon” in California
This functionally identical rifle — firing identical rounds with an identical mechanism from an identical magazine down an identical barrel at an identical rate of one per trigger pull — is legal to buy and own in California (assuming in both cases that the magazine holds no more than 10 rounds, despite looking like 20 or 30 round magazines):
Legal “Sporting Rifle” in California
What makes the legal difference?

The pistol-style grip above is illegal; the one below, fused to the stock, is legal. That's the difference. And don't think that federal laws are much better. If you add a handle-like grip to the barrel of either of the above without permission from the ATF and a $200 tax, that's a felony.

This, we are supposed to believe, is what is going to protect children from a Newtown-style shooting: making guns have the right kind of handle and making it a felony to have the wrong kind of handle or, perish the thought, an extra handle.

Wow!

So now you know why I agree with the gun rights activists and say “the California Assault Weapons Ban is one of the most astonishingly stupid things I have ever heard of”, but only wingnuts say things like that, so I must be a wingnut, right?

Edit: in the original version of this post, I said that (as someone here on a visa) I couldn't legally own a firearm. That's probably not exactly true. 18 USC 922 (d)(5)(B) criminalizes the sale, or other transfer, of a firearm or ammunition to a person “who, being an alien— [...] has been admitted to the United States under a nonimmigrant visa [...]” (that's me). Not that I'd realistically consider doing it, but it might be perfectly legal, at least under federal law, for me to make a firearm (e.g. from an 80% complete lower) and ammunition (e.g. by reloading), since the power that the federal government uses for 18 USC 922 derives from the Commerce Clause and so, strictly speaking, regulates only interstate or international trade. There's even an argument that I could legally purchase ammunition manufactured in California (since it would not involve interstate or international commerce and, therefore, cannot fall under the authority granted by the Commerce Clause). In any case, it's a minor technicality, there's probably some other law that prohibits it at the federal or state level, and I'm not so enamoured with the idea of firearms ownership that I'd bother risking it. Nevertheless, I've changed “own” to “buy” since, as far as I know, that's more accurate.

Monday, August 25, 2014

The Problem with Fracking: Part 3

In the first and second parts of this series, I argued that aquifer contamination from the completion in a fracked gas well is highly improbable, and that fracking fluid, as distinct from waste water, is benign.

In this part, which could easily be titled “When Fracktivism Isn't About Fracking”, I take a look at “fraccidents” in Pennsylvania.

Pennsylvania has been a gas-producing state since the mid 19th century, but has seen a boom in gas production since fracking enabled the exploitation of the Marcellus shale. There are estimated to be 350,000 oil and gas wells in Pennsylvania, the vast majority of which are old, inactive wells. EIA data shows a sevenfold increase in gas production in the four years after horizontal drilling (more-or-less synonymous with fracking) began in earnest around 2008. Currently, there are about 9,000 active wells in Pennsylvania, with a new well being drilled every day (on average). The following EIA animation shows wells drilled in Pennsylvania between January 2005 and April 2012:


As it happens, this is more-or-less the same time span covered by Earth Justice's record of “fraccidents” in Google Maps. In mid-late August, 2014 (the time of writing of this blog entry), they place 38 “skull and crossbones” symbols over Pennsylvania for what are, presumably, poisoning events of some kind resulting in death or serious injury; at least a major fish-kill or something, right? You don't use a skull and crossbones to indicate something like rocks falling from the back of a truck with a faulty tailgate, after all, right? It turns out that you do.

“Fraccidents” in Pennsylvania
When you click on a skull & crossbones, you sometimes find that it corresponds to two or three separate events that might be revealed at a higher zoom level (or not; sometimes they are in the associated text or linked articles). It can sometimes be hard to disentangle where and when, exactly, a particular event occurred since, often, linked articles make reference to events that happened elsewhere in Pennsylvania at some indeterminate time in the past (the Zimmerman vs. Atlas Energy lawsuit is mentioned several times). Equally, there are occasions when an opportunity to include a separate skull and crossbones has been missed.

“Fraccidents” Overlaid on EIA Well Data
All in all, I figure that the Earth Justice “fraccidents” represent 45 separate events.

But how many of these are actually to do with fracking?

Let's have a look at a few of these fraccidents...

Sticking out like a sore thumb, there's a lonely skull & crossbones about 30 miles south of Harrisburg, and over 100 miles east of any well (fracked or otherwise) known to EIA. It turns out that this is actually a drilling mud spill that happened when a gas pipeline was being drilled 13 feet under a creek. This might be related to the Pennsylvania gas industry, but has nothing whatsoever to do with fracking and, even if it did, it's a very minor event. Equally, representing a spill of 2-3 cubic yards of bentonite (a kind of clay) with a skull and crossbones reeks of alarmism.

More appropriate use of a “skull & crossbones” is in the southwest corner (as it happens, the event actually happened in West Virginia, but appears in Pennsylvania, presumably due to some innocent error), where 10,000 fish were killed over a 30-mile stretch of river. What caused this? An algal bloom caused by discharges from coal-mining. Nothing to do with fracking, or even the oil & gas industry.

There's a water-contamination event in Hickory (just west of Pittsburgh) in December 2005. The problem is that the first horizontal well in this area was recorded by EIA in September 2007. So this event, if it was was due to a gas well at all, was due to a conventional well and, again, nothing to do with fracking.

There are several examples of compressors catching fire, a faulty tailgate on a truck allowing drill cuttings to fall out onto the road, a truck leaking hydrochloric acid, drilling mud spills, diesel spills, or methane leaks. These are nothing whatsoever to do with hydraulic fracturing: they might just as well have happened with any kind of gas well, fracked or not, or in another industry entirely.

In fairness, there are several events that can plausibly be linked to fracking in some way. In most cases, these are either actual wastewater leaks or events probably caused by wastewater leaks. For example, there are several cases of high levels of metals, including arsenic, and aromatics, including benzene, being found in soil or drinking water. Although the causal connection with fracking is tenuous, they are most likely attributable to wastewater leaks, and the wastewater is from frack-jobs. There have been a number of casing and cementing failures that probably wouldn't have happened in a conventional well, probably happening due to the extreme pressure used during fracking.

So, how many of the 45 “fraccidents” survive cursory fact-checking?

Being generous? About half. The other half range from outright lies (fish-kills due to coal-mining) to gross exaggeration (cuttings falling from a truck) to falsely attributing accidents to fracking when they're just associated with the gas industry generally (compressor accidents, pipeline leaks).

So is, say, 25 real “fraccidents” too many? Maybe. The reality is that oil & gas extraction is dangerous. All extractive industries carry the potential for pollution, whether that's fracking for shale gas or mining neodymium for the permanent magnets in wind turbines. With 9,000 active wells in Pennsylvania producing 4 trillion cubic feet of gas over 6 years, 25 accidents doesn't seem like a whole lot to me.

It isn't a great surprise that much fracktivism is disingenuous. After all, the movie that essentially started the whole anti-fracking hysteria, Gasland (on Netflix), is a stunningly dishonest piece, as exposed by FrackNation (also on Netflix). The truth is that almost all real “fraccidents” are wastewater leaks, which are actually pretty rare, but do happen occasionally.

The idea that we need better regulation of wastewater storage and disposal practices is worthy of consideration, and enforcement must be adequately resourced, but the way to argue these points is not with alarmist lies, hysterical exaggeration, and presenting personal anecdotes as fact.

Josh Fox (Gasland) found a dozen people who claim that “fracking” has destroyed their lives. Phelim McAleer (FrackNation) found a dozen who claim that “fracking” is essential to their economic survival. Neither is a sound basis for forming a personal opinion, much less government policy. I could easily find a dozen people who claim to have been abducted and anally probed by aliens. I could make an engaging and emotional documentary about it. But that doesn't mean that we need a government policy to deal with the alien abduction problem. Policy should be based on expert analysis of evidence.




Wednesday, August 13, 2014

The Problem with Fracking: Part 2

In the first part of this series, I demonstrated, by correcting a representative anti-fracking graphic with a few simple facts, that contamination of aquifers by fracking fluid or hydrocarbons from the completion of a shale gas well is highly implausible due to the natural barrier between the two in the Marcellus shale.

In this second part, I will argue both that the composition of fracking fluid is benign and that, even if it weren't, it wouldn't matter. Hopefully putting to bed another fracktivist fable.

 

Sensationalism and Ignorance

The myth goes something like this: “fracking is pumping millions of gallons of a cocktail of poisons into the ground”. The majority of people who believe this do so because they've been misinformed, usually by people who claim to understand fracking and ought to know better, often by people who actually do know better and are compartmentalizing, and rarely by idealogical liars.

Much fracktivist propaganda exploits public scientific ignorance and chemophobia (“Eek! It's full of chemicals!”).

Not everyone is, or can be, highly scientifically literate, but to most of us, who don't know our isomethyloxidocarbonoxybenzoic acid from our isopropanylmethylphosphonofluoridate, these claims about an absolutely real fracking fluid component sound very scary: 
  • Component X is a powerful industrial solvent.
  • Component X is based on the highly reactive hydroxyl radical, known to mutate DNA, denature proteins, disrupt cell membranes, and chemically alter critical neurotransmitters.
  • Component X is a CNS (central nervous system) depressant, and can cause cerebral edema and brain herniation.
  • High levels of Component X have been found in tumors excised from cancer patients.
Are you scared yet? You should be: water is scary stuff!

The most common metric of toxicity is the median fatal dose, (LD50) usually expressed in wt/wt form, such as mg/kg (milligrams of toxin per kg of bodyweight) for lab animals like rats or rabbits (with certain caveats, we usually make the assumption that this “scales up” to people, at least roughly). The LD50 for water is 90 g/kg; this means that if 100 people, each weighing 80 kg (176 lbs) drank 7.2 liters (1.9 US gallons) of water in one sitting, half of them would die. Water is toxic.

This toxin, water, is “a powerful industrial solvent”. So what! Alternative uses of a substance tell you absolutely nothing about its safety.

Both sides of the fracking debate are absolutely rife with “danger by analogy” or “safety by analogy” fallacies, sometimes about the same substance. For example, a fracktivist might tell you that potassium chloride is the poison used in death by lethal injection, while a fracking proponent might tell you that potassium chloride is a harmless substitute for regular table salt. Both of these statements, on their own, are entirely true.

Now it would be tempting to damn both sides for making such fallacious arguments. After all, both “true” statements in the preceding paragraph are equally misleading, aren't they? Well, no, not quite. When we're talking about fracking, the concern is not that someone will accidentally inject fracking fluid intravenously, it's that someone will inadvertently ingest something contaminated with fracking fluid. In context, one of the analogies parallels the implied concern (ingestion vs. ingestion) and the other one doesn't (ingestion vs. injection).

Ultimately, there are three key points here:
  • misleading phraseology can make anything look extremely dangerous to a superficial reading;
  • simply asserting that something is “toxic” is meaningless without information about dosage (how much) and delivery (oral, skin, IV);
    • also, using more specific terms like “neurotoxic”, “hepatotoxic”, “cytotoxic”, “carcinogenic”, “teratogenic”, “mutagenic” doesn't change that; and
  • alternative uses for a substance are not indicative of their safety or otherwise.
Now, bearing these facts in mind, read this sensationalist article from Business Insider.  

 

Incidental Constituents

Let me ask a question:
  1. What would you think of a father who added acrylamide and nitrosamines to his child's food?
If we hadn't already dispensed with “danger by alternative uses”, I could probably ram home the psychopathic perversity of this parent by noting that acrylamide is a poison and carcinogen used in the manufacture of plastics and pesticides and in sewage treatment, and nitrosamines are known carcinogens used in the manufacture of rubber, pesticides, and cosmetics.

Now that you want to lynch the parent from the nearest tree for adding dangerous chemicals to their child's food, let me ask you a second question:
  1. What would you think of a father who gave his child a hot dog?
According to fracktivist logic, 1. and 2. are exactly the same thing.

Whenever you see anti-fracking propaganda saying that “oil companies used millions of gallons of products containing benzene and toluene in fracking fluid”, as in the above-linked article, it's undeniably true. Light hydrocarbons — including benzene, toluene, and others — occur incidentally in minute quantities in petroleum distillates, which are used directly as lubricants and indirectly as carriers for other additives. They are present, just as acrylamide is present in baked goods, such as a hot dog bun, and nitrosamines are present in cured and cooked meats, such as a wiener. But there is a huge difference between something being present incidentally in minute quantities, and being added with deliberate intent and depraved indifference to public safety.

The truth is that “Big Oil” is no more adding benzene to fracking fluid than Oscar Mayer is adding nitrosamines to bacon.

 

The Same, or Worse

Some of the most hysterical reactions to fracking fluid constituents are prompted by aromatics — hydrocarbons that contain 6 carbon atoms in a loop called a benzene ring that are often carcinogenic — such as benzene itself, toluene (a benzene ring with one methyl group), and xylene (a benzene ring with two methyl groups).

Natural gas, including shale gas, is a mixture of a large number of hydrocarbons. The composition varies widely from reservoir to reservoir, just as the composition of oil from Saudi Arabia, Texas, and the North Sea differ. We can say that it is mostly methane, ethane, propane, and butane, but also that it contains, amongst other things, benzene, toluene, xylene, and other aromatics.

The lithostatic overburden pressure (due to the rock above) in the Marcellus formation is probably something in the region of 400 to 500 times atmospheric pressure and the temperature is also considerably higher than at the surface. When the reservoir fluid is brought to the surface, it expands and cools. Some constituents remain or become natural gas and some condense into a liquid, called condensate. It can be pretty difficult to get an idea of the exact composition “deep in the ground” because data are published separately for natural gas and condensates at surface conditions, but the gas typically contains only minute traces of aromatics (0.005%), while the liquid condensate can contain aromatics at concentrations between 0.2 and 12%. What we can say is that there are a lot of aromatics in the ground and the concentration is non-negligible.

Why would a reasonable person care about pumping fracking fluid that has a trace of toluene in it into a formation where the concentration of toluene is 100 times higher? It makes no sense. We would all agree that discarding a lit cigarette butt is generally bad because it creates a fire hazard, but discarding it into a blast furnace is another thing entirely.

 

The Real Question

The proper concern about any component of fracking fluid is “is this substance harmful in the concentrations found in fracking fluid?”

We can vacillate endlessly about individual components, but ultimately, the simple answer is “no”.

Furthermore, whatever the components of any real-life fracking fluid, the same in higher concentrations or much, much worse is already down there, and some of it ends up in the fracking fluid that returns to the surface when the frack-job is done. This is the reason why it is the waste water after fracking that should be the focus of environmental concern, and not what “Big Oil” is putting in the fracking fluid. Conflating the two, as fracktivists are wont to do, is worse again.

Saying things like “fracking is pumping millions of gallons of a cocktail of poisons into the ground” is a shibboleth for reflexive opposition and ignorance of the real environmental issues.

In the next instalment, I will deal with the question: “When is fracktivism really about fracking?”

Monday, August 11, 2014

The Problem with Fracking: Part 1

The problem with fracking is that fracking itself is fairly benign. It's really the associated wastewater disposal that presents the most serious environmental challenge.

Almost every day, I see anti-fracking posts on Facebook. About once a month, I get handed anti-fracking leaflets on the street. All of these tell me that fracking is bad because of, amongst other things, the risk of contamination of drinking water aquifers with fracking fluid and hydrocarbons from the completion, as depicted in this graphic that I found via Google Image Search:

“Gasland” Fracking Graphic

The problem with this is that it's a lie. In this first instalment of The Problem with Fracking series of blog posts, I'll explain why.

Aquifers used for drinking water and irrigation are usually shallow, something like a few hundred feet down. Anything over 500 feet down is considered a “deep bedrock aquifer”. There are a couple of reasons why shallow aquifers are preferred: economics and water quality. As a general rule, the deeper you go, the worse the water. The reason for this is that temperature and pressure rise as you go down, with a corresponding increase in the proportion of dissolved salts in the water. Geothermal plants, where the water comes from deep underground at high temperature, regularly measure salinities as high as 20% (sea water is about 3.5%).

Most shale gas plays occur at depths of around 10,000 feet. The famous Marcellus shale is often chosen to exemplify the problems with fracking because it is well-known, vast, and unusually shallow in places, but still about 5,000 feet to the top of the formation, with an average well depth of 6,300 feet.

Marcellus Shale

I've said that the graphic above is a lie, so it's reasonable to ask what happens if we correct it? I took the number of pixels from the “surface” to the bottom of the water well on the right, dramatically shown with a big yellow flame on top, and found it to be 90 pixels. The average depth of a domestic water well in Pennsylvania is 200 feet, or 4.4 feet per pixel. At this vertical scale, the picture becomes:


So as not to be accused of hypocrisy, here's what it looks like if we correct the aquifer depth and fracture tops to their worst-case values (1,000 feet and 4,500 feet, respectively):


So, now we have something a little more honest, but there's also the issue of the composition of the rock. With its choice of color, the graphic implies that the gas play and the aquifer are part of the same rock formation. I have little doubt that the color is chosen to be suggestive of sandstone, which is typical of the permeable rock found in both aquifers and oil reservoirs, but these aren't called shale gas plays for nothing, and, in this case, it isn't called the Marcellus shale for nothing, so let's add somewhat plausible Pennsylvania stratigraphy (I've changed the color of the gas shale from black to light bluish gray to retain easy visibility of other features, such as the completion; other colors are unchanged):


This final diagram couldn't honestly be described as “representative”, because it stretches the facts to within a hair's breadth of breaking-point, yet it still leaves an impermeable barrier totalling over a kilometer of rock in three facies between the worst-case fractures and the worst-case aquifer. At least this diagram bears some passing resemblance to the truth, but the original is outright


It is possible for groundwater contamination to occur at the surface, but fear of aquifer contamination from the completion, as depicted in the original graphic, is about as reasonable as the premise of Black Sheep.

The next installment of this series will demonstrate why another hobby-horse of anti-fracking hysteria — the composition of fracking fluid — holds no water (pun intended).

Thursday, August 7, 2014

On the Datatype of Matrix Indices

Computer science purists often try to convince me that size_t is the appropriate type for matrix and vector indices in C or C++. This is always asserted without further justification as if it were commonly accepted. When I say “a matrix index isn't the size of anything, so the burden of establishing that size_t is the ‘one true type’ for these indices lies with you”, I'm generally either insulted or berated, but a strong rational justification has yet to be presented.

My position is that any unsigned integral type is unsuitable for use as a general matrix or array index in computational science.  My argument is essentially a utilitarian one: that pragmatism should win over naïve pedantry.

The most succinct expression of my reasoning is that, from an algorithmic perspective, it is, in general, highly desirable that indices approximate a group under addition (as closely as we can with finite size), and that using any unsigned integer type unnecessarily deprives index variables of the ability to store the additive inverse.



The argument that, formally, matrix indices are natural numbers, {1, 2, 3, ...}, holds very little weight in this argument, since C and C++ already base arrays at zero. I maintain that the ultimate reason for this is the utility of having the additive identity, 0 (zero).

Matrix-oriented languages, like Fortran and Matlab, despite basing indices at 1, do not restrict the datatype of variables used as indices strictly to the set of natural numbers. That is to say that, in these languages that are specifically and explicitly matrix- and vector-oriented, provided that an index variable is a valid index when it is used as an index, the values that it takes at other points in a program are unconstrained. I would take some convincing that the exact opposite should be the case in C or C++, yet this is precisely the position that purists ridicule me for opposing. If you were to suggest to a Fortran or Matlab programmer that assigning zero or a negative number to an index variable at any point in a program should cause an error, I would expect them to be so puzzled by the sheer stupidity of it that they would have extreme difficulty articulating why this is a bad idea.

If unsigned indices were genuinely as good an idea as the pedants would have you believe, one might expect that in 57 years of Fortran and 30 years of Matlab, it would have been tried out and been such a great success that it would have caught on, but that is clearly not the case. Fortran, in fact, allows you to define the index range of arrays to accommodate negative indices. If this were something C-specific, one might expect that the C standard would incorporate this idea, yet it does not (§6.5.2.1 “Array subscripting” uses int) and x[-5] is perfectly valid.

The reality of doing computational linear algebra is that, although indices are non-negative integers, the arithmetic manipulation of indices in the course of executing an algorithm often, if not usually, involves not just subtraction, but negative numbers even if the eventual index computed is always non-negative. Consider, for example, the diagonal matrices formed from the stencils of finite difference methods. It would add nightmarish complexity to restrict the relative indices of the stencil to non-negative integers. What would a lower boundary check, now a trivial if(i<0) {... }, become if i were not allowed to be negative?

It might be argued that, in these cases, one “ought” to do these index computations with a signed type so as not to “pollute” the index type with negative numbers, but what exactly is the benefit of doing this? I mean, other than the smug self-satisfaction of being an über-pedant?

In practice, if you attempt to use an unsigned integer type for indices, but a signed type for index calculations, you have to add a lot of casts to silence warnings, and this quickly becomes so onerous that one either ends up either with ill-considered casts that may accidentally mask true errors, or such diligent consideration of whether a cast is truly correct that “cast contemplation” becomes a major, if not the dominant, contributor to development effort.

Again, the pedant might argue that you should have to consider these cases; that it is not a bad thing to have your development time doubled if that means it's correct. But is it “correct”? What does this “correctness” buy me? What are the actual benefits?

Well, the only one I've ever heard is this: “because size_t is the canonical type used to represent sizes in C, such as in calls to malloc(), size_t is the correct type for indexes because it guarantees that they can index any array returned by malloc() irrespective of the platform”. Really? That's it?

Leaving aside the fact that this is really an argument for choosing one of size_t and ssize_t, and I hope I've convinced you that ssize_t would be the better option, this “guarantee” is worthless, because flexibility in the representational range of a datatype used as a matrix index is, at best, useless.

The range of values that you need to use as a vector or matrix index isn't defined by what size objects you can malloc(), it's defined by the problem that you're trying to solve. So, there are actually only two scenarios that merit consideration:
  • size_t is big enough to represent all problem indices; and
  • size_t is too small to represent all problem indices.
In the former case, which is usual, choosing size_t over, say, int32_t doesn't matter, and in the latter case, you have an issue so major that, not only does it not help, but it probably exacerbates.

Suppose that the problem of interest is such that indices need to go up to 1,000,000. You develop a solution under a 32-bit memory model where size_t is 4 bytes. Going to a 64-bit memory model where size_t is 8 bytes is essentially trivial and presents no problem (no matter the choice of datatype for indices) other than doubling the memory requirement for indices, which is not a good thing. However, going to a platform where size_t is 2 bytes is going to be very difficult: you're going to have to do quite a bit of memory management and index segmentation and manipulation to be able to solve your problem under this constraint, and direct indexing is more-or-less off the table. If you have chosen size_t for your indices, you now also have to contend with having 2 bytes automatically hacked off all of them, even in places in your code where no array is indexed; in all likelihood, this is going to make solving the issue more difficult instead of less.

So the correct answer to the question “what datatype should I use for matrix indices” is a signed integer type that is sufficiently large to represent all anticipated indices. Moreover, the correct answer to the question “what datatype should I choose for problem X” is “whatever is required by problem X” and not something provided by the compiler or platform for some other purpose.

Thursday, June 5, 2014

The “Secret to Happiness” Isn't on LinkedIn

LinkedIn's machine learning algorithms have decided that I need to be emailed daily with vacuous deepities from every self-proclaimed “life coach” on their multi-million user site, when, in fact, I hold them in contempt and put them into two categories: charlatans and clowns.

The charlatans prey on the insecurities that about half of us share: we don't like our jobs, we wonder if we were “meant to do” something else, our marriages or relationships could be better, we procrastinate, we feel guilty, or trapped, or unhappy or all of the above. The “cure” to all your ills is their patent medicine, their “Secret of Happiness” and as surely as snake-oil comes in a bottle, it's always the same hackneyed aphorism: “work towards being able to “pursue your passion” as a job even if it means taking a small pay-cut”, swiftly followed by a liberal dose of loosely connected banalities.

Almost worse than the charlatans are the semi-literate deluded clowns, who — having, to all appearances, dropped out of school and never been within a bull's bellow of an introductory philosophy or psychology book — nevertheless believe they're in a position to hawk hokey cornball platitudes to the rest of us (in fairness, I don't know if this particular “coach” is a charlatan or a clown, but, either way, I wouldn't give you the gum off the back of a stamp for five hundred of her moth-eaten potboilers).

The reality is that happiness is amenable to scientific inquiry and can be studied empirically. There are legitimate “happiness researchers” in psychology, psychiatry, and neuroscience. Here's the upshot of what we know: happiness is approximately
  • 50% genetic,
  • 40% attitude, and
  • 10% all the shit people think it's about.
If you're wondering what the hell I'm talking about, then you may have lucked out in the genetic component and just be naturally predisposed toward happiness, as opposed to your less fortunate counterpart on the other side with dysthymia.

But the really important points here are twofold:
  • your “career”, relationships, finances, etc. basically don't matter a shit; and
  • you can learn to change your “attitude”.
So you're really happy with the promotion you got today? Won the lottery today? Feeling on top of the world? In 6 months, you'll be at about the same level of happiness that you were up to yesterday. Just lost your legs in a car accident? Feeling suicidal? In 6 months you'll be at about the same level of happiness that you were up to yesterday. We adjust.

Empirical evidence suggests that spending 15–30 minutes every day cultivating mindful awareness or practising CBT techniques will do more for your long-term happiness than any new job, spouse, or money, and certainly more than any vapid drivel peddled on LinkedIn.