Friday, June 22, 2018

A Gotcha in Variable Initialisation in Golang

I'm new to Golang development, and there are lots of things I consider weird with the language. I've just discovered this gotcha, luckily before any code went live, so I figured I'd post about it.

Variables of the same name can be declared at multiple scopes within the same function, and as functions can return tuples, it's possible that, when declaring and initialising variables at the same time, you intend to actually reuse a previously declared variable.

For example:

  x := 1
  y := true
  if y {
    z, x := DoSomethingThatChangesX(x)
    fmt.Printf("Output: %d, %d", x, z)

  fmt.Printf("If x is 1, oops: %d", x) // x == 1

The output of this will show that the x that is set as an output of DoSomethingThatChangesX will not be the same x as in the outer scope.

This next version shows how the code can be changed, in quite an ugly way, to avoid the gotcha:

  x := 1
  y := true
  if y {
    var z int
    z, x = DoSomethingThatChangesX(x)
    fmt.Printf("Output: %d, %d", x, z)

  fmt.Printf("If x is 1, oops: %d", x) // x != 1

By separately declaring z before initialisation, z and x can both be assigned a value separately to declaration.

I know this will come across as pretty simplistic, and is obvious when you think about it, but I still think it would be really easy to increase some subtle bugs, which even careful eyes might not spot, because of it.

Monday, October 16, 2017

A Challenge for Homeopaths

Homeopathy is a body of "knowledge" wherein it is believed that ingredients that cause a symptom when consumed in full strength can be used to treat health issues that have those same symptoms.

At least some homeopaths cause patients to delay real treatment for diseases like cancer, and thereby to die.

The discipline (in the sense of its adherents being disciples) was created, entirely out of whole cloth, at a time when placebos could conceivably be better than the real medical treatments of the day. That's one proposed reason for its rise in popularity.

Not coincidentally, homeopathic remedies require extreme dilution, to the point where the mathematical modelling demonstrates that the remedy contains none of the original active ingredient.

Homeopaths claim that a higher amount of dilution, even well past the point where there is nothing left but water, boosts a remedy's strength and effectiveness.

I'm sure this is an overly simplistic summary of homeopathy. Just as there are entire universities where people study for many years in theology, the more fictional a structured field of study, the more esoteric the knowledge must become. Much of the body of knowledge and study must be focused on learning and developing "outs", i.e. the ability to shift goalposts in order to keep the main hypothesis unfalsifiable.

So, based on this take of homeopathy, here is my challenge:

You need not use a remedy to successfully treat a disorder, because that would allow for the aforementioned goalpost shifting ("it doesn't work if you don't believe").

I will merely supply several samples of homeopathic remedies. They will all be samples from real purveyors of homeopathy. For each sample, you need only tell me what the active ingredients are, and at what concentrations.

You can use whatever equipment you would like in order to do the analysis. You can use the samples on people - even true believers - to measure the effect; anything you like as long as the challenge is conducted with your ignorance of the source samples.

In the spirit of James Randi's million dollar challenge, and in light of my inferior financial position (given the need for escrow), I'd suggest a $1000 prize, or perhaps I can crowdfund the prize money, so you can win from lots of non-believers.

Either way, it will be worth your while to merely prove to me that your career isn't a giant fraud, and that you didn't waste all those weeks at the Unaccredited University for Fictional Studies.

Are you up to the challenge?

Saturday, January 21, 2017

Trump's Inauguration Speech

So, if you haven't, watch Trump's inauguration speech. Don't watch excerpts, which can introduce bias; go to the source and watch the whole thing.

I can see how people could see it as inspiring or uplifting, or other positive things.

I thought it was pretty worrying if seen through the lens of examples of fervent, populist movements concentrating power at the top. His references to hearing the people's voices and that people wouldn't be unheard anymore was particularly scary, as he didn't show how he'd actually be listening to individual real people, and deliberating rationally based on those inputs.

Instead, it sounds like he'll be doing what is needed to maintain that fervour and to increase his power, i.e. he'll be the figurehead of a mob. That's a power structure that is easy to exceed the limits of American constitutionalism. And without that, there's the risk of some very dark times.

But like I said, watch it for yourself. I could be wrong. I hope I'm wrong.

Tuesday, December 6, 2016

AdWords used in eBay Stores Bait-and-Switch Scam

I was looking at a device that I recently saw online - probably through Facebook marketing, called a Fidget Cube. It cost something like US$20 each or 3 for about $50, including shipping.

I almost bought it on an impulse, then decided to see how much it cost if I googled it.

Monday, March 28, 2016

Australian Senate Electoral Reform: Close, but no Cigar

In Australia, we have a great, albeit complicated-in-the-back-end, system for electing senators. Not only is it proportional so that smaller parties can get represented, but it's preferential, so people aren't pushed towards 2-3 parties due to a fear of wasting their vote.

In practice, almost every person just votes for a single party, and the party's own preferences for how that vote should be distributed are followed. This is called a Group Voting Ticket, or GVT. The effort of a person specifying all their own preferences, or even learning about more than a couple of different parties' policies, is enough to deter about 96% of the population from numbering every box for every candidate, which often reaches about 200 in total, which until recently, was the only alternative to following a party's GVT.

One area where there has been a lot of argument is that the way GVTs were being created wasn't fair, because they allowed parties to agree how to game the system by preference sharing in a way that was technically visible to voters, but invisible in practice, creating strange bedfellows. This allowed election of senators with sub-1% of the first preference votes to win seats after preference distribution.

Lack of transparency is an issue, but I have no problem with preferential voting systems allowing the election of people who would not have been foreseen in a non-preferential system. That's what preferences are for, after all: electing consensus candidates, rather than extremists who win a non-preferential plurality.

So, a reform that's just been made, specifically designed to exclude many minor parties from doing what was done in the last election - winning seats against the odds - has been enacted. (The government says the problem is that those who were elected in this way are not representative of Australia, but looking at the individual senators makes it clear they are far more representative of Australia than the major parties' senators.) The reform sounds reasonable, being that a person can preferentially number party boxes - as many as they'd like to express their preferences - instead of one party box or all candidate boxes.

The problem with this reform, however, is that it throws the baby out with the bathwater: some parties, specifically Pirate Party Australia in my experience, use preference deals with other parties in an open, transparent and honest way, and those parties will now be penalised by the unaddressed problem with this reform: most people still don't know enough about all the political parties, or care enough about how the system works, to vote for more than a few pairs at the top of their mind. Preferences will now be left unspecified, even where they would have clearly aligned with a voter's honest preferences.

I appreciate that the Australian Greens have said that they have had this reform as their policy for 12 years, so there should be no surprise to anybody, but the public debate was non-existent, and most people would have no clue about some old Greens policy that has had very little airtime over the intervening years. There was no Australian Law Reform Commission request for opinions, followed by a report, which would be standard practice for such an important reform.

Pirate Party Australia was calling for a, now possibly useless, non-partisan royal commission to consider different approaches that would be fair (to the voters, not the status quo). I would like to think that one solution that could have come out of that would have been this: Allow people to specify their own party preferences, just like in the current reform, but for any unspecified preferences, follow the preferences of the party in the voter's first preference.

For example, if party A had a GVT of A, B, C, D, E, F, and a voter voted A, F, D, then that would be translated into A, F, D, B, C, E.

This slight tweak to the system would have been the best of all worlds: Voters would be free to specify their own preferences, without too much effort and without relying on backroom party deals, parties could have worked with like-minded parties to ensure that votes aren't exhausted, and thereby wasted, and most of the power to exploit GVTs would have been removed.

Maybe this idea can be revisited after the upcoming election, but with all those independent voices set to be wiped out and a resulting, further entrenchment of power upon us, I'm not holding my breath.