Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Saturday, May 03, 2008

[Programming] Crucible code-review system

At work, we use a great code-review system called Crucible (by the makers of the Jira bug tracker and Confluence wiki).

To use it, you simply click a line of code. A text box appears, allowing you to enter a comment. The author is notified with an email.

Screenshot

Crucible is great because it makes code reviews easy: just click on a line, and enter your comment.

Another good thing is that it makes code reviews non-threatening (and efficient). I'm not saying that face-to-face code reviews should never be done. But using an asynchronous code-review system is convenient: you review the code at a convenient time, at your own pace. For some reason, the tone of any criticism of the code remains constructive and respectful.

Saturday, April 26, 2008

[Programming] Understanding the "this" keyword in JavaScript

My colleague asked me how to know what the "this" keyword refers to in JavaScript. It's a bit different from other languages.

First, the rule: When you invoke a function on an object, "this" refers to the object. When you invoke a function by itself, "this" refers to the global object (the window object).

Now for some examples.

Creating an object in JavaScript is easy:
    var food = {};

Let's add a function to this object:
    var food = {
getCalories: function() { alert(this); return 300; }
};

food.getCalories();

When we call food.getCalories(), "this" is the food object, because we are invoking the function on the food object.

But check this out:
    var getCals = food.getCalories;
getCals();

Here we invoke the function by itself, i.e., not on an object. "this" is the global object (i.e. window), because we are invoking the function by itself.

Now look at this:
    var automobile = {};
automobile.getCalories = getCals;
automobile.getCalories();

Here we've created an automobile object, and added our function to it. "this" is the automobile object, because we are invoking the function on the automobile object.

Thus, "this" is a dynamic quantity – it is not cast in stone when the function is defined, but refers to the current object that the function is being invoked on.

Thursday, April 24, 2008

Trillions to 1

Just the other day I was thinking, if, 31 years ago, the two gametes from which I was formed - those two first cells of me - differed in location by a millimeter, I would not be here today. Someone else would be in my place, someone looking very similar, but it would not be me. I would have never awakened to life, but would have remained non-existent. Someone else - a pseudo-Jonathan-Aquino - would have grown up with my family, attended my school, fallen in love with computers, contributed to society - in my place. All without me knowing it; I would never have been born into reality. I would have remained dormant.

The chances of those two first cells meeting were astronomically low - 1 in trillions. And going further back in time, through the generations, the chances of events happening in just the right place and at just the right time to result in this one meeting of cells: very unlikely. If anything had been slightly different - a rainy day instead of a sunny one, for instance - another Jonathan Aquino, not I, would be living this life.

Yet here I am. Trillions to 1 that I should not have been granted a shot at this life. I'm very lucky.

Tuesday, April 15, 2008

Videos of Great Speeches: I Have A Dream; JFK's Inaugural Address

Footage of a couple of amazing speeches:

Thursday, April 10, 2008

[Programming] The Proper naming pattern: Extract the guts of foo() into fooProper()

Often in programming you will have two versions of a function: one that serves as an outer shell, and the "real" function itself. Suppose you have extracted the guts of addAttachment() into addAttachment2().

A difficulty confronts you: What do you call the new function? addAttachment2() is a lousy name.

A wonderful adjective can help us here: proper. We would call the new function addAttachmentProper():

FliE1

The function proper is *the* function, the one that does the work. I live in Victoria, but not in Victoria proper (the central part of the city). "proper" is a convenient term to denote The Actual Function.

More examples:
  • iconUrl() and iconUrlProper()

  • broadcast() and broadcastProper()

  • url() and urlProper()

  • delete() and deleteProper()

Sunday, April 06, 2008

DIY Hand-Bordered Correspondence Cards

Crane's sells some very nice hand-bordered correspondence cards, but at $20 + shipping + tax for a box of 10, they're not cheap.

But you can do almost as well by taking a 4x6 index card and applying a border with a felt marker. Just lay a sheet of paper beside the edge of the card (to make a clean border edge), find a marker with the desired color, and fill in the border.

Picture 825

Sunday, March 30, 2008

Another song: Dolor Sit Amet

Here's another song I made using Audacity and a couple of instruments. It's a passionate love song / waltz, called Dolor Sit Amet.

Saturday, March 29, 2008

Song I made using Audacity

Here's a song I made using Audacity and a bunch of instruments: Experiment 1.

Friday, March 14, 2008

Useful widgets for Google Desktop sidebar

I turned the Google Desktop sidebar back on, because there are a few widgets that I thought would make my life easier. They definitely help.

At the top, there's the time and date, day, and a mini calendar.

Below that is a large yellow notepad - this is the most useful widget. I often need a place to jot down information, and to refer to it. This notepad widget is always visible, and doesn't cover up any other windows.

Just below that is a little purple calculator widget called easyCalc. You can type in arithmetic expressions. It's not the greatest - the numbers are tiny, and it behaves a bit wonky sometimes - but it does the job.

Fli5

Wednesday, March 12, 2008

Nice bookmarks you can print out

If you ever need to print out some bookmarks, these three by Jan Brett are quite nice.

Saturday, March 08, 2008

jEdit macro: Toggling between proportional and monospaced fonts

Here's a jEdit macro to toggle between a nice proportional font and a not-bad monospaced font:
if (jEdit.getProperty("view.font") == "Franklin Gothic Medium") {
jEdit.setIntegerProperty("view.fontsize", 19);
jEdit.setProperty("view.font", "DejaVu Sans Mono");
jEdit.propertiesChanged();
} else {
jEdit.setIntegerProperty("view.fontsize", 22);
jEdit.setProperty("view.font", "Franklin Gothic Medium");
jEdit.propertiesChanged();
}

I like jEdit's choice of macro language (Java). And you can assign a keyboard shortcut to any macro (I'm using F9).

Fli139

Fli13A

Thursday, March 06, 2008

5beeps.wav - Useful replacement sound for calendar apps

Don't you hate how Outlook's Reminder window is buried under your other windows, causing you to miss appointments?

Solution: Change the Reminder sound to this more noticeable set of 5 beeps: 5beeps.wav. Change it in Tools > Options > Advanced Options > Reminder Options > Reminder Sound.

It's an unobtrusive yet noticeable alert sound. Useful for other applications as well.

(Based on the public-domain beepdoub.wav sound.)

Tuesday, February 12, 2008

QuickSlide: Create slides from your browser's address bar

Here's another little site I've been working on: QuickSlide. It lets you create good-looking slides using your browser's address bar.

For example,
http://quickslide.ning.com?q=QuickSlide<div class="subtitle">Simplicity. Power.</div>
Fli3CE8

You get a nice dark backdrop, and centered text at a good size.

You can also add a picture – one of the built-in leaf images, or an image of your own:
http://quickslide.ning.com?q=<img width="450" src="leaf1.png">Improvements
Fli3C66

http://quickslide.ning.com?q=<img width="300" src="leaf2.png"><br />Music
Fli3BF8

To add a reflection to an image, use class="reflect":
http://quickslide.ning.com?q=<img width="300" src="leaf4.png" class="reflect">Reflection
Fli3B09

If you use YubNub, you can generate slides using the qsl command. Here's a slide that shows a random number:
qsl { random 100 }
Fli3B98

QuickSlide source code

[Programming] Unused Variable Detector

Presenting the Unused Variable Detector. Paste code into the box, press the button, and you will be given a list of variables that aren't used. Works for many different programming languages. Source code.

FliCFAC

Saturday, February 09, 2008

Trying out the Maxthon browser

Trying the Maxthon browser again. I've loaded down Firefox with web-development extensions, so it's nice to have a zippy browser for regular use.

One cool feature of Maxthon is Split View. I often want to see two websites side by side.

Fli35A

Sunday, February 03, 2008

Firefox Bookmarklet for Making Webpages Easier to Read

On many websites, the text is tiring to read because it is too small and too closely spaced:

Fli175

If you use Firefox, try dragging the following booklet to your Bookmarks Toolbar: Legiblize.

Now, whenever you encounter a page that it is hard to read, click the bookmarklet. It will increase the font size, increase the spacing, and change the font to Palatino.

Fli174

This is much easier to read on my monitor. Adjust the font and font size to taste.

Thursday, January 31, 2008

Four Learning Styles

The book Teach What You Know has an interesting list of four learning styles:
  • Purpose-Driven learners need to know why something is important before they begin to learn about it. While you are teaching away, they are trying to figure out why the topic is important. Once they have an answer, they will give you their attention.
  • Just The Facts learners don't care so much about the big picture – what's important to them is the steps to do the job. They want you to skip the fluff and just tell them the main points.
  • Contextual learners seemingly ask you about everything except the topic at hand. "OK, let's get back on topic," you say gently. But that's how contextual learners learn: by seeing the connections to things on the periphery.
  • Out-of-the-Box learners are ornery devil's advocates. "What if we took a totally different approach and try this?" they ask, to your chagrin. "What would happen if that part failed?" Out-of-the-Box learners learn by pushing the limits of knowledge, by asking about hypothetical situations.
In the book, these styles are called: Why learners, What learners, How Does It Work learners, and What If learners.

Update: The book's author, Steve Trautman, sent me this helpful clarification:
Hi Jon

Thanks for posting about my book. I wanted to offer a slight correction. I’d say you’ve mixed your “contextual learner” with your “out of the box learner.” The hallmark of a contextual learner is needing to see the relationships between the components in a situation. For example, they like to see an org chart and job descriptions so they know how the people fit together. They like to see a site map to know how the grounds are laid out and they like to have information about external factors like competition or seasonal issues. They’re the ones who need to see the “big picture” in order to learn.

Otherwise your paraphrase is good.

The other note you might want to share is that since not everyone learns the same way, we need to be a little tolerant of the differences when we’re the teacher/mentor – adjusting for the learning style of our apprentices rather than making them adjust to us.

Hope this helps.

All the best

Steve Trautman

www.peermentoring.com

Wednesday, January 30, 2008

Subversion Time-Lapse View 1.6 Released

SVN Time-Lapse View 1.6 has been released. It has the following improvements:
  • Remember Password checkbox
  • Repository Browser dialog, added by Kim Tiedemann. The Browse button will open the file dialog or Repository Browser dialog as appropriate, depending on whether you specify a filename or URL.

Tuesday, January 22, 2008

Using text-to-speech to listen to online books

An even better way to learn from online books – if you are an audio learner like me – is to have them read to you. I just bought the high-quality AT&T Natural Voices for $35 (including a Windows program that lets you paste in text to read). And I've heard that Mac OSX Leopard has a pretty good built-in voice called Alex.

Here's an MP3 excerpt from Teach What You Know: A Practical Leader's Guide to Knowledge Transfer Using Peer Mentoring. The text is from the O'Reilly online book (shown in my previous post); it's being read aloud by AT&T Natural Voices.

The voice is easy to understand, and the information sinks into my brain easily. I like this way of learning.

Saturday, January 19, 2008

Firefox O'Reilly Online-Book Legiblizer

I find O'Reilly's online books to be hard to read. The font is too small, and the lines are too close together.

Here's a bookmarklet that increases the font size, increases the line spacing, and changes the font: O'Reilly Legiblize. Drag it to your Firefox toolbar, then click it while reading an O'Reilly online book.

Before legiblizing:

Fli223

After legiblizing:

Fli224

Much better.

(Font, font size, and line spacing can be adjusted to taste.)

Monday, January 14, 2008

Quote from Zinsser's "On Writing Well", Chapter 4: The Audience

"Another question will occur to you: 'Who am I writing for?' It's a fundamental question, and it has a fundamental answer: You are writing for yourself."

–William Zinsser

Wednesday, January 09, 2008

Programming: Method names: Statistics for the JDK

Here are some statistics on method names in Java 1.5 (method signatures, method names). By analyzing code of reasonably high quality like the JDK, we can derive rules of thumb for good, standardized function names. Useful for any language.

Number of methods in JDK 1.5:
    80818


Most common method names:
   1304 toString            
1219 run
663 equals
496 hashCode
440 actionPerformed
439 getName
383 contains
352 accept
320 remove
285 reset
280 get
278 getCharacterEncoding
277 paint
261 read
258 add
256 write
224 main
216 close
213 clone
204 getValue
199 getType
193 next
191 createUI
189 size
175 clear
168 getPreferredSize
167 print
159 init
152 newEncoder
152 newDecoder
150 propertyChange
145 update
140 historicalName
134 getMinimumSize
130 debug
120 translate
119 setValue
116 set
116 put
110 getEncoderIndex2
110 append
107 isEmpty
107 getInstance
104 initialize
103 getMaximumSize
102 getBorderInsets
102 error
102 dispose
101 writeObject


Most common 1-word prefixes:
  19984 get       
5449 set
3555 is
1604 to
1534 create
1441 visit
1180 add
776 remove
707 write
642 update
532 mouse
501 hash
500 check
477 new
471 has
468 print
449 action
412 read
374 install
357 parse
330 paint
302 uninstall
294 handle
260 put
258 init
252 process
223 next
223 find
220 end
217 load
217 build
202 can
198 make
195 do
171 window
166 type
161 start
159 compare
157 fire
152 property
141 impl
140 historical
140 clear
138 contains
137 jj_3
121 code
116 draw
109 show
109 focus


Most common 2-word prefixes:
  626 getAccessible
308 getCharacter
229 getPreferred
223 getDefault
190 getMinimum
183 getIcon
175 getClass
163 getSystem
160 getMaximum
130 getMax
129 getEncoder
128 getBorder
127 getFile
117 getLast
115 getDecoder
109 getNode
109 getInput
105 getNext
105 getCurrent
89 getType
89 getLocal
88 getColumn
88 getAttribute
87 getFont
82 getComponent
80 isValid
80 hasMore
78 getRow
75 visitType
75 getJvm
74 getElement
73 getData
72 getParent
65 getNum
62 getUser
62 getProperty
61 getMenu
60 getText
59 getStandard
57 visitConstant
57 getNative
57 getContext
57 getActual
57 addLayout
56 setDefault
56 getSelected
55 getError
54 getDocument
54 getContent


Most common 1-word method names:
 1219 run       
663 equals
383 contains
352 accept
320 remove
285 reset
280 get
277 paint
261 read
258 add
256 write
224 main
216 close
213 clone
193 next
189 size
175 clear
167 print
159 init
145 update
130 debug
120 translate
116 set
116 put
110 append
104 initialize
102 error
102 dispose
96 start
96 match
95 parse
94 eval
91 trace
83 create
83 compare
81 encode
72 finalize
71 flush
68 stop
68 insert
60 copy
57 check
55 render
54 matches
52 delete
50 process
50 name
47 skip
46 show


If you want to conduct your own analysis, view the JDK 1.5 method signatures and method names.

Thursday, January 03, 2008

Programming Book: The Little Schemer

I'm having fun going through a computer-programming book called The Little Schemer. It consists of dozens of exercises that you solve using little snippets of recursive code. It definitely has the feel of a game - Sudoku moreso than Call of Duty.

The key to enjoying this book is to not get hung up on the non-code questions. The book is written as a list of questions and answers, and it's frustrating to try to answer the non-code questions because they are often unguessable:

Q: Is that bad?
A: You must beware of shadows

Quickly read through the non-code questions and answers. But try to answer the code questions - that's the stuff that's fun and interesting.

Q: Write fun? with set? and firsts
A: (define fun? (lambda (rel) (set? (firsts rel))))

You'll find pencil and paper to be too slow for this stuff; a text editor is more convenient. But you need not bother running the code through a compiler - the answers are given on the same page.

Sunday, December 30, 2007

RSS feed of Thomas Aquinas's Summa Theologica

Here is a daily RSS feed for the Summa Theologica. It gives you one article a day, and takes 8½ years to finish.

Better than spending $165 on the 5-volume set.

Tuesday, December 25, 2007

GridNote - A grid of sticky notes

GridNote is a webpage of sticky notes that you can use to jot down things you need to remember (like a timesheet log, or restaurant prices, or calorie counts).

GridNote uses a cookie to remember your notes - no database is involved, so your privacy is protected. Source code.

These sticky notes are perfectly laid out for you. If you've got a third monitor or some extra screen real estate, try putting GridNote there.

Fli334C

Monday, December 24, 2007

Current Ergonomic Setup

Picture 347

Here's the ergonomic setup that's currently working for me.

1. Keyboard: Kinesis Advantage ($300). These used to give me pain in my palms, until I started using SmartGloves (item 3). I like how this keyboard puts Ctrl and Alt on the thumbs instead of the pinky (which, if overworked, can lead to Emacs Pinky). I've also found the Microsoft Natural 4000 keyboard ($80) to be good; unfortunately it locates Ctrl and Alt at the pinky.

2. Trackball: Kensington Expert Mouse ($150). Using a mouse gives me various aches. This trackball doesn't, for some reason.

3. SmartGloves ($100). Keeps your wrists from bending backwards (pronation), by means of a hard foam strip down the back of your hand, and a beanbag under your palm.

4. Forearm support: rolled up towel ($0). Inexpensive way to prevent forearm pain, especially with the 1.5"-tall Kinesis keyboard.

5. Table, 26" high. This is a good height for me, as it keeps my elbows at right angles.

6. (Not shown) Good office chair with back support ($150).

Sunday, December 23, 2007

Programming Books and a $200 Amazon Gift Certificate

I received a $200 Amazon gift certificate and here's what I got:
  • Implementation Patterns ($34) by Kent Beck. Tips for maintainable code. Should be a fun read.
  • Patterns of Enterprise Application Architecture ($43) by Martin Fowler. Web presentation, concurrency, O/R, distributed objects.
  • Pro JavaScript Techniques ($30) by John Resig (jQuery creator). I'd watched a video of one of John's talks, and liked what I heard. I've read another JavaScript book (JavaScript: The Definitive Guide), and look forward to learning JavaScript best practices from this book.
  • Why Programs Fail: A Guide to Systematic Debugging ($58) by Andreas Zeller. The priciest book of the bunch. Looks like it's written in an engaging way. Hope to expand on the debugging techniques I learned from Debugging: The Nine Essential Rules.
  • jQuery Reference Guide ($31). jQuery is the new kid on the JavaScript-framework block, so I'd like to learn more about it.
Books which, alas, didn't make the cut:
  • Domain-Driven Design $44. Many reviews complained of its verbosity.
  • xUnit Test Patterns $45. Too long (900 pages).
  • Structure and Interpretation of Computer Programs $70. I should read this sometime.
  • Code Complete 2 $30. Read the original Code Complete some years ago. Wonder if the new edition merits a second reading.
  • Programming Pearls $30. A favorite of James Gosling and Tim Bray.

Friday, December 21, 2007

Programming Resources: Smalltalk Tutorial, PragProg Appendix, Searching Blogger Profiles

Programming-related resources I'm checking out:
  • Squeak by Example (PDF). Book-length Smalltalk tutorial. Smalltalk is a fun, quirky, OO language/environment.
  • Pragmatic Programmer (book) Appendix A: Resources. Lists interesting programming resources: Tcl, Mozilla source code, comp.object FAQ, Z Shell, JavaSpaces, Emacs . . .
  • Joel on Software (book) It's about time to read this again.
  • Search Blogger profiles to find people interested in X and Y: http://www.google.com/search?q=inurl:blogger.com/profile+catholic+software&hl=en&filter=0 . Useful for finding people for your highly specific social-networking group (like the Association of Catholic Computer Programmers). Even better, set up a Google Alert so you are notified about matching profiles.
  • Homepage Usability (book). Jakob Nielsen's critique of 50 homepages.
  • Refactoring to Patterns (book). Good synthesis of the ideas from two important books: Refactoring and Design Patterns. Can be a bit hard to read sometimes – I'm glad that examples are provided.
  • Windows Presentation Foundation Unleashed (book). I'm not currently coding in .NET, but Devin mentioned to me that WPF is "Microsoft's new way of doing UI and tying it to logic and is very powerful". Hoping to glean some ideas.

Sunday, December 16, 2007

Association of Catholic Computer Programmers

I would like to announce the founding of the Association of Catholic Computer Programmers, which unites two great interests of mine (and of many others, I hope).

If you are a Roman Catholic who counts The Pragmatic Programmer, Design Patterns, and Refactoring among your favourite books, come join the ACCP at http://accp.ning.com/

Thursday, December 13, 2007

PHP Regular Expressions: Recursion, Named Capture

Here's a PHP regular expression for matching *nested* parentheses (e.g. blocks of code):

    ((?:[^()]++|\((?1)\))*)

The ?1 is a recursive reference to the regex marked by the outermost parentheses. It is a feature of the PHP regex engine.

See Jeffrey Friedl's Mastering Regular Expressions, 3rd ed., p. 476, "Recursive reference to a set of capturing parentheses".

Another potentially useful regex technique is "named capture":

    ^(?P<protocol>https?)://(?P<host>[^/:]+)(?::(?P<port>\d+))?

Here you can use either $matches[0], $matches[1], $matches[2] or $matches['protocol'], $matches['host'], $matches['port'].