Tuesday, 18 April 2006
Student Java gotchas
My two favourite annoyances are unnecessary setters and getters and the following use of boolean expressions:
while / if(x == true) { ... }
The latter just says that the student doesn't really understand how expressions are evaluated, which is pretty fundamental, although I've seen the same "mistake" in production code too.
The first thing about setters and getters is slightly more subtle. A field should be declared private if either it is or should never be used by another object or if it has some class or object invariant associated with it. A field with no associated invariants can be declared public. In fact, this is probably preferable, as declaring a field to be public tells anyone using your API that that particular field definately has no invariants associated with it that they need to think about.
Sunday, 9 April 2006
Pygame
Lesson 4: Python rules!
I can't believe how quickly many features came together using Python as opposed to, say, C++ or even Java. Things like typeless variables, dictionaries, and extremely easy-to-declare lists (allowing a mixing and matching of object types) made it very easy to implement content lists, attribute handling, spell effects, and so forth. I was already a fan of the language, but now the prospect of using Python, tied into a high-level 3D engine, has become extremely appealing to me.
Friday, 24 March 2006
Emacs-fu
Emacs just rules. Lately, I've been trying to figure out how abbrev mode can be used nicely with skeletons. The following is a skeleton to produce a Java "main" method and is due toJorgen Shaefer:
(add-hook 'java-mode-hook 'fc-java-setup)
(defun fc-java-setup ()
(c-set-style "k&r")
(setq c-basic-offset 4)
(c-set-offset 'case-label '+)
(define-abbrev java-mode-abbrev-table "main" "" 'java-main-skeleton)
(define-skeleton java-main-skeleton
"Insert a Java main function."
> "public static void main (String[] args) {\n"
_ "\n"
"}" >)
)
Tuesday, 28 February 2006
Tail Call Optimization as a Python Decorator
Monday, 30 January 2006
Colour transforms
I found this *really* useful comment in the Python source for the Python Image Library. Guess I should have remembered this from Uni, but never mind!
When translating a colour image to black and white (mode "L"), the library uses the ITU-R 601-2 luma transform:
L = R * 299/1000 + G * 587/1000 + B * 114/1000
technorati tags: python, image, PIL, colour, color, transform, luma, RGB
Wednesday, 25 January 2006
Pong for the Symbian60

I've spent an evening and a bit writng Pong in Python for my Nokia 7610. Seems weird to have a hobby after all the time we've spent working for the ARC launch, but Pong was fun and it was nice to see how incredibly simple the PySymbian stuff really is. Yay.
technorati tags: python, symbian, s60, phone, mobile, programming, software, games, pong
Monday, 23 January 2006
Camera modes for Symbian60 camera phones
"""
Prints all available information about available cameras:
* Number of cameras
* Maximum zoom
* Available image modes
* Available white balance modes
* Available image sizes
* Available flash modes
* Available exposure modes
"""
from camera import *
__author__ = 'Sarah Mount'
print 'This phone has', cameras_available(), 'camera(s).'
print 'Max zoom is', max_zoom(), '.'
for mode in image_modes():
print 'img_mode:', mode
for mode in white_balance_modes():
print 'wb_mode:', mode
for size in image_sizes():
print 'img_size:', size
for mode in flash_modes():
print 'flash_mode:', mode
for mode in exposure_modes():
print 'exp_mode:', mode