Skip to content

Instantly share code, notes, and snippets.

Today I had a brief debate on twitter about AMD vs CommonJS, https://twitter.com/TechWraith/status/441387541778808832. It's a debate worth having for sure. But I had to bail out of this one. The thing that annoyed me is that the first argument that people bring up to disquality AMD is "the syntax is too complex". I disagree with this. There are lots of reasons to prefer CommonJS over AMD, but the module authoring syntax is not a very good one. There was also a related statement that AMD authoring introduces more "cognitive overhead". This is absolutely true. But I don't consider this to be synonymous with "complexity" by any means.

So I thought I'd explore some comparable examples. Here's a simple one that was offered up by someone else in the thread. This was on twitter so I can forgive erring on the side of brevity.

AMD

define('myThing', ['some', 'deps'], function (some, deps) {
  //my code
  
 return myThing;

Currently you can export things from a module in at least six different ways, and import things in at least six different ways, resulting in 36 different combinations, most of which are not semantically valid.

Here is a greatly simplified (and probably naive) suggestion for modules in ES6:

###export You can only export named things, including variables and functions.

let a = "hello";
export a;
@necolas
necolas / webpack-pre-css-loader.js
Created September 8, 2014 20:15
webpack-pre-css-loader.js
var path = require('path');
/**
* CSS transform dependencies
*/
var autoprefixer = require('autoprefixer-core');
var calc = require('rework-calc');
var color = require('rework-color-function');
var conformance = require('rework-suit-conformance');
@domenic
domenic / .bashrc
Last active September 1, 2015 17:50
.bashrc with GitHub PR function
pr () {
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1 --force
git checkout -b pr/$1 origin/pr/$1
git rebase master
git checkout master
git merge pr/$1 --ff-only
}
I decide to work on a new feature, so I create a branch, topic.
o---o master
\
o---o---o---o topic
I am not yet finished working on my feature when I have to make some bugfixes to master
o---o---o---o master
@jumski
jumski / backbone_sync_hack.coffee
Created August 5, 2011 17:10
BackboneJS sync hack to namespace params when saving/updating model
###
Usage:
* add model.name property that will be used as a namespace in the json request
* put this code before your Backbone app code
* use toJSON() as usual (so there is no namespacing in your templates)
* your model's data will be sent under model.name key when calling save()
###
# save reference to Backbone.sync
Backbone.oldSync = Backbone.sync
@avakhov
avakhov / ability_rules.rb
Created August 27, 2011 19:18
six gem usage
class AbilityRules
class AccessDenied < Exception
end
def self.allowed(user, subject)
rules = []
railse [user, subject].inspect # <--- this exception was rescued by six rescue block (of course it need only in development for debug :)
return rules unless user
anonymous
anonymous / marshal.js
Created December 31, 2012 06:20
NodeJS module to allow unmarshaling of Ruby serialized objects. Works fine for simple objects, but there's no clear way to implement classes, etc.
"use strict";
/**
* @author geoff
*/
var Marshal = (function() {
var debug = false;
var symbols;
var marshal_major = 4, marshal_minor = 8;
@ryanflorence
ryanflorence / package.json.md
Last active December 23, 2015 02:29
Lets make a better package.json

A better package.json

Right now everybody seems to be creating their own .json.

Here are the reasons I think it happens:

  1. node dependencies may be different than browser dependencies
  2. node main.js may be different than browser main.js
  3. {project} {something} may be different than {project2} {something2}
@roberttod
roberttod / cookie-blocking-test.js
Created October 10, 2013 10:29
Test if the cookie is locked during synchronous execution.