https://gravatar.com/userimage/16926726/2de44cb9918f08ff7f430244b10bf37b.jpeg?size=256

gowinder's Blog

The Joy of Code Generation — Marking My First Integrated Code Generator, DBCodeGen

It suddenly struck me that an engine which supports rapid development needs, besides a good foundation and convenient templates, a complete set of development tools. That toolset should include automated code generation — the way Visual Studio generates an MFC application for you. It saves us a ton of unnecessary work.

Nobody who has used a code generator needs convincing. Back when I was building each system, there was always some repetitive work, and that work was awkward to handle with templates or interface base classes — every time it was copy, paste, then modify, which was a real pain. Then one day a colleague said to me, you can write a program to generate that code. And that’s how, after eating rice for 30 years, I finally learned you can make congee.

Book Review: Marooned in Realtime

https://img2.doubanio.com/view/subject/l/public/s29930241.jpg

http://book.douban.com/review/3801851/

“Marooned in Realtime” is obviously the sequel to “The Peace War”. The style is different — Realtime reads a lot like a detective novel — but I don’t think the way it’s told is all that different. Vinge’s novels always spend a huge amount of the early going laying out the setting, the characters, the clues and so on, so with a Vinge novel you have to get at least halfway through before it becomes impossible to put down. “Realtime” and “The Peace War” are both like that, and so was “A Fire Upon the Deep”, which I read before: the beginning was so dull, I spent days on the first half, reading a bit and stopping, and then I finished the second half in one sitting. The real climax is at the back. It makes you not want to put it down.

Understanding a Few Creational Patterns

Abstract Factory is about creating a whole family of products in a unified way. That is, it’s like a template: one concrete factory creates a series of products, and that series probably shares a single style, so different product series get assigned to different factories. The downside is that the product lineup for the series is already known in advance; if you want to add a new product to the series, you have to extend the factory and modify the low-level code. This pattern can be used to control variation — in other words, if I want to make a special modification to one product within an otherwise uniform series, I have to generate a whole new factory.
Builder, I personally feel, is very similar to Abstract Factory. The reason it’s called Builder is that the interface it provides doesn’t produce the basic parts (that’s what Abstract Factory does) — after producing the parts it also takes responsibility for assembling and combining them (Abstract Factory doesn’t do the combining). That way the caller doesn’t have to care which parts make up the final product; it just needs to find a Builder that can produce the final product. And by deriving from Builder, you can get parts of different specifications combined in different ways. Put plainly, Builder has one extra assembly step compared with Abstract Factory. If the assembly process and the details of the parts can’t be determined in the low-level code, use Builder; conversely, if the assembly process and the part specifications must be constrained down at the low level, use Abstract Factory.
Factory Method is a bit similar to Abstract Factory, but Abstract Factory supplies a whole set of parts while Factory Method supplies a single part. Once a product’s assembly method and part specifications are fixed, you can use Factory Method and let derived classes create the parts they need according to those specifications.

Dazed and Confused: I Did the Same Work Twice

Today I was completely out of it — I actually did yesterday’s work all over again.
It’s a general-management feature. Yesterday I wrote a CHeroCenter, basically finished. Today I wrote another one called CHeroTender. Apart from the class name, everything is identical: the functions, the member variables, even the function parameters. When I was writing the code to dismiss a general I needed to return an error code, and I was going to have the designers add it to string.xml — then it turned out string.xml already had it. Surprised, I searched the code, and there it was, that exact same class. Depressing.
Good thing the class isn’t big. A hundred-odd lines of code.

Starting the Hyperion Sequel, Endymion

The full set of original editions arrived right after New Year, and I never got a chance to read them. I’d meant to start from the first book, but I found the plot had lost its freshness, and reading it in English made it hard to keep going, so I decided to start straight from the sequel.

Two days in, I’ve read two pages and run into a pile of unfamiliar words. Still, it’s not too bad — without a dictionary I can more or less guess the plot, and with a dictionary I get it properly. But if you asked me to translate the whole thing into Chinese, I don’t think I’m up to it. Right now I’m stuck at the beginner stage of “getting the gist”.

(500) Days of Summer

https://m.media-amazon.com/images/M/MV5BMTk5MjM4OTU1OV5BMl5BanBnXkFtZTcwODkzNDIzMw@@._V1_FMjpg_UX1000_.jpg

Today I watched a movie with my wife called “(500) Days of Summer”. I’d never seen the male lead, but the female lead is the one from Yes Man, Zooey Deschanel — she has a lot of that America’s Sweetheart Meg Ryan feel from back in the day. In this film she’s the same, all quirky and sprite-like.
The plot isn’t cheap either: the ending isn’t a happy-ever-after, but it isn’t a tragedy either. It’s just like life — a relationship ends painfully, and that ending is itself a new beginning.