Skip to content

Instantly share code, notes, and snippets.

@cky
Last active January 17, 2018 08:17
Show Gist options
  • Save cky/c246c17b80ee8308343f04a95e01ce06 to your computer and use it in GitHub Desktop.
Save cky/c246c17b80ee8308343f04a95e01ce06 to your computer and use it in GitHub Desktop.
100 Days of Code challenge, round 1

#100DaysOfCode Log—Round 1—Chris Jester-Young

The log of my #100DaysOfCode challenge. Started on 1 January 2018.

Log

R1D1 (2018-01-01)

Created SwiftJson as a Swift port of ktjson and c++17-json. Coded up the basic JsonValue enum type.

R1D2 (2018-01-02)

Implemented a basic JSON value printer.

R1D3 (2018-01-03)

Converted the JSON value printer to use visitor pattern, which is how it should have been to begin with.

R1D4 (2018-01-04)

Support initialising JsonValue with literals. Yay for yummy syntactic sugar!

R1D5 (2018-01-06)

Support pretty printing of JsonValue. The implementation approach is a bit fugly so I'll try to refactor this later.

R1D6 (2018-01-07)

Add a very basic parser, that does not support parsing numbers and strings yet.

R1D7 (2018-01-08)

Add number and string parsing.

R1D8 (2018-01-09)

Track down why printing out large JSON trees is so slow. It turned out to be because, by default, objects passed to print or debugPrint are sent to a _TeeStream, which collects the output into a string that is then sent to _playgroundPrintHook.

You have to set _playgroundPrintHook to nil to disable this; it is initially set to a no-op closure, which means the string buffer is still built, only to be discarded.

What kind of slow are we talking about? For a 4MB JSON document, it takes about 1 second to print with _playgroundPrintHook disabled, and on the order of minutes with it enabled.

R1D9 (2018-01-11)

Reorganise the code into multiple modules, so that there's SwiftJson library and a PrettyPrintJson executable.

R1D10 (2018-01-12)

Add some simple tests for the SwiftJson module.

R1D11 (2018-01-13)

Move JsonPrettyPrinter to the PrettyPrintJson module, and make JsonVisitor use argument name overloading, which seems more idiomatic for Swift.

R1D12 (2018-01-15)

Print numbers in JsonPrettyPrinter as integers if they actually are.

R1D13 (2018-01-16)

Convert JsonPrettyPrinter to use JsonPrettyPrintVisitor, a new subclass of JsonPrinterVisitor. This is where the true power of visitors come in: open methods become extension points for the visitor, something that isn't as clean to achieve using switch alone.

R1D14 (2018-01-17)

Implement ASCII-only mode in JsonPrettyPrinter, where non-ASCII characters are escaped with \u.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment