Better HN
topnewbestaskshowjobs
Log inSign up

phpnode

7,416 karma · joined Oct 23, 2009 (17y ago) · 1,582 submissions

Founder of https://codemix.com/ - authoritative product context which makes sure coding agents build the right thing and humans stay in control.

Email: charles@codemix.com

Submissions

comment 10y ago · link · parent

That's a very different attack vector to the one in this post - buffer overflow vs legit service running on open ports unbeknownst to the user

comment 10y ago · link · parent

Still waiting for you to make good on this promise :)

comment 10y ago · link · parent

GDC = Global Development Centre

comment 10y ago · link · parent

We're all here to learn, if you've got some insight into what the article got wrong then why don't you school us?

comment 10y ago · link · parent

Looks refreshing! http://d2ydh70d4b5xgv.cloudfront.net/images/2/c/vintage-mark...

comment 10y ago · link · parent

I've never seen a type system expressive enough to cover all the things that contracts can do, e.g does a type system exist which can assert the existence and size of a particular file on disk?

comment 10y ago · link · parent

Contracts are just structured assertions, they're very similar.

comment 10y ago · link · parent

Your argument seems more like one against transpilers in general.

Contracts are useful during development, they're typically stripped out in production builds, so there's no performance overhead there. If you find a bug in production, turn on your contracts and you'll quickly discover the source of the error. Contracts can validate the state of the world at runtime in a way that can never be covered by unit tests, unless your tests cover all possible inputs to your program. It doesn't mean you don't need unit tests too, they are yet another layer of safety.

I use this in combination with Flow, which means I have to transpile regardless, so the overhead is very low for me. Of course I'd like them to be part of the language proper, but for that to happen there needs to be developer demand first.

comment 10y ago · link · parent

Limited Partners

comment 10y ago · link · parent

It's definitely most useful when combined with type annotations. They're complementary tools, annotations can ensure type safety at compile time, but type safety is only one part of program correctness, whereas contracts can validate just about any aspect of program operation because they have access to all of the runtime information. They're like unit tests that run all the time (until you strip them in production at least).

This thing can be used alongside Flow[0] and other babel plugins which use flow syntax.

[0] https://flowtype.org/

comment 10y ago · link · parent

It's always baffled me why more people don't seem interested in adopting design by contract, it is a ridiculously powerful tool for writing quality software.

Here's a Babel plugin which adds design by contract to JavaScript, squeezing it into existing JS syntax (the result is really similar to Eiffel) - https://github.com/codemix/babel-plugin-contracts

and here's what it looks like in a reasonably complicated program - https://github.com/codemix/malloc/blob/master/src/index.js

(disclosure: I wrote this)

comment 10y ago · link · parent

No SIMD intrinsics yet

comment 10y ago · link · parent

Fried. Not deep fried. No one would do that.

comment 10y ago · link · parent

You wanted to open a bank account in Germany, yet couldn't ask even the most basic questions in German? And you characterise this as a failing of the other party (the bank)? That is insane!

comment 10y ago · link · parent

I think you'd run into escaping issues like that. It would have to be:

    <JavaScript src={`[1, 2, 3].map(n => n + 1)`} />

comment 10y ago · link · parent

Do you have a link to that poem?

comment 10y ago · link · parent

It bothered me more than it should have that you used isuckat@passwords.com instead of isuck@passwords.com for your example :)

comment 10y ago · link · parent

That doesn't need to be true for this to have happened. Zuck is a high profile target, probably the hackers just prioritised cracking his account and such a weak password would be found reasonably quickly even using bcrypt

comment 10y ago · link · parent

You are asking a question, I do not owe you an answer, it's up to you to find out whether this stuff matters for your use case. I've done these tests myself, it is trivial for you to do the same. Do your own homework.

comment 10y ago · link · parent

By the same token, why do I owe you any further evidence?

comment 10y ago · link · parent

Check out the Bluebird benchmarks [0], or you can easily try it for yourself - create a simple web server which does some makework async task, like stating a bunch of files, then benchmark with ab or something better.

[0] https://github.com/petkaantonov/bluebird/blob/master/docs/do...

comment 10y ago · link · parent

The call itself is relatively expensive, but as you say it's a one off call at startup time and the methods it produces are faster than explicit promisification using `new Promise`, they are blazing fast :)

comment 10y ago · link · parent

Bluebird's `promisifyAll()` is just a way to generalize that pattern, so that you don't need to write it yourself. And if you care about performance it's substantially faster too. If you want to learn about the pattern then fine, but personally I don't want to write that for every single `fs` function I use in a project, it's much more convenient to just `Bluebird.promisifyAll(require('fs'))`.

comment 10y ago · link · parent

Presumably instances of `MyObject` can be accessed by functions which are running while this function is suspended, waiting for the network call. It's single threaded, as in only one thing happens at a time from JS's point of view, but other functions can be invoked (by a request coming in, or a UI event etc) while an asynchronous operation is awaiting completion.

comment 10y ago · link · parent

Bluebird is mainly designed for node (V8) and promise performance can make a massive difference on the server. On the client there tend to be fewer async calls and so promise performance is usually less of a factor, but obviously, it depends what you're doing.

comment 10y ago · link · parent

> Isn't the whole point of promises that they can be chained together without nesting?

Yes, it's an excedingly common misunderstanding and probably one of the main causes of people being "turned off" by promises. It's kind of frustrating to see so many blog posts making this mistake when critiquing them.

comment 10y ago · link · parent

I think your examples could be simplified:

    export default function getUsers () {
      return getUsersFromDB()
      .then(filterUsersWithFriends)
      .then(getUsersLikes);
    }
And there's just about never a reason to use the `Promise` constructor in real world code. If you already have a promise as in your example, so you can rewrite your refactoring as:

    export default function getUsers () {
      return getUsersFromDB()
        .then(users => filterUsersWithFriends(users).catch(err => trySomethingElse(users)));
    }

comment 10y ago · link · parent

This is happening because of compiler optimisation technique called Loop Invariant Code Motion [0], which means that the author is not measuring what he thinks he's measuring (and this should be obvious from the numbers really), so the result is meaningless.

0. https://en.wikipedia.org/wiki/Loop-invariant_code_motion

comment 10y ago · link · parent

Replying to myself because it is too late to edit: thinscript isn't exactly typescript, it has some extra features and doesn't attempt full js compatibility, but they are very similar.

comment 10y ago · link · parent

Here's something a bit like that, it turns TypeScript into JS, WASM and C, very early but interesting - https://github.com/evanw/thinscript
1
242526
53