
It's Flash card Friday, on time. Without further ado, here are the lessons learned this week:
- Bounded wildcards should not be used for fields
I've mentioned PECS before, and this relates to it. Maybe you've be tempted by the sweet sugar that is bounded wildcard generics. You need to be careful though. So far, I've only found one good usage area for them, and that is method arguments. It would however, in my opinion, be a mistake to use them for:- Return values. They clutter the API in unnecessary ways, and it's not Java 5 compatible.
- Field or variable types. Try it. You'll run into trouble.
- Return values. They clutter the API in unnecessary ways, and it's not Java 5 compatible.
- Google App Engine datastore not suited for massive amounts of data
This week, I developed a small GAE application that scrapes a website for apartment listings. In no time I had found thousands of entries, each saved as an entity in the GAE datastore. Awesome.
Then I found myself in a bit of a pickle. The datastore API only permits fetching of at most 1000 entities per fetch call. Ok, I thought, so I guess I can just get the next 1000 after that. Nope, the offset also has a limit of 1000. But, I can actually iterate over the query object! Great? Well, unfortunately, the time one is allowed to spend in datastore API calls is quite limited, so the iteration times out in a few seconds.
I'd love to hear how people manage large amounts (>10k) of entities in the GAE datastore. - Good ideas often bring additional benefits
Something I've noticed when watching skilled coders refactor is that their changes often include additional benefits. Their explanations often sound something like this:
- Well, if we do it this way instead, then we don't need this list at all. And also, those classes can make use of this thing now, so we can remove that old thing.
or
- If we change this method signature we will get a cleaner API. That other class can then make use of this instead, further decreasing our dependence on that other sucky API.
Note the sentences in italics. These are the extra perks you get when you're doing a good job refactoring your code. In fact, if your refactoring doesn't bring any extra benefits, maybe you should rethink it.
Note: It's not a coincidence that my examples described refactoring making code leaner. That's the way it should be done :)
0 comments:
Post a Comment