Better HN
topnewbestaskshowjobs
Log inSign up

substack

1,135 karma · joined Mar 22, 2009 (17y ago) · 212 submissions

Whatever.
Submissions

comment 13y ago · link · parent

This kind of static analysis is really easy to do with falafel:

https://gist.github.com/substack/4735826

Program:

    var falafel = require('falafel');
    var fs = require('fs');
    var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
     
    var output = falafel(src, function (node) {
        if (node.type === 'IfStatement'
        && node.test.type === 'MemberExpression'
        && node.test.object.name === 'Meteor'
        && node.test.property.name === 'isServer') {
            node.update('');
        }
    });
    console.log(output);
Input:

    if (Meteor.isClient) {
        console.log("I'm the client!");
    }
    
    if (Meteor.isServer) {
        console.log("I'm the server!");
    }
Output:

    if (Meteor.isClient) {
        console.log("I'm the client!");
    }
This won't catch fancy things like Meteor['isServer'] or compound expressions but should be a good place to start.

edit: I had them backwards. Fixed now.

comment 13y ago · link · parent

Click on any of these demos: http://voxeljs.com/#gallery

comment 13y ago · link · parent

And another new voxeljs module for portals: https://github.com/substack/voxel-portal http://substack.net/projects/voxel-portal/

comment 13y ago · link · parent

What a crazy coincidence, I just factored out my company's payment widget code into a reusable module a few days ago: https://github.com/substack/pricing-widget

Basic example: http://substack.net/projects/pricing-widget/basic/ Fancy example: http://substack.net/projects/pricing-widget/browserling/

comment 14y ago · link · parent

The service registry I wrote (http://github.com/substack/seaport) is fundamentally version-aware to avoid this problem. You register services with a semver such as `web@1.2.3` and then clients or other services query for registered services with semver query strings such as `web@1.2.x`. This way you can specify your breaking changes much more explicitly and not need to port over the clients to the new service all at once.

comment 14y ago · link · parent

     and it DOES work with everything
... so long as you wrap all the files in the particular variant of define() function that works with requirejs (but not with other competing AMD function signatures). And then you might want to use some modules written for commonjs or node with `exports`, so you'll need a tool to transform those files. And then you'll probably want to compile the application into a single javascript bundle in production for performance.

I'm not saying bower is any better in any of these respects, just that everything is terrible.

comment 14y ago · link · parent

No. If anything, it will probably just get even more fragmented before the situation gets better. As we understand the features and architectures of package management systems better it becomes even easier to write package managers. This is a good thing long-term because we can more thoroughly explore the solution space before settling on a few "winners". However, at the same time package repositories are fundamentally a network effects problem because packages depend upon other packages, so the repository with the most packages offers the most benefit for each additional package because new packages can build on everything that already exists instead of bundling that functionality themselves.

The reason why I am skeptical of new entrants into the javascript package management arena is that there is already a package manager with over 14k packages and a vibrant community that is producing packages at a very high rate: npm. npm might not be the best package manager as-is for browser development, but tools like browserify (disclaimer: I wrote browserify), ender, or many others can let your browser code use much of the value that has already been created for npm, even though npm is primarily about node.js packages. A surprising number of modules written for node will just work in tools like browserify.

Any upstart package systems would be wise to have a clear and simple path for unlocking the value created in the node community because there is too much value being created in npm to ignore. Whether that path involves adding fields to the package.json, tools to bridge the gap between package repositories, fancy in-browser trickery or compile steps remains an open question but it would be really pointless to require people to publish their modules that they've already put on npm to buy in to yet another package system, especially since there seems to be a new package manager every month lately.

comment 14y ago · link · parent

Actually that code snippet that computes a summation can be done without any loop or recursion at all:

    function sum (m, n) {
        return m * (m + 1) / 2 - n * (n - 1) / 2
    }
I only know this because I remember from math competitions in high school learning that you can compute the sum of the digits from 1 to n quickly from `n * (n + 1) / 2` which naturally follows from the equations regarding binomial sums.

This example somewhat agrees with the author's main point that we are more a product of our experiences than endowed with certain innate capabilities.

comment 14y ago · link · parent

I've complained about this before too, but if you click the "i" with a circle around it in the bar that says "this pull request can be automatically merged" you get a nice box with all the git commands to do a local fetch and merge. I think this functionality should be less hidden away but it is there and quite useful.

comment 14y ago · link · parent

If you want to play with this new version but also have code running on older versions that hasn't been completely ported yet, I recommend using nave to manage your node versions. After you `npm install -g nave` you can just `nave install 0.8.0` to get node 0.8 then type `nave use 0.8.0` to start using it!

https://github.com/isaacs/nave

comment 14y ago · link · parent

The verify phase was just defining an inline function but not running it. However, I just noticed that a program with carefully placed braces could jump out of the function box and actually run. I replaced the checker with just Function(src) which shouldn't have that problem and is much faster.

comment 14y ago · link · parent

Nice to see people using some of my libs to do nifty stuff but I must caution against depending on `latest` since this could cause your application to break in the future if I push breaking changes: https://github.com/ptrsghr/joint/blob/master/package.json#L5...

It's a better idea to do:

    "dnode" : "~0.9.11",
    "browserify" : "~1.10.17"
since that way you'll get patch fixes automatically but your library won't break when I push out an update that bumps the minor version, which could including backwards-incompatible changes.

comment 14y ago · link · parent

Sorry about that. We booted up a ton more free servers but the queues are still rather large. On days when we're not getting a traffic spike you can usually use the service right away.

comment 14y ago · link · parent

This is a nifty feature and npm can do something very similar:

    npm install git://github.com/substack/node-optimist.git

comment 14y ago · link · parent

Check out tap, it has a very simple api that works well for testing asynchronous code: https://github.com/isaacs/node-tap

Here's a tap example that sets up a server and client for dnode: https://github.com/substack/dnode/blob/master/test/single.js

Timers usually aren't necessary with test harnesses like tap or nodeunit since you need to call `t.end()` explicitly or else `t.plan()` the number of tests that are supposed to be run. If a different number of tests actually run or assertions fire after `t.end()` is called, those are reported as errors.

For (4), to run a bunch of test files in a directory you can use the `tap` command. You can even add something like `tap test/*.js` to the scripts.test field of a package.json file and then to run all your tests you can just do `npm test`.

76.

Multi-server continuous deployment with fleet(substack.net ↗)

7 points · by substack · 14y ago · discuss

comment 14y ago · link · parent

For which there is a massive amount of selection bias going on. I would want to see actual figures and a proper linear regression model before jumping to any conclusions here.

comment 14y ago · link · parent

Part of my point was that "self-selecting out the gene pool" does nothing to dispel harmful beliefs. That is a culture and education problem.

comment 14y ago · link · parent

    > And, for the record, I'm all in for homeopathy and faith
    > cures - they may help remove some undesirable genetic
    > traits from the gene pool. OTOH, the populations presenting
    > such traits can evolve to have better immune systems. Life
    > has a way to perpetuate itself.
Susceptibility to harmful ideologies really doesn't work like that. Being raised within a religion or cultural practice is an amazingly better predictor for continuing that belief in the next generation than what genes were passed along. Faith cures and placebos operate at the level of belief and culture, not the gene level.

Further, look no further than the anti-vaccination movement to see how harmful medical ideas can put the general population at a greater risk for entirely preventable diseases.

comment 14y ago · link · parent

That seems like a massively inefficient way of doing things. Tests are very inexpensive since they can run without human intervention. Code review requires another human to sift through changes. If the automated tests pick something up first then the code reviewer wouldn't need to sink any time into a review in the first place.

81.

Colorful javascript object diffs with difflet(substack.net ↗)

15 points · by substack · 14y ago · 1 comment

comment 14y ago · link · parent

I mean why does `module` pull down resources? Shouldn't that be import's job?

comment 14y ago · link · parent

Thanks for this. I'm glad that using a single export function will at least be possible. I'm still pessimistic about the amount of syntax being introduced here.

In particular, I still really dislike the special import "local renaming" syntax since it seems so unnecessary compared to just having an import keyword that returns an object and letting the programmer extract and manipulate the relevant entries. You would still get the static analysis benefits of having static imports without all the awkward complexity of the current proposal. Wouldn't it just be the same thing to Object.freeze() the export object but without any syntax magic necessary?

Plus, overloading `module` to do loading AND defining with the `module Bar at "uri"` form seems really wrong. Why can't it JUST do defining and just let import do all the loading?

comment 14y ago · link · parent

I really dislike what they're doing with modules because it's such a step back from the commonjs-inspired require() that node uses. In node, require() just returns a value. That value is usually an object but often it's just a function. Why should a module that encapsulates exactly one function return anything else but that one function?

In ES.next, you've got to use pythonesque `import y from Bar` statements which introduce a frustrating correspondence between the lexicals of your own program and the export names of the module you're trying to use which is really terrible if you're using as many modules as I typically do. I presume ES.next will invent even more specific syntax for some sort of `as` like keyword to side-step this but it seems so unnecessary when javascript already has a module system that is so very good as is exploding in popularity and use (>7000 modules now on http://search.npmjs.org/).

I understand what they're trying to do with static analysis too but you can already pretty much do that and I've done it. It's not hard at all, just ignore require() statements that don't contain strings when you walk the AST, like this: https://github.com/substack/node-detective

Inventing more syntax instead of just adopting a far better module system that has seen actual use in practical situations is such a shame and ES.next is rife with this kind of prescriptivism. It irritates me to no end and I sometimes want ES.next to die a quiet death in obscurity because of it.

http://wiki.ecmascript.org/doku.php?id=harmony:modules

85.

Semver your services with seaport(substack.net ↗)

2 points · by substack · 14y ago · discuss

comment 14y ago · link · parent

> JavaScript has very little support for any of those nice things: it doesn't even have namespaces, for chrissakes. Why would I want to repeat these same mistakes over and over again in a new language?

Javascript doesn't have this (by itself) but node has a very nice require() system that is really excellent for long-term maintainability. When you bump a dependency in a node project that change will only affect the code near it because of how node_modules are resolved to the most local copy. You can bump dependencies without worrying how this will affect other packages.

Plus, require() just returns an object. It doesn't puke a bunch of objects into the current scope. This is massively useful for readability. I've sunk a lot of time on other systems tracking down unqualified exports to figure out which package's documentation to consult.

I've got nothing against scala and am sure it's a useful language but I wonder if the author has even used node.

comment 14y ago · link · parent

At the civic level, check out some of the projects that the Code for America folks are up to: http://codeforamerica.org/projects/

comment 14y ago · link · parent

As a hacker/founder who has also taken up the art/design role, I disagree and think that developers who can draw reasonably well should try designing the art assets for their startups.

When you design your own art assets, you can iterate on the design in a much more incremental way because the transaction cost of going out and finding a designer is quite high. When you can design your own assets in-house, the art can work its way into the core of the product better and ends up in more places. For instance, many of the modules my startup has released have silly cartoons that I drew: http://www.catonmat.net/blog/browserling-open-sources-90-nod...

When there are external barriers to art, you're probably going to use it less. Contracting out for all of those silly readme cartoons would be wildly uneconomical but for me it provides a nice refuge from coding all day that happens to help us establish credibility with potential customers and expand our product exposure.

If you are a developer who is going to try your hand at doing the art yourself, I wouldn't be too concerned if your initial attempts look amateurish. Our earliest prototype looked really bad:

http://substack.net/images/screenshots/browserling-1.png

but we iterated and made it a little better:

http://substack.net/images/screenshots/browserling-3.png

and then did a redesign recently:

http://browserling.com/

Make some art!

12345
8