Noda Time 3.0.0 came out yesterday1, bringing a shiny
new parcel of date- and time-related functionality.
What’s new in 3.0? Firstly, there’s a couple of things in 3.0 that just
plain make it easier to use Noda Time:
Nullable reference types. The API now correctly uses the
nullable reference types introduced in C# 8.0 to document when a
method or property may accept or return a null value.
Nullability was previously noted in our documentation, but now (with
appropriate compiler support) you can opt-in to warnings that indicate
where you might be accidentally passing a null somewhere you shouldn’t.
A plethora of API improvements. For example, we now have a
YearMonth type that can represent a value like “May 2020”;
TzdbDateTimeZoneSource now provides explicit
dictionaries mapping between TZDB and Windows time zone IDs; and
DateAdjusters.AddPeriod() creates a date
adjuster that can be used to add a Period to dates, along with many
other improvements. As always, see the version history and API
changes page for full details.
A single library version. Previous versions of Noda Time were slightly
fragmented when it came to supporting different framework versions. For
example, Noda Time 1.x was specific to the .NET Framework, and later added
a Portable Class Library version that was missing a few key functions,
while Noda Time 2.x again provided a separate .NET Standard version that
differed slightly from the ‘full’ version. As of Noda Time 3.0, we have
just one library version, providing the same functionality on all
platforms.
Better support for other frameworks. Most core types are now annotated
with TypeConverter and XmlSchemaProvider attributes. Type
converters are used in various frameworks to convert one type into other
(typically, to or from a string) — for example, ASP.NET will use type
converters to convert query string parameters into typed values — while
the XML schema attributes make it possible to build an XML schema
programmatically for web services that make use of Noda Time types.
Performance
Although not as significant as the changes from Noda Time 1.x to 2.x,
performance is still a key concern for Noda Time.
In 3.0.0, we’ve managed to eke out a little more performance for some common
operations: finding the earlier of two LocalDate values now takes
somewhere between 40–60% of the time it did in Noda Time 2.x, while parsing
text strings as LocalTime and LocalDate values using common (ISO-like)
patterns should also be a little faster, taking around 90% of the time it
did in Noda Time 2.x.
Caveats
The change from Noda Time 2.x to 3.0 is not as big a change as the one
from Noda Time 1.x to 2.0, but there are still some small incompatibilities
to watch out for.
The migration document details everything that we’re aware of, but there
are two points worth calling out explicitly:
Noda Time 3.x has (slightly) greater system requirements than Noda Time
2.x. While Noda Time 2.x required either .NET Framework 4.5+ or .NET Core
1.0+, Noda Time 3.x requires “netstandard2.0”; that is, .NET Framework
4.7.2+ or .NET Core 2.0+.
.NET binary serialization is no longer supported. While .NET Core 2.0
added some support for binary serialization, binary serialization has
many known deficiencies, and other serialization frameworks are now
generally preferred. Accordingly, we have
removed support for binary serialization entirely from Noda Time 3.x.
Noda Time still natively supports .NET XML serialization for all core
types, and we also provide official libraries for serializing using JSON
(1, 2) and Google’s
protobuf.
In general, though, we expect that most projects using Noda Time 2.x should
be able to replace it with Noda Time 3.0.0 transparently.
Availability
You can get Noda Time 3.0.0 from the NuGet repository as usual
(core and testing packages), or from the
links on the Noda Time home page.
Note that the serialization packages were decoupled from the main release
during the 2.x releases, and so (for example) there is no new version of
NodaTime.Serialization.JsonNet; the current version of that
library will work just fine with Noda Time 3.0.0.
What’s next?
Good question. While Noda Time is fairly mature as a library, we do have a
few areas we’d like to explore for the future: making use of Span<T> in
text parsing, and providing a little more information from CLDR sources
(stable timezone IDs, for example). If you’re interested in helping out,
come and talk to us on the mailing list.
And once again, I’m going to copy/paste this to produce the official Noda Time blog post. (The evidence suggests that this is the only way I’ll get any content on my personal site, after all.) ↩
[Insert obligatory “well, it’s been a while since I’ve written anything for
this blog” paragraph here.]
With 2018 finally complete, I thought it might be fun to take a quick look
at the books I read last year. All of these are from my Goodreads
profile, though
I tend not to write reviews for individual books there.
Goodreads has a “reading challenge” each year wherein you can set a target
number of books to read. In 2016, I hit my target of 34 books, albeit only
by cramming both the SRE book and The Calendar of the Roman
Republic (long story) on the last day of that year. Buoyed by
success, I increased it to 38 books for 2017… and then got distracted by
life and fell a bit short.
So, for 2018, I kept the same target as for 2017, and tried to not get
distracted. A few weeks ago, I’d got a little bit ahead of that — woohoo
me! — and decided it might be fun to put together a short review of each.
So here are all the books I read in 2018, in (roughly) chronological order.
Robots vs. Fairies, various authors
Starting off 2018, an anthology of short stories: some about robots, and
some about fairies. Definitely mixed, with a few really good ones, and
a few that are… not so good (John Scalzi’s comes to mind as one of the
latter, surprisingly).
The Fifth Season (The Broken Earth, #1), N.K.
Jemisin
So, this I definitely liked. It has a great premise, post-apocalyptic —
or maybe just apocalyptic, given the intro — fantasy, good characters,
and good worldbuilding, it won the 2016 best novel Hugo, and yet… I
haven’t picked up the series again.
I’m not sure exactly why: perhaps because of the writing style (it’s
present tense, partly in second person), perhaps because I was irritated
by the way the writer withheld some key information the characters knew,
or perhaps because of the incomplete ending. It’s possible that the
sequels are brilliant, but I haven’t got around to finding out yet.
Possibly in 2019.
Dark State (Empire Games, #2), Charles
Stross
Continuing Stross’ reboot of the Merchant Princes series, a
multiple-alternate-timeline spy/techno-thriller. Stross groks politics and
economics (and technology), so this is actually a pretty good alt-history
analysis as well as being a lot of fun. (Although if we could stop heading
towards the dystopian timeline in real life, that’d be great, thanks.)
The Night Masquerade (Binti, #3), Nnedi
Okorafor
Quoting from the one Goodreads review I did write: I was looking forward
to this offering a conclusion to the series. Well, in some ways it does do
that, and in some — quite important — ways, it doesn’t. I think I’d
have been better just appreciating the great world-building here rather
than the plot.
Beneath the Sugar Sky (Wayward Children, #3),
Seanan McGuire
So, what if fairy tales were real? What happens when they’re over? That’s
the premise of this series — in much the same way as Stross’
Equoid asks what it might be like if unicorns
were real (spoilers: sharp horns, so blood, mostly).
This book is almost-standalone, with some of the children from earlier
books going on portal-hopping adventures of their own. I liked this one a
lot more than the second book in the series, which had a different focus,
and was a bit more serious. Also, I’ve just realised that book #4
(In an Absent Dream) is out next week!
The Fox’s Tower and Other Tales, Yoon Ha
Lee
A collection of flash fiction from Yoon Ha Lee, who’s also written some
excellently weird science fiction and interactive fiction. Like
Robots vs. Fairies above, I thought this was somewhat
hit-and-miss.
The stories I enjoyed more tended to be those heavy on imagery and light
on ‘plot’ (such plot as is possible with flash fiction), though The
Stone-Hearted Soldier was an excellent inclusion, and an exception
to that rule (but also one of the longer stories).
An Unkindness of Ghosts, Rivers Solomon
A dystopian space opera set around a study of oppression and segregation
aboard a generation spaceship. The protagonists are incredibly varied and
interesting characters, though the bad guys are unfortunately cardboard.
I remember this being something I wanted to keep reading (if challenging
in parts), but I can’t actually remember any of the plot at this point.
Minor issues notwithstanding, I definitely enjoyed this.
The Arcadia Project series, #1–3
(Borderline,
Phantom Pains,
Impostor Syndrome),
Mishell Baker
From one set of neuroatypical characters to another. No spaceships here,
but an urban fantasy/mystery that posits a link between fey and Hollywood
celebrity. The whole series is great, the characters are believable and
well-rounded (and self-sabotaging and dysfunctional). I was worried that I
wouldn’t be that interested in a Los Angeles movie-town setting, but the
characters and story won me over.
This series ties with Smoke and Iron (below) as my favourite
read of 2018. Recommended.
The Gone World, Tom Sweterlitsch
So, apparently I liked this enough to give it 4/5 on Goodreads, but I
can’t actually remember anything about it. It looks like it’s a time
travel/murder mystery/apocalypse story? Perhaps I should re-read it.
Sleeping Giants (Themis Files, #1), Sylvain
Neuvel,
Told via the medium of interviews and news clippings, in the style of
World War Z, this is the story of how the discovery of a
giant robot hand plays out politically. There is some sci-fi here, but
mostly it’s the politics from Arrival that takes centre
stage.
This was alright, but again, I’ve not picked up the next in the series.
The journal/interview format makes it hard to get much in the way of
interaction between characters, and the story seemed more interested in
the politics than in the sci-fi/mystery aspect (which is fine, just not
what I was looking for).
The Red Rising series, #1–4
(Red Rising,
Golden Son,
Morning Star,
Iron Gold),
Pierce Brown
Dystopian sci-fi. The blurb says “Ender’s Game meets The Hunger Games”,
and I suppose that’s about right: the protagonist takes on the elite by
infiltrating them and subverting them from within, only this time we’re
talking about Mars, and later an entire solar system.
I enjoyed the first few books in the series, but somewhere around the
third or fourth I started to get a bit tired of the diffusion of the story
to uninteresting point-of-view characters, and also in the continuous
faux-Roman melodramatics.
The first book is definitely good by itself, and maybe I’ll pick the
series up again at some point.
Kindred, Octavia E. Butler
This is also sci-fi, or maybe fantasy1, but is probably simpler to
think of as historical fiction. A modern progressive black woman is
transported to early 19th century Maryland, deep in the
antebellum American South.
With the caveat that “modern” here means the 1970s (the book being
published in 1979), this is a fascinating story — if deeply unsettling
at times — about how culture shapes behaviour, and how social
hierarchies and systems can be justified and propagated by those within
the system.
The Pliocene Exile / Galactic Milieu series
(The Many-Coloured Land,
The Golden Torc,
The Nonborn King,
The Adversary;
Intervention;
Jack the Bodiless,
Diamond Mask,
Magnificat),
Julian May
An easy re-read. Julian May’s epic galaxy- and time-spanning series starts
with a fantastic premise: as Earth has joined a galactic federation of
sorts, and as humanity has begun to evolve psionic powers, a misfit group
of disaffected/adventurous travellers escapes into exile via a one-way
time wormhole that deposits them in France, in the Pliocene epoch, 6
million years ago2.
Without spoiling too much, the story shifts very quickly from science
fiction to something closer to high fantasy (for the first series, at
least; the second is in a more contemporary time period, and is more
‘regular’ sci-fi). Weaving mythology and an epic story, this is well
worth the time to read.
A Rag, a Bone and a Hank of Hair, Nicholas
Fisk
This YA dystopia was fun to read when I was a lot younger (it was
published in 1980; I probably read it sometime in the mid-1980s, along
with a lot of other Nicholas Fisk), but it hasn’t really held up that
well. The motivation behind the plot falls apart a bit on any analysis,
and some of the technology is a bit dated now (explanations about
miniature tape recorders, that kind of thing).
However, I do still like how the protagonist learns to interact with the
other characters (both modern, and not-so-modern), and how their attitude
changes over the course of the story, and I do still appreciate the swerve
away from hard sci-fi that happens partway through. It’s flawed, but it’s
still a classic.
The Lady Astronaut series, #1–2, plus the initial novelette
(The Lady Astronaut of Mars,
The Calculating Stars,
The Fated Sky),
Mary Robinette Kowal
Alt-history in which the author bootstraps the space race a decade early
via a meteorite-shaped forcing function. Post-steampunk, but
pre-electronic-computer; the author describes it as “punchcard punk”.
This is Hidden Figures meets Apollo 13, with a
strong focus on the racial and gender discrimination of the
1950s3.
(The novelette was published first — winning the 2014 Hugo for best
novelette — but is set some thirty or so years after the novels. I read
it first, but you could easily read it after: it’s not directly connected
to the novels.)
The novels suffer very slightly from telling two separate stories: one is
a humanity-against-the-elements story (Apollo 13 or The
Martian), while the other is a documentary about 1950s cultural
attitudes. Both are interesting stories, but I found it a little
frustrating when the story would focus tightly on the protagonist to the
exclusion of the wider global impact (pun most definitely intended).
However, overall this is definitely worth reading.
The Labyrinth Index (Laundry Files, #9),
Charles Stross
Well, we’re past the Lovecraftian singularity at this point, and it’s all
about surviving while the transhumans play. One of whom happens to be
inhabiting the Prime Minister at present, and who has opinions about
foreign policy.
Mhari, who we met in her current incarnation in The Rhesus
Chart a while back, is presently attempting
to stay alive while said elder god is playing eleven-dimensional chess
nearby. Meanwhile, the US appears to have collectively forgotten that
the executive branch exists…
I liked this a lot. Mhari was interesting without being annoying, as I
worried she might be (she was in some of the earlier books; deliberately
so in order to annoy Bob, I think). Otherwise, this was pretty much
exactly as I expected at this point in the series: a lot of fun.
Revenant Gun (The Machineries of Empire, #3),
Yoon Ha Lee
Yoon Ha Lee’s conclusion about a 400-year-old immortal general and crazy
magic that works because of a shared consensual reality. It’s military
sci-fi, kinda?
I can’t really discuss this without spoilers, but while it did more
hand-holding than earlier books in the series, it still featured a lot of
creative worldbuilding.
Lies Sleeping (Rivers of London, #7), Ben
Aaronovitch,
Like The Labyrinth Index above, by the time you get this far
into a series, you pretty much know what to expect: in this case, a fun
police procedural with magic and geeky in-jokes.
However, I did find it a bit hard to follow what was going on with the
plot here, which seemed to be both a bit muddled and to reach back over
the whole of the series. (I’ve also not read the associated graphic
novels, which might have helped, though they’re not supposed to be
necessary prerequisites.)
A Canticle For Leibowitz, Walter M. Miller
Jr.
A classic (1959) post-apocalyptic sci-fi tale published during a high
point in Cold War tensions. In the far aftermath of nuclear war, society
struggles to drag itself out of a new dark age, and to rediscover and
protect old knowledge. This is three distinct stories — originally
published as such — separated by time (centuries), and vaguely connected
by place.
This unapologetically puts forwards a Christian (specifically, Catholic)
viewpoint, with the church to some extent a main character. It has some
ironic humour, but also serious comment about ethics and human nature.
With one exception near the end, I didn’t find it to be too preachy.
It made a big impact at the time, but is it actually a good story
nowadays? Well, meh. I found it thought-provoking (and somewhat
depressing) in turns, but I can’t actually say that the story exists much
more than as a framework for the author’s viewpoints. Largely
unsatisfying, and probably more important for the historical context now.
Smoke and Iron (The Great Library, #4), Rachel
Caine
Okay, this is just brilliant. Along with The Arcadia Project series
(above), this was easily one of my favourite reads of 2018.
So, why? Well, it’s got good worldbuilding, a fast-paced (and fun) plot,
it’s got great characters and character development, and good writing.
The plot itself starts immediately after Ash and
Quill, so talking about the plot directly would spoil
the earlier books. In general, though, this series is a YA
alt-history/fantasy in which the Great Library (of Alexandria) has become
a ruthless worldwide power, tightly controlling both the dissemination of
information and also the source for some of the magic/alchemy that’s
available in this world.
On the writing: one section in particular has the viewpoint character
magically hypnotized into believing that they’re someone else, and the
author shifts the (tight third-person) text to match that impersonated
character, having the viewpoint character not just act as another, but
having the prose notice (and the character comment on internally) an
entirely different set of things appropriate for the character they were
impersonating. Subtle, but I liked it.
Murderbot is a fairly apathetic and introverted humanform security droid
that just wants to be left alone to watch sci-fi soap operas, but stupid
humans keep doing stupid things that stop it from doing so, or worse, are
trying to interact with it rather than let it stand in a corner by itself
(to watch soap operas again, probably).
This is a series of four novellas written with Murderbot narrating, and
it’s delightful. They are short, so each has a fairly straightforward
plot, but it’s great fun nonetheless.
Ra, Sam Hughes
On the one hand, Ra is excellent: it’s a hard sci-fi novel (novella?)
with some really well thought-through worldbuilding. To some extent, it
puts me in mind of Snow Crash. (It also has some
really nice in-jokes, which I don’t think I can reference without being
spoilery.)
It was published in chapters on Sam Hughes’ blog (at
qntm.org/ra, where you can read it for free), and
there are also a few EPUB versions, some of which you can choose to pay
for.
So as a self-published story, it’s really rather good. Unfortunately, on
the other hand, I think it could also do with some quite significant
editing, as there seem to be two almost completely different stories here,
and while they’re linked, the story switches at one point from something
grounded (like Snow Crash) to something incomprehensible by
Greg Egan, and while both are good, I don’t think they fit well together.
To sum up: I managed to read 40 books last year, almost all of which were
fiction, mostly urban fantasy and sci-fi, to nobody’s surprise. (I also
started and failed to finish a bunch of non-fiction books).
I think I did a better job of picking books with diverse protagonists this
time round, and while most of the books I read were published in the last
few years (40% were published in 2018), I managed to also seek out a few
older ones (Kindred, for example, I’m really glad I got round
to reading).
Onward to 2019!
I’d have called it sci-fi purely because it has time-travel, but I ran across an interview with Butler in which she points out, “Kindred is fantasy. I mean literally, it is fantasy. There’s no science in Kindred.” She has a point. ↩
… though from what I can tell, 6 Ma is squarely in the Miocene epoch, not the Pliocene. In A Pliocene Companion, Word of God resolves this by stating that, in-universe, the Pliocene is considered to start around 11 Ma (not 5.6 or 5.33 Ma, as in our reality). ↩
And to a large extent, discrimination that’s still present today: there’s a line where our heroine says that “people would ignore what I said until [my husband] repeated it”, which sounds familiar enough. ↩
I recently ran across the fact that it’s possible to make the Java runtime
deadlock while initialising a class — and that this behaviour is even
mandated by the Java Language Specification.
Here’s a Java 7 program that demonstrates the problem:
In addition to demonstrating that lambdas are a good idea (all that
boilerplate to start a thread!), this also shows how cycles during class
initialisation can lead to a deadlock. Here’s what happens when you run
it1:
$ javac Program.java
$ java Program
That is, it hangs.
In Java, classes are loaded at some arbitrary point before use, but are only
initialised — running the static {} blocks and static field
initialisers — at defined points2.
One of these points is just before a static method is invoked, and so the
two calls to A.initMe() and B.initMe() above will both trigger
initialisation for the respective classes.
In this case, each class contains a static field that instantiates an
instance of the other class. Instantiating the other class requires that
that class is initialised, and so what we end up with is that each class’s
initialisation is blocked waiting for the initialisation of the other class
to complete.
If you trigger a thread dump at this point — by sending a SIGQUIT or
hitting Ctrl-\ (or Ctrl-Break on Windows) — then you’ll see something
like this:
Full thread dump OpenJDK 64-Bit Server VM (24.79-b02 mixed mode):
"Thread-0" prio=10 tid=0x00007efd50105000 nid=0x51db in Object.wait() [0x00007efd3f168000]
java.lang.Thread.State: RUNNABLE
at Program$A.<clinit>(Program.java:13)
at Program$1.run(Program.java:5)
at java.lang.Thread.run(Thread.java:745)
"main" prio=10 tid=0x00007efd5000a000 nid=0x51ca in Object.wait() [0x00007efd59d45000]
java.lang.Thread.State: RUNNABLE
at Program$B.<clinit>(Program.java:18)
at Program.main(Program.java:9)
[...]
Interestingly, you can see that while both threads are executing an implicit
Object.wait(), they’re listed as RUNNABLE rather than WAITING, and
there’s no output from the deadlock detector. I suspect that the reason for
both of these is that the details of class initialisation
changed in Java 7:
In Java 6, the runtime would attempt to lock the monitor owned by each
Class instance for the duration of the initialisation, while in Java 7,
attempting to initialise a class that’s already being initialised by another
thread just requires that that the caller be blocked in some undefined
fashion until that initialisation completes.
There are other ways to trigger the same problem, too. Here’s another
problematic snippet:
Here we have Foo, and EmptyFoo, a special — presumably empty, in some
fashion — version of Foo. EmptyFoo is usable directly, but it’s also
available as Foo.EMPTY.
The problem here is that initialising EmptyFoo requires us to initialise
the superclass, and initialising Foo requires initialisation of EmptyFoo
for the static field. This would be fine in one thread, but if two threads
attempt to initialise the two classes separately, deadlock results.
Cyclic dependencies between classes have always been problematic in both
Java and C#, as references to non-constant static fields in classes that are
already being initialised see uninitialised (Java) or default (C#) values.
However, normally the initialisation does complete; here, it doesn’t, and
here the dependencies are simply between the classes, not between their data
members.
Unfortunately, I don’t know of any convenient way to detect these cycles in
Java: OpenJDK provides -XX:+TraceClassInitialization, which I suspect
might be useful, but it’s only available in debug builds of the OpenJDK
JRE3, and I haven’t been able to confirm exactly what it
shows.
And for what it’s worth, I’m not aware of a better solution for detecting
cycles in C# either. For Noda Time, we used a custom cycle detector for a
while; it spotted some bugs resulting from reading default values, but it
was too brittle and invasive (it required modifying each class), and so we
removed it before 1.0.
I suppose that if we assume that class initialisation occurs atomically and
on multiple threads, then this kind of problem is bound to come
up4. Perhaps what’s surprising is that these
languages do allow the use of partially-initialised classes in the
single-threaded case?
If videos are your thing, the folks at Webucator have turned this post into
a video as part of their free (registration required) Java Solutions from the Web course. They also offer a
series of paid Java Fundamentals classes covering a variety of topics.
Or at least, what happens when I run it, on a multiprocessor Debian machine running OpenJDK 7u79. I don’t think the versions are particularly important — this behaviour seems to be present in all Java versions — though I am a little surprised that I didn’t need to add any additional synchronisation or delays. ↩
You can trace class loading with -XX:TraceClassLoadingPreorder and -XX:TraceClassLoading, but this doesn’t tell you when class initialisation happens. ↩
He says, with a sample size of one. I haven’t managed to confirm what C# does, for example, and C++ avoids this problem by replacing it with a much larger one, the “static initialisation order fiasco”. ↩