Tag Archives: book

JavaScript: The Good Parts

Just finished reading this book for the second time. It’s usually the first book developers read when coming to JavaScript, and I admit I didn’t really understand all of it back then. Reading it again with more experience was useful, as it allowed better understanding, questioning of “why” on the points that are made, and realisations of where some of the things mentioned could be useful.

JavaScript: The Good Parts

Highly recommended for beginners and those with a bit more experience alike. Below are some of my brief notes on things that are simple to note down from the book.

  • When invoked with “new”, if a function does not return an object, then “this” is returned.
  • Closure can be used to hide things like nextId generation. var nextId = (function () { var nextId = 0; return function () { return nextId++; }; }());
  • Use closure to have event handlers use value of variables at the time when the handler was bound.
  • Curry = combine a function with values for some parameters, to create a function that requires less parameters. add1 = curry(add, 1).
  • Function memoizer pattern/utility – p.44
  • Object.create – differential inheritance possible from another object
  • Regex group prefixes: ?: noncapturing, ?= positive lookahead, ?! negative lookahead
  • array.sort is not stable: if there are equal elements, they won’t always sort the same. Use a special comparator with a tie breaker function – p.81
  • Regexp.test for true/false, .exec to return null / array of [match, groups…]
  • string.match is like Regexp.exec when no /g flag.
  • string.replace – can take a regex, and the replacer can be a function
  • $& is the matched text, $` is text preceding match, $’ is text following the match
  • string.search is like indexOf, but takes a regex
  • string.split can take a regex
  • string.charCodeAt(index), String.fromCharCode(code)
  • Remember typeof null is “object” – remember when checking
  • parseInt – remember to always pass radix to be safe, usually 10
  • Money calculations – multiply by 100 into pence, calculate, divide back to £
  • Care with special cases of NaN, isNan, isFinite – p.105
  • Is it an array? Object.prototype.toString.call(thing) === ‘[object Array]’. Or Array.isArray in ECMAScript 5
  • Empty string is falsy
  • Care when using objects as maps which may have arbitrary keys – e.g. to do a per-word count. Problems if e.g. the string to count has the word “constructor”.

Version Control with Subversion

I recently read the book Version Control with Subversion free online book. I’d recommend it to anyone who uses SVN as part of their work, including GUI client users.

If you’re a developer, you can probably skip the sections on repository administration (I did). It’s good to skim them though, so you’re aware of server side capabilities that you might want to ask for such as hook scripts and write-through mirroring.

Some points I picked up/thought people would generally benefit from knowing:

1. Fundamental Concepts

  • 1.7 has a new working copy format with only one .svn folder, in the root of the working copy.
  • 1.7 prevents use of mixed revision working copy as target of merge, to prevent common problems.

2. Basic Usage

  • Repository layout considerations – have trunk/branches above all projects, or underneath each one
  • svn status -u option shows * if someone modified the item in the repository. If also locally modified, will have to update before committing.
  • dc option for interactive conflict resolution diffs only the conflicted part.
  • svn resolved is deprecated in favour of svn resolve –accept working.
  • svn commit -F option reads message from file.
  • svn maintains private to-do list to help recover from e.g. killed processes. This is what svn cleanup uses.
  • Resolve tree conflict – diff the old file, edit the headers to point to new path, apply patch. Then delete old file with force, and resolve –accept working the new one.

3. Advanced Topics

  • svn log -r base:head – see what’s happened since last updated.
  • Pegged revisions avoid ambiguity when dealing with deleted or renamed moved files. @rev at end of path. Defaults to base.
  • svn:eol-style property can be useful when dealing with multiple platforms.
  • Use svn add –force instead of svn add *, as the latter is expanded by the shell and might include ignored files.
  • Keyword substitution in files using $var$, need to set svn:keywords property on the file.
  • Sparse checkout – can check out immediates, exclude unwanted folders, then telescope what’s left. Can also de-telescope.
  • svn:needs-lock property will make file read-only on file system.
  • svn:externals – auto checks out what’s referred to.
    • consider specifying revisions, so when you backdate your copy you get the old version of the external as well.
  • Changelists – file can only be on one at once, folders not supported. Lists are removed when committed, but option to keep them.

4. Branching and Merging

  • A branch is “dead” after reintegration
    • To keep it alive, need to do a record-only merge of the reintegration revision from trunk to the branch, to prevent it being subsequently merged to the branch.
  • Undo changes by reverse merge. To revert 303, do -r 303:302 or -c -303. Doesn’t record mergeinfo.
  • Use svn copy to ressurect files with history (A+ status).
  • When merging after cherrypicking, will do separate ranges to skip the cherrypicked one(s). Any in-between conflicts must be resolved interactively.
  • svn merge is simply “diff and apply”. No magic.
  • General use of record-only merge is to block changes from being merged somewhere, by lying that they’ve already been merged there.
  • Move is just a copy and delete. Dangerous when merging moves and renames – comes up as a deletion and an add, you won’t notice that your changes to the renamed file have been lost.

5. Repository Administration

  • Various useful hooks, not just pre-commit.
  • Use svn relocate if server name changes. Admin can set up a redirect, and 1.7 clients will auto-relocate.
  • Can use hooks to prevent commits to tags.
  • When branching for a release, manually port bug fixes in both directions.
  • Use vendor branches when we make customisations to third party code.

7. Customizing Your Subversion Experience

  • Global config to preserve extensions on conflict files, so they open in the default editor.
  • File timestamps are normally those of last touch, can config to make checkout use last commit time.
  • Various methods of setting which editor to use e.g. for conflict resolution (one is SVN_EDITOR environment variable).
  • svnversion command summarise local revisions of working copy – easy way of determining if it’s mixed revision or not.

9. Subversion Complete Reference

  • -x options for diff and blame, for ignoring whitespace
  • svn info can be applied to folders, files and urls
  • svn mergeinfo command, with show-revs merged or eligible options
  • Status R (replaced) means item was scheduled for deletion and then one with the same name was scheduled for addition.

What should every programmer know about web development

An excellent question and top answers over at Stack Exchange Programmers – What should every programmer know about web development?

Most of us will know the majority of points given in the answers, but a few were new to me and/or interesting so I wanted to note them for reference: