James Crisp

Coding, calisthenics, book reviews, mind hacks and the occasional personal bit.

Month: December 2008

Wing Chun Notes

Stance

  • Lift up through body. Imagine your body is hanging from a thread from the middle of the top of your head
  • Shoulders should be relaxed and down
  • Knees springy (ie very slightly bent so you can bounce up and down)
  • Tie gung on – tensing core muscles and rotating pelvis up slightly (bottom of pelvis goes forward)
  • core muscles tensed, rest of body relaxed

Moving

  • Get into stance
  • Move with weight centred between legs, not on one foot or the other
  • When you move forward, your core/waist should move forward in time with the leg. Ie, leg should NOT lead and then pull body forward.
  • Waist should be driving the leg movement, which means your weight still stays balanced between your legs
  • Legs should be light and relaxed, body is being drawn up by the stance

Speed
When punching or kicking, you arms and legs should be completely relaxed, although tie gung should be on. If completely relaxed can move faster. Imagine swatting a fly.

When moving in, trust your wing chun. Moving in should be almost like getting pushed from your waist from behind. Legs relaxed, high acceleration, full weight moving forward, taking the space they currently occupy.

Pivoting
Pivot so that both feet finish moving at the same time. Move from the waist.

Guard
Guard should be with arms relaxed and fingers pointing forward towards your opponent’s centre line where the neck meets the trunk, to give even time for high and low attacks.

Defending against head punches
Think primarily of hitting the opponent with your punch/strike, as this will cripple the attack. The dai sau is secondary. Dia sau should keep sheering upwards on contact. It should be a rotation in the shoulder joint, your angles should not collapse. Your shoulder should always be down and the ball of the joint rotating at the back of the joint. Dia sau should be inscribing an even circle of your space. Contact should be shearing with the hard side bones of your arm against the inside of their wrist. Wrist should always stay on centre. Your fingers may be pointing towards the opponent’s head near the end of the move, or your hand may be above your head, depending on strength and hookedness of the attack.

Hook Kick
You really need to swing your hip into a good hook kick. Your leg should go up quite high as it swings around and then drive down into your opponent’s thigh / leg. In close, you may contact with your knee, with more distance, you should be contacting with the front of your lower leg (above ankle, but below knee).

Review: JavaScript – The Good Parts by Douglas Crockford

“JavaScript: The Good Parts” was kindly lent to me by my friend and colleague Dave Cameron. It was a highly informative read, and a good length at just under 150 pages. The aim of the book is to define an elegant, recommended subset of JavaScript that allows you to do everything you need, and work around problems in the language. The book is aimed at people who already have a good grasp of programming in other languages.

I learnt quite a bit from the book. Here are a few of the most important parts that come to mind:

  • JavaScript has function scope, not block scope so it is best to declare variables at the top of functions.
  • It is important to put { on the same line as the block opening keyword (eg, function, if etc) rather than on the next line. Otherwise, you may run into problems with some JavaScript implementations auto-adding ; in the wrong place.
  • Using the === and !== operators are safer and better than the == and != operators as they do no coerce types.
  • The ‘new’ operator is a bad way to make new objects in JavaScript and should be avoided. Functions starting with a capital letter should always be called with the new operator by convention. Failing to do this will add all the functionality of the object you are trying to create to the global object (thanks to the this references)!
  • You can always pass any number of arguments to a function. Extra arguments are not bound to function parameters, missing arguments will be undefined. Inside the function all arguments are accessible using the ‘arguments’ variable which is an array-like object.
  • Lots of things are false. Eg, 0, NaN, empty string, null, and undefined.
  • hasOwnProperty(name) is great in for(property in object) loops to find members of your object rather inherited members.
  • Object.beget(someOtherObject) allows prototypal inheritance from someOtherObject.
  • JavaScript arrays are really just objects with numerical property names and the length property, so if you use a for in loop, you’ll get indices in random order.
  • It is a good idea to ‘namespace’ your code in a single global variable for your application to avoid conflicts with other libraries. Eg, myApp = {}; myApp.myVariable = 5;
  • If you don’t used var, a global variable is created.
  • Closures let you make information private and give you encapsulation.
  • Inner functions have access to the variables defined in an outer function.

Creating objects with private data:

var incrementer = function() {
  var value = 0;
  
  return {
    increment: function (inc) {
      value += typeof inc === 'number' ? inc : 1;
    },
    getValue: function() {
      return value;
    }
  };
};

var myIncrementer = incrementer();
 

Functional inheritance

var mammal = function(spec) {
  var that = {};
  
  that.getName = function() {
    return spec.name;
  };

  return that;
};

var myMammal = mammal({name: 'Fred'});
myMammal.getName() === 'Fred'

var cat = function(spec) {
  var that = mammal(spec);
  var super_getName = that.superior('getName');

  that.purr = function { /* new catty stuff */ };

  that.getName = function { 
    return super_getName() + ' the Cat!';
  };

  return that;
};

var myCat = cat({name: 'Kitty'});
myCat.getName() === 'Kitty the Cat!'

// Helpers

Object.method('superior', function(name) {
  var that = this, method = that[name];
  return function() { return method.apply(that, arguments); };
});

Function.prototype.method = function(name, func) {
  this.prototype[name] = func;
  return this;
};

There were a few things that I thought could be improved in the book. First of all, although the structure was adequate, it did lend itself to repetition. For example, scope is covered on p36 (in Functions section) and p102 (Awful parts), with very similar words. Secondly, I did not find the frequent syntax diagrams added much to the narrative.

Despite these small blemishes, I’m glad to have read Crockford’s book. I now understand much better which parts of JavaScript to use, and how to build good object oriented code in JavaScript.

XML: When to attribute and when to element?

When defining an XML document, when are attributes most appropriate, and when are elements best? This is something that I’ve generally decided based more on intuition than a good set of rules.

Recently, at work, the need has arisen to define quite a few XML message payloads. I’ve also had the good fortune to work with Erik Doernenburg and we had a chat about attributes vs. elements. Largely thanks to Erik, here are some guidelines that could come in handy when making such a decision.

An attribute is best used to represent:

  • an id
  • metadata (eg, like rel and class in HTML)
  • a value from a small, closed set of values which interpreting programs rely on (eg, values that end up as application constants)

If none of the above apply, an element would likely be the best choice.

Powered by WordPress & Theme by Anders Norén