HNHacker News
TopNewBestAskShowJobs

ahoge

1,026 karma · joined December 11, 2011

submissionscomments
ahoge··on ES6 in Depth – Symbols
> does JS have enums?

No, but TypeScript and Dart do.

Enums don't really work without types.

But using Symbols for fake enums is probably a good idea.

    class Enum {
      constructor(...props) {
        props.forEach(p => this[p] = Symbol(p));
      }
    }
    const dir = Object.freeze(new Enum(...'NESW'));
    console.log(dir.E === dir.E); // true
    console.log(dir.E === dir.N); // false
Slightly awkward, but this might be about as good as it gets.
ahoge··on ES6 in Depth – Symbols
N, E, S, W? I think you want an enum for that.
ahoge··on ES6 in Depth – Symbols
`Symbol.for` uses a global registry and the whole thing is "stringly typed".

Looks like an anti-pattern to me.

If you want one particular symbol from some library, you could import it.

ahoge··on Intel’s contributions in Microsoft Edge: SIMD and other performance enhancements
> Statcounter is unreliable.

StatCounter's stats are very similar to Wikimedia's though. Net Applications is the outlier.

I've only seen IE in the #1 position in the stats of corporate extranet applications.

For all the regular websites it's generally Chrome and IE is either in 2nd or 3rd place. Firefox is kinda popular here, you see.

"Unreliable" is a pretty odd word choice, by the way. Global stats are always different from your own stats. By catering to a particular demographic you're inevitably introducing a massive bias.

Naturally, the only thing that matters are your own stats for a particular website. If it's 95% IE8 then that's how things are. IE8 has to work perfectly. There is no way around it.

ahoge··on Intel’s contributions in Microsoft Edge: SIMD and other performance enhancements
> Microsoft IE has 55% market share.

Only according to Net Applications.

http://en.wikipedia.org/wiki/Usage_share_of_web_browsers#Sum...

Chrome is the #1 everywhere else.

ahoge··on Inside a $34 smartphone
By the looks of it, the physical button is just more annoying to press because it's at the very bottom of the device. You can't easily reach it with your thumb.
ahoge··on Why Japanese Toilets Are Failing in America (2013)
> Wet wipes work quite well.

Wet wipes are terrible for the sewage system:

http://www.nytimes.com/2015/03/15/nyregion/the-wet-wipes-box...

> [Wet wipes] are about $2.50 a pack, or $20 for a metric-xxxxload.

You can buy a cheap mechanical bidet attachment for around $30.

ahoge··on Why Japanese Toilets Are Failing in America (2013)
There are, however, many Americans who started to use wet wipes because they want to feel cleaner.

Bidet attachments and bidet seats ("washlets") are much cheaper in the long run and they also aren't a problem for the sewage system.

By the way, electricity isn't an unsolvable problem. There are water resistant extension cord covers. You can safely extend it.

Maybe it would be a good idea to produce models with replaceable power cords (with generic IEC 60320 plugs) for the American and European market.

ahoge··on Introduction to Object-Oriented JavaScript
One would think that 20 additional characters per function don't really matter if you can save 100 keystrokes.

Compared to JavaScript, I have to press fewer keys when I write Dart. (This would be also true without shorthands like method cascades.)

ahoge··on Introduction to Object-Oriented JavaScript
> but it's not a programming language you're selling me, it's a whole environment

Well, yes, because programming languages don't exist in a vacuum. The currently available libraries, tools, and documentation are very important if you decide to actually do something with that language.

> I have never missed autocompletion in Javascript

A moment ago, you complained about having to press a few more keys for the type annotations.

> I wanted to make the point that I don't automatically consider that "IDEs can autocomplete" is a positive feature

That there are IDEs which let you auto-complete everything is a positive feature.

Being toolable doesn't mean that those tools exist. If those tools exist, you can make use of them if you decide to use this language. This is a good thing.

By the way, JavaScript doesn't lack good tooling because it doesn't need good tooling. It's the way it is, because offering good tooling for JavaScript is really difficult. ES6's modules and classes will help with that though. The tools will make good use of this statically available information.

ahoge··on Introduction to Object-Oriented JavaScript
With optionally typed languages like Dart and TypeScript, you only have to add types to things like fields and functions/methods to get all the tooling benefits. Type inference takes care of the rest.

Secondly, you should be able to auto-complete pretty much everything.

ahoge··on A re-introduction to JavaScript
> The behavior of Number, Boolean, String, and Array is well-defined, it's safe to call them without new.

ES6 is packed with weird but well-defined things.

The problem is that calling a constructor function (a PascalCase'd function) without `new` looks like an error because it generally is an error. To make matters worse, without closely examining that function, you cannot tell if it's an error.

I do know that `Number()` happens to be one of those constructor functions which not only work without `new`, it also happens to behave differently when `new` is missing. It does not return an object. It returns a primitive.

Someone who doesn't know about this unusual secondary function will waste some time if they spot this apparent mistake.

Now, to defuse this time-wasting trap, you could either add a comment... or just do the sensible thing and write it in a way which does not require a comment.

ahoge··on A re-introduction to JavaScript
That's from IEEE 754 (a standard for floating-point arithmetic). `NaN` and -0 exist for the same reason.
ahoge··on A re-introduction to JavaScript
Since calling constructor functions without `new` is generally an error, I'd rather use `parseFloat`.
ahoge··on Intent to Implement: SIMD.js
Intel's (Cordova-compatible) Crosswalk project supports SIMD:

https://crosswalk-project.org/

ahoge··on Ask HN: Would Java make it if introduced today?
I don't think any of the languages which were introduced 20-25 years ago would make it.

All modern languages and all current iterations of the older languages are vastly superior by every imaginable metric.

All those 1.0s from the past would look like someone's toy project, because, well, that's what they were.

ahoge··on FOAM: New JavaScript Framework by Google Engineers
GWT is a set of tools which allows you to write JS front-end applications in Java.

Polymer is a library for creating Web Components.

ahoge··on RethinkDB 2.0 is amazing
There was an article in the past. Well, that's just how Wikipedia is. The Node.js article, for example, has only been undeleted by an admin because someone mentioned it in some "Wikipedia is lame" thread on Reddit.
ahoge··on Boolean parameters to API functions considered harmful (2011)
Not a problem with named arguments.

Too bad that they really screwed that up with ES6:

    function foo({a = 1, b = 2} = {}) {...}
Dart's syntax is a lot easier to remember:

    foo({a: 1, b: 2}) {...}
Another very important detail: ES6's syntax is not declarative. You aren't restricted to "compile-time" constants and you can do all kinds of bogus stuff there.

    function foo({a = 1, b = 2, c} = {c: 3}) {
      console.log(a, b, c);
    }
    foo();         // 1 2 3
    foo({a: 'a'}); // a 2 undefined
    foo({c: 'c'}); // 1 2 c
But wait! There is more!

    function foo({length = 2} = 'foobar') {
      console.log(length);
    }
    foo();            // 6
    foo({length: 0}); // 0
    foo({x: 'x'});    // 2
Just look at that! Those short Hello World examples are already super confusing brain teasers.

I really don't understand why they prioritized this kind of excessive flexibility over tooling. Now you can put entire programs into a function's signature. Why would anyone want that?

ahoge··on Reverse Engineering Wipeout
It's a shame that there was never a good PC version. If I remember correctly, Wipeout 1 had proper timing, but it only offered software rendering. There was one version with hardware acceleration, but it used some crappy proprietary 3D API (ATI CIF).

Wipeout 2 used DirectX, but it used tick-based timing which was meant for 30 FPS. So, if you capped it at 60 FPS by using vsync and 60 Hz, it ran butter-smooth but twice as fast as intended.

ahoge··on Popular JavaScript Package Manager Npm Raises $8M, Launches Private Modules
Many of the bigger "JavaScript" projects aren't written in JavaScript. Browsers support any language. As long as they compile to JavaScript, that is.

Also, Dart just works fine. Inside browsers as JavaScript and outside browsers in its own VM.

This was written in Dart, for example: http://adsense.blogspot.com/2015/04/new-adsense-performance-...

You really don't have to use JS if you don't want to.

ahoge··on Who is behind Dart?
Dart also works outside of browsers. The standalone VM can be used to write command line tools and web servers. You can interact with native libraries and you can also embed it in other applications. It offers excellent tooling and good performance. It's quite a bit faster than Ruby, Python, or PHP (Hack included).

There is also a second JIT-free VM called "Fletch" in the works which is meant for locked-down environments like iOS or Sony's PS4.

ahoge··on AwSnap – This link crashes Chrome
The port number is supposed to be a 16-bit number though. So, anything above 65535 is malformed.

http://en.wikipedia.org/wiki/Port_%28computer_networking%29

ahoge··on Programming Languages in 2014
> Dart now always compiles to JavaScript

Client-side Dart code, yes. But that's something you had to do for compatibility reasons anyways.

Also, don't forget that Dart also exists outside of browsers. It's a fast scripting language with excellent tooling. I use it for almost everything nowadays.

They are also working on a second JIT-free VM (Fletch) for iOS and similar locked-down environments. It's small, highly concurrent, pretty fast, and it supports atomic code updates via some wire protocol. So, Dart doesn't just compete with TypeScript on the browser side, it also completes with languages like Ruby, Python, and PHP on the server side and even with compact embedding-friendly languages like Lua.

Dart's future looks bright, but it's definitely a lot less browser-centric than initially anticipated.

ahoge··on I won't be using Angular for my next project
> Angular 2.0 [...] doesn't fix any of today's problems

Directly followed by:

> Views and data-binding are a mess, and seriously degrade performance

Want to have your cake and eat it, too?

Angular 2.x does simplify things quite a bit and it also offers much better performance.

ahoge··on Chrome’s Console API: Greatest Hits
> Don't use that in prod

A linter will catch this.

ahoge··on Image Decoding on the GPU Now in Firefox Nightly
IE11 actually does some of the JPEG decoding on the GPU:

http://blogs.msdn.com/b/ie/archive/2013/09/12/using-hardware...

So, this really doesn't work as a joke.

ahoge··on More Details About Project Spartan
As a web developer or user, you can't really see the similarities anymore. The basic stuff like CSS 2.1 works the same everywhere. It's the new features where the browsers differ.

http://caniuse.com/#compare=ie+TP,firefox+39,chrome+44,safar...

Chrome matches Safari in 57 cases. However, Chrome matches Firefox in 61 cases. So, going by the implementation status of those features, Chrome might as well be using a fork of Gecko.

Here is the script I used:

    for (let b = 1; b < 5; b++) {
      let r = [0, 0, 0, 0];
      [].forEach.call($$('tbody tr'), function (row) {
        for (let i = 0; i < 4; i++) {
          r[i] += +(row.cells[i + 1].className === row.cells[b].className);
        }
      });
      console.log(r);
    }
Output:

    [130, 35, 36, 48]
    [35, 130, 61, 36]
    [36, 61, 130, 57]
    [48, 36, 57, 130]
ahoge··on More Details About Project Spartan
They should be over 100k commits apart by now.

A lot happened in those 2 years.

ahoge··on Dart 1.9
This is the biggest release since 1.0. Async/await and generators are a welcome addition. Shareable server sockets and better isolates are also nice to have.

Enums are currently rather disappointing though. They went with the simplest possible implementation... minus 1. You can't assign integers. Which is a problem because you can do that everywhere else. Naturally, there are many protocols and formats which use ints to represent specific enum values.

I hope they'll fix this in the future.

Speaking of the future, there are a bunch of other interesting things on the horizon such as null-aware operators, non-nullable types, and union types.

The upcoming "Fletch" runtime for iOS and similar restrictive environments is also very exciting. It might turn Dart into the perfect language for video game scripting. It's small, fast, and it supports atomic program changes via a wire protocol.

← PreviousPage 3 of 16Next →