Just When I Thought I Was Out…

In November of 2013 I attended a BarCamp Nashville session presented by Luke Stokes on Bitcoin. I’d certainly heard of Bitcoin at that point but really didn’t know much about it. I was intrigued as I left the session but didn’t follow up for several weeks. When Luke gave his presentation Bitcoin was trading at around $200. Three weeks later it was at $700. That may have had something to do with my sudden compulsion to learn more. In the meantime I made various tiny purchases over the next couple months to play with as I educated myself on how exactly Bitcoin, and cryptocurrency in general, worked.

I found Satoshi’s solution to the problem of tracking ownership of a digital asset, the blockchain, to be incredibly interesting. As I learned more I wanted some practical experience mining Bitcoin but even at that time it required specialized hardware to be viable so I turned my attention to Scrypt based currencies, like Litecoin, which could be mined using a reasonably current GPU. It was also around this time that Dogecoin made it’s debut. I loved it and the community which grew up around it and I even made a few submissions to the Dogecoin client.

I mined tiny amounts of assorted coins in the first half 2014. Mostly Dogecoin and Litecoin, which all got converted to Bitcoin and transferred to Coinbase. Once I clawed my way up to a single Bitcoin I stopped mining as my interest, and belief in crypto started to waver. Continue reading

Truth

Just about every day I wake up and wonder how it is that the world seems so broken. Maybe it’s just that I’m paying more attention and it’s always been broken. I know that’s true to a certain extent but it’s hard to look at current events and dismiss all the craziness as business as usual. But what to do about it? Do I just try shutter myself away from any news of whats going on outside the little patch of earth I inhabit? It’s hard for me to see a problem and try to keep myself from trying to find a solution. Though “fixing the world” seems like it might be a lot of work so I’ve tried my best to stop thinking about it.

It’s not really working.

Inevitably when I’m unable to stop myself wondering how we got here and how to make it better I next ask myself, okay, what exactly is broken? Can’t very well fix something until you know what the problem is. There are many but the one that really gnaws at me is our inability to agree on what is fact and what is fiction. There is seemingly no source that all can agree is an unbiased repository of truth.

When the internet was shiny and new, the naive among us, had high hopes that it would bring the world closer together. Here for everyone was the sum total of all human knowledge at our fingertips. With a snap of our fingers we could summon forth a wealth of expertise on any topic one could conceive of. The sad truth is that the internet is not just the sum total of all human knowledge but rather the sum total of all human thought. And humans have had some pretty bizarre thoughts. For every almost “fact” you can find someone on the internet willing to refute it. Once upon a time I thought sites like Snopes or PolitiFact would save us. Whenever I’d see someone suggesting things like Mark Zuckerberg was going to charging for Facebook unless you made some nonsense post, I’d try to gently nudge the misguided to a Snopes article refuting these claims. That generally worked though they might not be thrilled to discover they’ve been dupped. With more serious matters this doesn’t work so well. I personally believe that the people that run these sites do so for, generally, altruistic reasons. I’m sure there are biases but I have to believe their exist people that are more concerned with the truth and not just proving themselves right. At least I am. I don’t want to be wrong but I especially don’t want to be willfully ignorant. Still, on more that one occasion, I’ve seen people explain that Snopes is just a husband and wife googling for answers and jotting down whatever they find. The same people claim without a hint of irony, that it must be true because they googled it. And, with almost no effort, you can learn about PolitiFact’s bias against the right. Just google PolitiFact bias. And what reasonable person wouldn’t agree that random people are the internet are the more credible than documented sources. Who are these sources and how can we trust them!?

I want to believe that people could be convinced that these sorts of sites aren’t an evil conspiracy by “the left” to brainwash us into believing… I don’t know, whatever agenda it is they believe fact checking sites are trying to push. But then I consider that the Flat Earth Society has hundreds of members. Hundreds of years of physical and scientific evidence are all dismissed as a big conspiracy for… reasons. I have no idea. There are even more that believe we never landed on the moon and, despite overwhelming consensus among scientists that climate change is real, there are many many people that refuse to accept this interpretation of the evidence.

Before the internet these fabrications and fringe beliefs had a tougher time taking root. If I decided that we’re all living in a computer simulation and went around to friends and family expressing this belief they’d (hopefully) tell me that I should seek help. I haven’t googled this but I bet if I did I could find plenty of people on the internet 100% convinced this is the truth. There is probably a Matrix society for like minded individuals. So how do we fix that? Is it even fixable or are humans hard wired to be skeptical of any challenge to any deeply held belief? We could make a 100 more Snopes and end up with thousands more theories on how and why there conclusions are biased.

It’s all incredibly frustrating to me and I don’t see a quick fix. We’re not going to be able to address the real problems in the world until we reach a point where we can mostly agree on reality itself and see what the real problems are. It feel cuckoo to even have to type that out but there it is. So how do we get to that point? What would it take to create a source of knowledge that wouldn’t immediately be dismissed as a tool of the left or the right? Is such a thing even possible in society as it exists today?

for, forEach, and map (oh my)

We interrupt the recent political ramblings and assorted existential crises to bring you a post about loops in Swift.

I was tempted to use forEach today but then I started wondering what sort of overhead closures add. So I cobbled together something resembling a test. Staring with an array of ints:

var loopIndices = [Int](0..<20000)>

I used these to create characters which are appended to a string. The “classic” for loop looks like:

for ch in self.loopIndices { self.loopStr.append(UnicodeScalar(ch)?.escaped(asASCII: false) ?? "X") }

The forEach version looks like:

self.loopIndices.forEach { self.loopStr.append(UnicodeScalar($0)?.escaped(asASCII: false) ?? "X") }

I ran this test 100 times on my AppleTV and the total time for a regular for loop was 1.8076 seconds. The time in the forEach loop? 3.6851 seconds. So basically twice as long. For good measure I made a map version as well that looks like:

self.loopStr = self.loopIndices.map({ UnicodeScalar($0)?.escaped(asASCII: false) ?? "X" }).joined()

The map has to join as well so it’s not surprising that it’s basically the sum of the other two tests coming in at 5.3892 seconds. Let me summarize in this handy table:

Type Duration Comments
Basic for loop 1.8076 seconds
forEach loop 3.6851 seconds Ew
map 5.3892 seconds Super ew

I thought, since the forEach closures are not @escaping, that Swift might be able to do some trickery since it shouldn’t need to capture values, worry about memory management, etc. So on a hunch I tried the same test with release settings (basically -O -whole-module-optimization instead of -Onone) and when we do that we get:

Type Duration Comments
Basic for loop 1.5675 seconds
forEach loop 1.6468 seconds Better! Only 5% slower, but then…
map 1.5958 seconds What sorcery is this?!

This got me wondering what map looks like without the added join so instead of appending to a String we have:

var loopStrings : [String]

And running this with optimization on yields:

Type Duration Comments
Basic for loop 0.4478 seconds
forEach loop 0.5814 seconds Overhead more visible now. 30% slower
map 0.3168 seconds Maybe it make better guesses about memory allocation?

In general appending to an Array is faster than appending Strings. No surprise there, but look how much better map is. Okay, so maybe we eliminate the need to muck about with memory in our tests and see what happens. We'll take the same array of Ints but add them up or something. Hmm, but map isn't great for that sort of thing, we'll reduce instead. We'll also double the number of items in our array of ints, but this is going to be really fast and our profiling numbers may be down in the noise floor. Whatever, the original question was how much overhead do closures add? So our map is now:

self.loopTotal = self.loopIndices.reduce(0) { $0 + $1 }

And the other loops have been modified to produce the same results. In this case our times are:

Type Duration Comments
Basic for loop 0.0070 seconds
forEach loop 0.0103 seconds Not quite 50% slower
reduce 0.0093 seconds Still better than forEach

With most of the actual work stripped away we can see the closure overhead more clearly. Although it's not a constant value or it would have been at least the difference in time from the previous example (0.1336 seconds). In this case, the difference works out to an extra 3300µS over 4 million iterations. Woo. So if forEach results in code that you believe is clearer you're probably not going to notice the performance hit. But it will be there so it's probably something you want to avoid if you're looking to conserve every cycle.

My Team

Hello people. I’ve been mulling this post for awhile. It’s a bit political again I’m afraid. But then again it feels like everything’s a bit political these days.

So, there’s something that’s been bugging me for a while now. People seem to be treating their chosen political affiliation the same way they would their favorite sports team. This makes no sense to me at all. It’s like asking who your favorite football team is: offense or defense? Oh hey defense is my team and it doesn’t matter that we’re losing the game because we’re totally winning on time of possession! Or our defensive buddies over there are keeping our offense from scoring! Woo! Defense rules! Suck on that offense!

That’s kind of ridiculous. Isn’t it? Hopefully we can agree on that. Maybe?

I mean it’s simplistic but if we keep the sports analogy going, then the Democrats and Republicans would just be different strategies on what wins games. Plenty of people that can disagree whether offense, defense, special teams, or whatever, wins games. And at the end of the day all those people can come together to celebrate a victory or console one another when their team suffers a loss. And everyone’s “team” should be The United States of America and not an ideology.

Can you even begin to imagine if attitudes shifted this way? Regardless which half of the team makes a great play the other half is there to celebrate. You don’t normally hear guys after winning a game say, “well the offense once again saved our bacon. I don’t even know why we have a defense”. Even when it clearly the kicker’s fault for missing an easy field goal (laces out, Dan!), the post game talk is almost always about the team effort, not any individual, faction, or how the crowd didn’t cheer loud enough.

When I think about it, it doesn’t feel like this would be a huge shift in sentiment. Sure let’s keep the sports mentality going, but let’s treat the politicians like we do our favorite team’s coaching staff. Your team may have won a half dozen championships but turn around and lose a half dozen games and see how quick the fans are to demand the coaches head on a spike. Even if you agree 100% with a coach’s philosophy, if your team isn’t winning it doesn’t matter. For that matter it may be one player. Maybe the goalie has lost his mojo, whatever. The point is that criticizing your sports is almost expected. Everyone knows that criticism doesn’t mean you don’t love your team. I can imagine a lot of Vols fans shaking their heads sadly in agreement.

So how about that? Can we give that a try or at least keep that in mind? I’m not on team Democrat or team Republican or even the dastardly team Media (mustache twirling intensifies). I think that’s true for most people. All we really care about is our home team: USA.

The Real Battle

If you’ve ever been to a casino maybe you’ve noticed how maze-like the layout is. Also the lack of clocks and windows, the low ceilings, busy carpet, and of course all the lights, sounds, and action! I’m sure you wouldn’t be surprised to learn that this is not at all by accident. Casinos owners pour quite a bit of research into subtle (and not so subtle) psychological tricks designed to extract the maximum amount of money from you the moment you set foot in one of their establishments. Though perhaps it might come as a surprise to you just how detailed this research is. For example check out the table of contents to this 627 tome on Designing Casinos to Dominate the Competition. No detail is too small to escape the notice of the casinos!

This same research and attention to detail is applied to anything that can be marketed: food, clothing, vehicles, electronics, you name it. All around the world companies with things to sell are devoting incredible resources in discovering all the little tricks that can be employed to give them an edge in selling their product to you. Perhaps you’re skeptical on the effectiveness of marketing but the $200 billion spent every year on advertising leads me to believe that there’s probably something to it. Whether you want to believe it or not our motivations are influenced in big ways and small, directly and indirectly, by marketing and the psychological theories on which it is constructed.

And if you accept the amount of time, energy, and money spent as evidence that these psychological manipulations are effective then surely you can imagine that others have as well. For example just consider the political landscape in the United States right now. Doesn’t it seem like it we’re becoming more and more polarized? I mean come on. Sure Republicans and Democrats have always disagreed but lately it feels like the major political parties are portrayed the same way we’d present sports teams, or even as the good guys versus the villains, instead of human beings associated to some degree with a particular set of ideologies. And why do you suppose that is? Might it have something to do with the monetization of the news and political coverage? Is Rush Limbaugh going to build a more energetic audience by bringing together both sides for a reasonable and nuanced discussion about the role of government in our lives or by painting the other guys as people who literally want to destroy all that you hold dear? Of course the latter is more compelling. It’s entertainment! People want to be entertained. An thinking is work, right? The media understands this and they want to cultivate audiences that can’t wait to tune in to the next episode to see what their heroes (or the dastardly villains) are up to now!

Does that not seem just the tiniest bit plausible? Or do we accept that this continued polarization is occurring organically? Now I’m not necessarily saying that all of the networks execs are in this cabal sitting around smoking their cigars, cackling maniacally whilst rubbing their greedy little hands together as they plot unrest amongst their audiences all in the name of corporate profits. I mean maybe, but more likely the decline of the moderate is the cumulative effect of a thousands little decisions that have been made to get people more fired up and tune in to the next show. Probably seemed kind of harmless really.

Perhaps you think I should look into hat making. Specifically the tin foil variety. Trust me I’ve wondered the same. But even if we’re somehow not being influenced by the big media conglomerates there are doubtless other actors out there that are attempting to influence our thinking. We know for sure of people who deliberately set up fake news sites although it’s debatable whether they were trying to influence the election or just make a few bucks from the gullible. But certainly and more alarmingly, seventeen different United States intelligence agencies have stated with “high confidence” that Russia tried to influence American opinion during the 2016 election. And there is solid evidence throughout the election campaign, and beyond, of Russian agents posing as Americans posting their support for Trump on social media services.

Also consider “Foundations of Geopolitics” written in 1997 by Aleksandr Dugin. This book allegedly had a big influence on Russia’s foreign policy strategy. It goes into detail on strategy with regard to almost every nation and has this to say one the approach to take with the United States:

  • Russia should use its special forces within the borders of the United States to fuel instability and separatism, for instance, provoke “Afro-American racists”. Russia should “introduce geopolitical disorder into internal American activity, encouraging all kinds of separatism and ethnic, social and racial conflicts, actively supporting all dissident movements – extremist, racist, and sectarian groups, thus destabilizing internal political processes in the U.S. It would also make sense simultaneously to support isolationist tendencies in American politics.”

Does this sound at all familiar? Maybe a teeny bit?

I expect, if you’re one of the millions of people that voted for Trump, it’s not easy to confront the possibility that you may have been influenced by Putin and friends. But closing your eyes to the possibility that the Russians may have played a role will not help matters. Though if it makes you feel better there are almost certainly other countries and organizations that have successfully influenced many to take opinions opposite your own. And, if the excerpt mentioned above can be trusted, maybe even those same Russians. Their strategy is to sow discord and it seems to be working!

What’s important to understand is that there are all of these invisible forces out there trying to guide us towards decisions or beliefs to further their own aims and not necessarily those that are best for ourselves, our community, nation, planet, etc.

I believe the modern battlefield is located between our ears and that many lose their battles without ever realizing there’s been one. Once we realize that our thoughts are under attack we can begin to defend ourselves by questioning our motivations and influences. By making sure we’ve fearlessly examined an issue from all angles including especially opinions from those we dislike or might normally disagree with. And that we continue to keep an open mind to new facts and input. I believe that if we put one tenth of the amount of effort into challenging our beliefs as we do seeking out validation for them that the world would be a better place. We need to take a step back and realize that Republicans and Democrats are not enemies, rather those who cultivate that belief are the true enemies.