635 points · by gary_bernhardt · 12y ago · 227 comments
if (a) b;
and if (a) { b; c; }
which tends to make you think of curly braces as a syntactic feature which can appear anywhere, turning many lines of code into one line of code. If you think that way then these should possibly also be valid: {b; c}
{b}
{}
but, since JS scope is function-oriented and in other places (e.g. functions) the braces are ultimately needed anyways, even for one-liners, it seems like this was a stupid choice and we should have just rejected the form: if (a) b;
and then the reuse of {} for lightweight (if non-robust) hashmaps would perhaps be unambiguous again.All his opinions should be discarded.
edit: nevermind, I clicked the download link. But I'm still wondering why the video's unplayable on the site.
Javascript is great once used in a "good" way. It's flexible & it's almost everywhere. Spending all your time complaining about how "bad" Javascript is kindof pointless. If you use Javascript, learn how to use it well.
Master sushi chefs don't sit there complaining how bad knives are because the knives need to be constantly sharpened.
If you are cooking spaghetti, learn how to strain the noodles, instead of using silly examples assuming people are incompetent at learning a tool.
Sushi knives don't decide to cut you because the rice came from a different origin. And I'd guess that most craftsmen, outside of a ritual and tradition would love for their tools to have less disadvantages.
If you want to draw an analogy to spaghetti (?), it'd be like complaining that the only kind of spaghetti you can buy locally cooks only at a specific temperature, and even a bit more turns it to mush. And the reason is because the local government passed a bylaw with only a few hours of consultation that ended up banning imports of better kinds of spaghetti.
While it might be "pointless" to spend all your time complaining, there's certainly value in asking "wat" and pointing out absurdity.
In the mean time, one can learn to appreciate & use javascript strengths. It can be quite fun, liberating, & useful. Anecdotally, I have not run into these crazy issues, and I program in javascript everyday. I also have a large app and the framework I built is custom.
I liken this to using C++, Unix, & bash as a base. Yes, you could say these tools suck and spend time creating, marketing, & community-building for a new tool. Or you can iterate & improve upon these existing tools. There's no wrong answer. What do you want to accomplish?
> Sushi knives don't decide to cut you because the rice came from a different origin.
That analogy seems like a stretch. Care to explain? Javascript works with different locales. There are many international websites that use javascript.
Also, javascript does not "decide" to create a bug in your program. You create that bug by misusing the tool. You will get further if you take some responsibility and improve your practice.
> And I'd guess that most craftsmen, outside of a ritual and tradition would love for their tools to have less disadvantages.
I agree with that. Usually the improvements are iterative. One could use a laser cutter (which does not need sharpening) to cut sushi, but that would also burn it. Here's a good talk (Clojure: Programming with Hand Tools).
https://www.youtube.com/watch?v=ShEez0JkOFw&safe=active
Ritual & tradition is a social tool to propagate knowledge, idioms, & practices across generations. It makes sense to challenge ritual & tradition to they improve over time. It does not make sense to whine about it without doing anything.
> it'd be like complaining that the only kind of spaghetti you can buy locally cooks only at a specific temperature, and even a bit more turns it to mush
Not getting your analogy. This seems like a stretch, similar to the person who cannot strain the spaghetti noodles on the video. Care to explain?
And your examples make sense, javascript doesn't (in some cases) so it's very appropriate to complain.
In that case, it's appropriate to complain about gravity & being restricted to the speed of light?
No, it's better to learn about and use these properties to your advantage.
However, I also want to rave a bit about his presentation in general! That was very nicely delivered, for many reasons. His commitment to the story, of programming from the perspective in 2035, was excellent and in many cases subtle. His deadpan delivery really added to the humor; the fact that he didn't even smile during any of the moments when the audience was laughing just made it all the more engaging.
Fantastic talk, I totally loved it!
For some weird reason (I'm not an OS/CPU developer) switching to long mode on an x86 cpu also turns on the mmu stuff. You just can't have one without the other.
There's a whole bunch of research done on VM software managed operating systems, back when the VM's started becoming really good. Microsoft's Singularity OS was the hippest I think.[0]
Perhaps that ARM cpu's don't have this restriction, and we will benefit from ARM's upmarch sometime?
[0] http://research.microsoft.com/en-us/projects/singularity/
I don't have a good sense of how the performance cost of hardware isolation breaks down into {virtual memory enabled,TLB thrashing,protection ring switching}. That's one of the reasons that I reduced the speed-up from "25-33%" in the MSR paper down to 20% in METAL. Maybe the speed-up would be less than that if virtual memory were still enabled.
Unfortunately, that distinction may have been blurred in the talk. That is, I may have implied that METAL would turn the MMU off entirely. If so, it was an oversight. I've done the talk end-to-end at least fifty times, which is how I smooth my execution out. Occasionally it can "smooth" the ideas out a bit too, leading to small inaccuracies. It's sort of like playing the telephone game with yourself (which is a very strange experience).
The MSR paper that I quote came from the Singularity team, so your reference is right on. Reading "Deconstructing Process Isolation" in fall of 2012 was probably the germ of the core narrative of the talk.
EDIT:
Kernel memory begins at PAGE_OFFSET, see here: https://www.kernel.org/doc/gorman/html/understand/understand...
Kernel memory lacks the flag _PAGE_USER so that it isn't accessible from userspace: https://www.kernel.org/doc/gorman/html/understand/understand...
To try to paint a very rough picture of the larger thoughts from which this talk was taken: I think that microkernels and the actor model are both the right thing (most of the time). When implemented naively, they both happen to take a big penalty from context switch cost. But Erlang can host a million processes in its VM, and we're using VMs for almost everything now anyway.
The obvious (to me) solution is to move both the VM and an Erlang-style, single-address-space scheduler into the kernel. Then you can have a microkernel and a million native processes without the huge overhead of naive implementations. There are surely many huge practical hurdles to overcome with that, and maybe some that can't be overcome at all, but it sure sounds right when written in two paragraphs. ;)
It has a single 64-bit address space and only protection contexts, and due to the general design of the system it doesn't require any register push(or registers at all, at least in the traditional sense). In addition, it has primitives which would allow programs to call directly into drivers and kernel services without a context switch.
Anyway, I don't mean to sound like an advertisement, and we've yet to see any silicon, so the jury's out.
Aside: Starting process address spaces at 0 is not really a convenience as far as I know(other than offering consistent addresses for jumping to static symbols), it's a way to enable PAE on 32-bit machines so that single contexts(typically processes) can use the whole address space.
While these probably won't be available in the next 5 years, and probably won't be acknowledged by existing programmers for decades - I think these ideas will take over.
http://arc.cecs.pdx.edu/publications https://www.youtube.com/watch?v=jR9pAaQlVRc
Now I didn't read the paper, but I think the 20% is purely the MMU, I think the protection ring switching thing is much less significant, so I think if you leave the MMU still on that 20% profit is still very optimistic.
Now, if you forget about compiling C (which defeats the purpose of your talk) and just compile managed languages like regular JS, the garbage collector can build a great model of memory usage. Therefore I think it could be much better to let the garbage collector manage both the isolation, and the swapping. So everything in software.
The swapping process would suffer some performance, but that's just CPU cycles, as everyone knows persistent data access isn't even in the same league as CPU memory access.
So yeah, that would mean that you would have to run all untrusted code in managed mode. And with untrusted I would mean code you can't trust with full physical memory access.
All of them are based on the concept of using memory safe languages for coding while leaving the runtime the OS role.
Except for C and C++, language standard libraries tend to be very rich and to certain extent also offer the same features one would expect from OS services.
As such, bypassing what we know as standard OS with direct hardware integration, coupled with language memory safety, could be an interesting design as well.
That is why I follow the Mirage, Erlang on Xen and HaLVM research.
http://erlangonxen.org/ http://kerlnel.org/
Also there is another project that can be related to that goal:
"Our aim is to remove the bloated layer that sits between hardware and the running application, such as CouchDB or Node.js"
From about 14:40 he gets animated, basically conducting! Would love to know a programmer's explanation for the function or purpose of arm waving and hand signals in a presentation. Not knocking, just curious!
Though I'm far less funny about it.
It's an 18 minute interview, and the show notes are detailed and timestamped. I especially liked the references to the Singularity project.
[1] http://en.wikipedia.org/wiki/Voiced_palato-alveolar_affricat...
> xs.map(parseInt)
[10, NaN, 2]
Javascript is beautiful.
var mappableParseInt = function(str){
return parseInt(str, 10);
};
['10', '10', '10'].map(mappableParseInt);
I'd suspect this snippet is more a snipe at people who don't know JS very well and expect parseInt to be base-10 only.I dunno, as someone without much experience with Javascript, it is a little odd that arrays return the index alongside the value by default.
>>> ['10', '10', '10'].map(x => parseInt(x, 10))
[10, 10, 10]The programmers are not the ones to blame on that.. this is really a bad contract between the language and the programmer
Its the equivalent of a function named "getStone()" to return you a " Paper{} " :)
xs = [
parseInt('10', 0),
parseInt('10', 1),
parseInt('10', 2)
]parseInt internally uses the ToInt32 abstract operation on the radix parameter. Once it has that value, it explicitly looks to see if the value is 0. If it is, it uses a radix of 10.
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-pa...
Edit: I hope that doesn't come off as pedantic. My point wasn't to disagree as much as it was to just add some further explanation.
Try this:
int subtract(int b, int a) { return a - b; }
int test = subtract(5, 3); // != 2, just read the damn docs
Oh, C sucks now !
The talk is quite fun and interesting to watch though.
And the end is pretty cool.
The number one thing taught at user interaction / usabillity courses is that users don't read the documentation. Or skim it and go directly to one or two parts they want to check (Sure, some bizarro outliers do read it all).
Besides, a golden rule from the UNIX era is the "principle of least surprise". Don't define stupid behavior as default, as in this case (both for parseInt and Map).
Let's assume JavaScript is a poorly-designed language, and Clojure is a well-designed language. In the first month of language use, the user of Clojure will have looked at the docs many more times.
And by "this is just stupid" do you mean "this === just stupid"?
If you think that's bad, you should see this!
Always. The moment you don't, all kinds of bugs follow.
I have to go cry now at the number of times this has bitten me.
xs.parseInt(Number)
function overValues(f) { return function(x) { return f(x); } }
Then you can do ['10', '10', '10'].map(overValues(parseInt));
However, usually you're going to want to do the equivalent of this ['0101', '032'].map(function(s) { return parseInt(s, 10); })
Because Javascript interprets a leading zero as an indicator of base.> as an indicator of base.
As an indicator of base 8 (octal).
['10', '10', '10'].map(Number);
var xs = ['10', '10', '10'];
xs.map(function (str) {
return parseInt(str, 10);
});
> [10, 10, 10]
Fixed that for you. Why? map callback params: (value, index, originalArray)
parseInt params: (string, radix)
Your code is passing the map array index to parseInt's radix.;)
The number of security issues that plug-ins have had in the last two decades makes most of them non-starters nowadays, although there are still plenty of sites that use them extensively (say, Childrens' game websites like Neopets and Nick Jr.'s website) depending on the target audience.
http://www.washingtonpost.com/world/asia_pacific/due-to-secu...
Javascript won for this reason.
Javascript just required that you click refresh.
Especially on 1995 technology, that mattered. Compiling Java took a while. I didn't use Flash enough to retain an impression of speed, but it sure wasn't instantaneous.
The fact that Java, ActiveX etc.. had full control of the system and causes problems ensuring security was an issue, but it is not the reason why JS beat them all.
Don't discount the power of 1) free and 2) easy to use software that is 3) not controlled by a single corporation. JS is the only web programming language that is all of these.
Yea, maybe Python or Clojure in the browser would be cool. I would argue Clojure is absolutely more difficult for a novice to learn, and Python provides what additional benefit? JS was there first.
The only reasons why plugins existed is you couldn't do these kinds of things in the DOM. JQ, and the subsequent advances in browser technology, HTML, CSS, JS - made it so you can. Also, other things being equal - programmers will choose elegance over bloat, less layers of abstraction over more. Plugin architecture became just an unnecessary layer between the programmer and the browser, after HTML/JS/CSS caught up.
JS did not become ubiquitous by accident, or because it was the only choice. There were many choices (all being pimped by big well-funded companies). JS won because it was the better than the alternatives.
Javascript, on the other hand, was omnipresent and comparatively accessible. It was the least bad option by a wide, wide margin. For a different comparison, I switched from Java applets to PHP in the early 2000s. I didn't really get into Javascript until many, many years later around 2009: before that, Javascript was mostly a way to make Flash work properly.
There was also the version issue to worry about. "Pardon me, Mr./Ms Customer/User -- would you mind terribly going and downloading and installing a 20 MB Java update on your 14.4k dialup connection before using this page?"
Nightmarish, it was.
Even stranger is how Sun, a hardware/platform company, decided making a popular platform that's hardware and platform independent would help their business. Sometimes I wonder if there was a really well thought-out plan, or people were just doing things.
(I'm typing this from my Pixel...)
http://unrealengine.com/html5 seems to have been purged from the internet (possibly due to this year's UE4 announcements?) and I can't find any mirrors anywhere.
Which is a shame, because that demo was how I used to prove to people that asm.js and the like were a Real Thing.
I want to become a full stack developer. I can program and write tests in ruby, I can write applications using Sinatra and now I am learning rails. I bought a book to start learning JavaScript because it's the most popular language and basically will allow me to write modern applications. After I'm done with JS I'll probably jump into something else (rust, go, C, C++, Java, whatever helps do the staff I want).
But watching this video, I'm confused: I avoided CoffeScript because I read in their documentation that in order to debug the code you have to actually know JavaScript so I figured that the best thing to do is learn JS and then use an abstraction (i.e. Coffescript) and tools like AngularJS and Node.js... Is my approach wrong? :-/
In practice, however, all that lovely Coffeescript syntax can easily trip you up; often something will compile successfully, but not to the 'right' Javascript. I wouldn't recommend CS until you get your head around the fundamentals of JS. In particular, CS does some very 'clever' things with the Javascript this object; I have certainly lost my scope at unexpected points in CS programs (often in loops). When you're optimising code, furthermore, you definitely need a strong sense of what JS code you'll get out the other end.
I'd recommend Reginald Braithwaite's Javascript Allonge as an overview of JS semantics - the material on scopes and environments is very useful, given that JS behaviour on that score is ... idiosyncratic. https://leanpub.com/javascript-allonge/read
I can't always tell what's a joke, does he actually believe people would write software to compile to ASM instead of javascript because there are a few WTFs on js's "hashmaps." Much likely a newer version will come out before 2035? Or was that a joke?
I also feel like poking fun at "yavascript" at a python conference is cheap and plays to an audience's basest desires.
Really I see a mixture of the following: - Predictions about the future, some of which are just cleary jokes (e.g. 5 year war) - Insulting javascript preferring clojure - Talking about weird shit you could, but never would do with ASM js - Talking about a library that allegedly runs native code 4% faster in some benchmarks, with a simplistic explanation about overhead from ring0 to ring3 overhead.
I mean, instead of machine code "binaries", don't we now have asm blobs instead? What happens when I need to debug some opaque asm blob that I don't have the source to? Wouldn't I use something not so unlike gdb?
Or what happens when one asm blob wants to reuse code from another asm blob -- won't there have to be something fairly analogous to a linker to match them up and put names from both into the VM's namespace?
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Guy has good vim skills for sure.
http://benchmarksgame.alioth.debian.org/u32/compare.php?lang...
So there'd be some work to do. You could also compile the code, but complete C compilers are not fast, in browser terms.
Gary Bernhardt (rightly) says that JavaScript is shit (with some other insights).
HN comments tl;dr:
50%: "Waahhh, JavaScript is awesome and Node.js is wonderful, shut up Gary Bernhardt."
25%: Smug twats talking about how they're too busy changing the world with JavaScript to even bother to comment.
25%: Pedants and know-it-alls having sub-debates within sub-debates.
Pretty standard turnout. See you tomorrow.
This talk has convinced me that their next step will be attempting to reinvent computer engineering itself.
It's a pretty cool time to be alive.