Tuesday, 20 September 2016

Is Apple A Christian Environment?

There's an article in Tech.Mic, syndicated to the New Zealand Herald and probably other places, about sexism in Apple's workplace culture. Most of it sounds all too plausible :-(. I haven't seen many examples of this sort of behaviour at Mozilla or elsewhere, but I wouldn't expect to have since, very sadly, I haven't had many chances to work with women in the office.

One detail doesn't sound right, though:

"several people" who have quit, citing a "white, male, Christian, misogynist, sexist environment"
Is Apple really a Christian environment? In my experience of the Silicon Valley technical workforce, Christians are extremely scarce and most of those keep quiet about it at work ... often for good reason. The environment is, in fact, fairly Christian-hostile. In social settings I have sometimes been in conversations where people started talking about what idiots those Christians are, assuming everyone present shares such views, and I'm sure there are more when I'm not around! I find it hard to believe Apple is different. (I know it's a cult, but not that kind of cult :-).)

I guess the quote probably meant "Christian" as some kind of general, malign force of culture and tradition, only loosely connected to actual Christians and Christianity. Regardless, it's frustrating to be saddled with.

Monday, 12 September 2016

Theism And The Simulation Argument

The simulation argument is quite popular these days; Elon Musk famously finds it compelling. I don't, but for those who do, I think it has an important consequence that is obvious yet underappreciated: if we live in a simulation, then a form of theism is true. If the simulation argument is valid, then atheism is improbable.

The agent responsible for the simulation would be the God of our universe: it intentionally designed, created and sustains our universe for some purpose. (That purpose might have nothing to do with us or our pocket of the universe, but since life on Earth is the most complicated system we have observed so far, we can at least take as a working hypothesis that the purpose is connected to us.) This already implies we have at least a God of classical deism.

Furthermore, if we can use our simulations as an analogy, we should assume the simulating agent has ongoing access to the substrate running the simulation and the ability to modify its state. In other words, the agent is likely to be omnipotent (in our universe) and miracles are possible. (This is not the "can make a rock so heavy he can't lift it" straw-man omnipotence targeted by many atheists, but it's well within Biblical parameters.) It's also possible for the agent to reveal itself to us, and that it might want to.

The other two "omnis" do not seem to follow. I see no reason to believe that the simulating agent would be omniscient, even just about our universe. Likewise I see no reason to believe it would be omnibenevolent. However, being omnipotent, it could make us believe it was omniscient and omnibenevolent if it wanted to.

I don't expect to see proponents of the simulation argument in churches en masse anytime soon :-). However, they should be taking theism seriously and atheism not seriously at all.

Saturday, 3 September 2016

Auckland Food 2016

Here are some places I like at the moment, valuing not just quality but also interest and value for money.

  • Uncle Man's on Karangahape Road (Malaysian). Best roti in the city in my opinion. Just a little bit better than Selera and Papa Rich.
  • Cafe Abyssinia in Mt Roskill. The only Ethiopian food in Auckland that I know of.
  • Kairali in Royal Oak. Good cheap South Indian food.
  • Jade Town on Dominion Road. Uyghur food, i.e., far-western Chinese. Get there early, around 6pm, or their specials are sold out.
  • Hog Heaven in Newmarket. The pulled pork sandwich is delicious. Go there soon because there's not much traffic and I fear it has not long to live.
  • Momotea in Newmarket and elsewhere. Decent food but their real attraction is their Taiwanese-style drinks and desserts. I like the black sesame milkshake and the "Momo Redbean Ice", perhaps the only time I've found a dessert to be bigger than it looks on the menu.
  • Viet Kitchen on Dominion Road. The pork-and-prawn pancake is delicious.
  • Hansan in Newmarket and elsewhere. Nominally also Vietnamese, but a different style that I've been told is more Cambodian. I think the food's generally less good than Viet Kitchen but it has milkshakes and desserts which I greatly enjoy, especially the coconut-banana-sago pudding.
  • Tombo in Newmarket, Korean-Japanese. The lunch boxes are good, and the dinner buffet is great, if a little overpriced.
  • Smile Dessert in Somerville. High-end Chinese dessert restaurant which also sells light meals. I like the walnut and black sesame soup.
  • Dae Bak in the city. Great value Korean BBQ buffet ($20 lunch, $22 dinner). A bit less variety than Gangnam Style in Takapuna, but cheaper, easier to get to, and a less cringe-worthy name.

Wednesday, 31 August 2016

Avoiding Cache Writebacks For Freed Memory

I wonder how much memory traffic is generated by the CPU writing out evicted cache lines for memory locations the application knows are dead because they belong to freed memory. This would be interesting to measure. If it's significant, then perhaps the application (or some lower level of the software stack) should be trying more aggressively to reuse freed memory, or perhaps it would be valuable to have hardware support for invalidating cache lines without writing them back. Though I suppose the latter case is problematic since it would make buggy software nondeterministic. At the OS level Linux has madvise(..., MADV_DONTNEED) to clear unwanted pages, but I'm not aware of anything analogous for the CPU cache.

Update Xi Yang pointed me at a paper on exactly this topic: Cooperative Cache Scrubbing.

For modern Java programs, 10 to 60% of DRAM writes are useless, because the data on these lines are dead - the program is guaranteed to never read them again.
That's a lot more than I expected! It would be very interesting to know what these numbers are for C++ or Rust programs. If the numbers hold up, it sounds like it would be worth adding some kind of hardware support to quash these writes. It would be nice to avoid the problem of nondeterministic behavior for buggy software; I wonder if you could have a "zero cache line" instruction that sets the cache line to zero at each level of cache, marks the lines as clean, and writes zeroes to RAM, all more efficiently than a set of non-temporal writes of zero. Actually you might want to be able to do this for a large range of virtual addresses all at once, since programs often free large chunks of memory.

Wednesday, 24 August 2016

Random Thoughts On Rust: crates.io And IDEs

I've always liked the idea of Rust, but to tell the truth until recently I hadn't written much Rust code. Now I've written several thousand lines of Rust code and I have some more informed comments :-). In summary: Rust delivers, with no major surprises, but of course some aspects of Rust are better than I expected, and others worse.

cargo and crates.io

cargo and crates.io are awesome. They're probably no big deal if you've already worked with a platform that has similar infrastructure for distributing and building libraries, but I'm mainly a systems programmer which until now meant C and C++. (This is one note in a Rust theme: systems programmers can have nice things.) Easy packaging and version management encourages modularising and publishing code. Knowing that publishing to crates.io gives you some protection against language/compiler breakage is also a good incentive.

There's been some debate about whether Rust should have a larger standard library ("batteries included"). IMHO that's unnecessary; my main issue with crates.io is discovery. Anyone can claim any unclaimed name and it's sometimes not obvious what the "best" library is for any given task. An "official" directory matching common tasks to blessed libraries would go a very long way. I know from browser development that an ever-growing centrally-supported API surface is a huge burden, so I like the idea of keeping the standard library small and keeping library development decentralised and reasonably independent of language/compiler updates. It's really important to be able to stop supporting an unwanted library, letting its existing users carry on using it without imposing a burden on anyone else. However, it seems likely that in the long term crates.io will accumulate a lot of these orphaned crates, which will make searches increasingly difficult until the discovery problem is addressed.

IDEs

So far I've been using Eclipse RustDT. It's better than nothing, and good enough to get my work done, but unfortunately not all that good. I've heard that others are better but none are fantastic yet. It's a bit frustrating because in principle Rust's design enables the creation of extraordinarily good IDE support! Unlike C/C++, Rust projects have a standard, sane build system and module structure. Rust is relatively easy to parse and is a lot simpler than C++. Strong static typing means you can do code completion without arcane heuristics. A Rust IDE could generate code for you in many situations, e.g.: generate a skeleton match body covering all cases of a sum type; generate a skeleton trait implementation; one-click #[derive] annotation; automatically add use statements and update Cargo.toml; automatically insert conversion trait calls and type coercions; etc. Rust has quite comprehensive style and naming guidelines that an IDE can enforce and assist with. (I don't like a couple of the standard style decisions --- the way rustfmt sometimes breaks very().long().method().call().chains() into one call per line is galling --- but it's much better to have them than a free-for-all.) Rust is really good at warning about unused cruft up to crate boundaries --- a sane module system at work! --- and one-click support for deleting it all would be great. IDEs should assist with semantic versioning --- letting you know if you've changed stable API but haven't revved the major version. All the usual refactorings are possible, but unlike mainstream languages you can potentially do aggressive code motion without breaking semantics, by leveraging Rust's tight grip on side effects. (More about this in another blog post.)

I guess one Rust feature that makes an IDE's job difficult is type inference. For C and C++ an IDE can get adequate information for code-completion etc by just parsing up to the user's cursor and ignoring the rest of the containing scope (which will often be invalid or non-existent). That approach would not work so well in Rust, because in many cases the types of variables depend on code later in the same function. The IDE will need to deal with partially-known types and try very hard to quickly recover from parse errors so later code in the same function can be parsed. It might be a good idea to track text changes and reuse previous parses of unchanged text instead of trying to reparse it with invalid context. On the other hand, IDEs and type inference have some synergy because the IDE can display inferred types.

Saga Of The Exiles

When I was younger I was a huge fan of Julian May's sci-fi/fantasy Saga Of The Exiles. I've re-read some of it recently to see if it's really all that good. It is, and I highly recommend it. The setting is strong: in the not-far future, humans develop magical psychic powers and join the Milieu, a society of similarly-psychic alien races. This society's misfits are sent through a one-way time portal six million years into Earth's past --- where it turns out to be already occupied by warring alien races with similar powers. May places some deeply interesting characters into this setup, then charts their adventures over the course of the four main books and introduces more major elements. Another book, Intervention, explores the events leading from our present (well, 1980's present) to joining the Milieu, and caps off the Exiles story arc with a truly epic twist.

In my opinion, it's all very well done. May seems to be a polymath; according to Wikipedia she wrote thousands of encyclopedia articles about science, and also helped write a Catholic catechism. Along with swords, psycho-sorcery and sci-fi trappings, her stories are full of convincing geology, flora, and fauna, and she pulls in some theology too.

In addition to the books mentioned above, she wrote a "Milieu trilogy" set after the Intervention. I found these disappointing and would recommend not reading them. The main problem is that the key events in that period have already been outlined in the other books; to give the Milieu trilogy some suspense, she adds new plot elements that don't seem to fit, and then the really important events are given short shrift.

For some reason these books seem to be less well known than contemporaneous opuses such as The Belgariad or The Chronicles of Thomas Covenant. That's a shame. I think they'd be great material for a TV series. You'd need an enormous special-effects budget, but there's lots of material to enthrall audiences (and yes, plenty of sex and violence), and more big and original ideas than the usual "Tolkien with the serial numbers filed off".

Tuesday, 16 August 2016

False Accusations

One of the problems with false or hyperbolic accusations is that they encourage your target to do the very thing you falsely accuse them of doing. E.g., if the company isn't collecting private data but you make people believe they are, then perhaps they might as well collect it. If you actually care about the issue in question, this is likely to be counterproductive to your cause.

I understand the urge to lacerate an opponent and I've been guilty of it myself, but I'll try to keep the above in mind.

Another reason to restrain oneself is given by C. S. Lewis:

“Suppose one reads a story of filthy atrocities in the paper. Then suppose that something turns up suggesting that the story might not be quite true, or not quite so bad as it was made out. Is one's first feeling, 'Thank God, even they aren't quite so bad as that,' or is it a feeling of disappointment, and even a determination to cling to the first story for the sheer pleasure of thinking your enemies are as bad as possible? If it is the second then it is, I am afraid, the first step in a process which, if followed to the end, will make us into devils. You see, one is beginning to wish that black was a little blacker. If we give that wish its head, later on we shall wish to see grey as black, and then to see white itself as black. Finally we shall insist on seeing everything -- God and our friends and ourselves included -- as bad, and not be able to stop doing it: we shall be fixed for ever in a universe of pure hatred.”