Dec
18
2015

Minesweeper and interviewing

Today I've read this article on interviewing and I decided to take the challenge:

You have one hour to implement as much of Minesweeper as possible. I've provided a JSBin for you though you're free to use whatever development tools/libraries/frameworks you're most comfortable with. You're allowed to use whatever internet resources you need, excluding plagiarism. I'll be available to answer any questions you may have. You're not expected to finish! In fact, no one ever has. Do your best and we'll chat about how things went afterward.

[ read more... ]


Oct
4
2014

Multiple inheritance and multiple dispatch in JavaScript

Multiple inheritance and multiple dispatch are core features in CLOS. The standard JavaScript object system supports neither, but they can be implemented. I thought I'd write this article, along with working code, for the JavaScript fellows who don't know the concept. Maybe someone smarter than me will come up with an efficient implementation.

[ read more... ]


Jun
8
2014

How to implement a programming language

I wrote a tutorial on how to implement a programming language in JavaScript. It got quite involved, and it took embarrassingly long to write. I wanted to write only about parsing, after a discussion with my dad about this problem; but once I had a parser I thought I'd add in a simple interpreter and once that was in place, I thought I'd turn it into continuation-passing style to show how we can workaround the lack of tail call optimization in JavaScript. But this opened the opportunity to talk about continuations. And of course, it was too slow so I thought I'd discuss compiling as well.

Long story short: I describe how to implement a non-trivial programming language. We get to a language that has decent performance, can interface easily with JavaScript and can offer first class continuations. To hell with the callback hell!

Read on and let me know what you think.


Jan
22
2014

Find all expressions that evaluate to some value

Some friends came to visit last weekend, and we got to talk about the following problem, which seems to have made the news headlines (it was given at a math contest for ten year olds and apparently many math teachers couldn't figure out a solution):

We have numbers 1, 3, 4 and 6. Create an expression using any elementary operators (+, -, *, /), containing only these numbers, exactly once each, such that the result is 24.

(if you'd like to try finding a solution, stop reading now because there's a spoiler here)

I felt the problem itself is inappropriate for 10 y.o. kids and irrelevant for a maths contest; but it seemed like a good programming exercise, so I told'em “while you're banging your heads to guess a solution, I'll go and write a program to give me all solutions.”

I implemented it in Scheme, because it requires backtracking and using continuations for this is a joy. But in this blog post I'll work out the solution in JavaScript.

[ read more... ]


Mar
20
2013

Using UglifyJS for code refactoring

Somebody asked me the following question:

I want to do AST transformations on my javascript files. Specifically, i want to take all throw "string" expressions and replace them with throw new Error("string") expressions.

The problem is I want to make no other changes to my source. I want to not change anything: no comments, no indentation, no whitespace, etc. I just want match certain AST subtrees (a throw node with a string node as a child) and replace them with something different.

I thought I'd write this blog post to show how.

[ read more... ]


Feb
27
2013

Livenode — Live-code your NodeJS application

I'm working on a NodeJS application for Kendo UI. If you've been following me for a while, you probably know that I'm not the biggest fan of NodeJS—however, it seems that for this project Node is the best option, so I actually pushed for it.

A small annoyance that I'm trying to “fix” is the requirement to restart the server all the time in order to test changes. After some years with Common Lisp, I know there are better ways to do development than restarting the program — so here's Livenode, a module that allows to “live-code” a NodeJS application.

[ read more... ]


Jan
11
2013

Enterprise tools

Enterprise tools take an idea which is essentially simple and beautiful, and place a mountain of mud over it: acronyms, nouns, APIs, XML (and XSLT, DTDs, SOAP!, WSDL!) and the list is endless. Such that you don't see the beauty anymore; you don't see it simple anymore. You then live in constant fear that everything has to be enormously complex, ungodly hideous, and you thank your Enterprise Tools Vendor, your new God, for providing you with an IDE that makes life bearable, completely losing sight of the fact that it's the Enterprise Bullshit itself which adds in the complexity. You're locked to your Vendor, and you're doomed to never see beauty again.


Nov
13
2012

Thoughts on CommonJS / RequireJS

This rant is to explain this tweet. The short version is, I think they introduce more problems than they solve. While I do admit there is a need to define packages in JavaScript, it should probably be addressed at language level. In this fabulous class, Gerald Jay Sussman says “I consider being able to return procedural values, and therefore to have first-class procedures in general, as being essential to good modular programming” and continues saying that first-class functions cover all modularity needs, including making package systems. That's certainly true, but no language I know, not even Scheme, relies solely on that for defining a module system. Except JavaScript.

[ read more... ]


Nov
8
2012

Should you switch to UglifyJS2?

Every now and then somebody asks me if UglifyJS v2 is ready for production use. I'd say it is, but it's hard to back that claim without a lot of users. Version 1 got some huge popularity boost after John Resig's twit about it and after jQuery switched to it. Thanks to being so popular, a lot of issues were identified and fixed. Something similar needs to happen to V2.

Here are some views on the status of V2 compared to V1 and other compressors.

[ read more... ]


Oct
16
2012

UglifyJS online demo

The UglifyJS2 API documentation pages are more or less complete. I also worked on an online demo which allows you to minify scripts from your browser; the intended use case is just to demonstrate features of UglifyJS like compressor/beautifier options and source maps. You can minify a script and click some token in the minified output and the editor will move to the original position of that token in the initial code. You can easily see all the warnings that UglifyJS dumps, and click them to go to the original location and fix them.

It's only tested with Chrome and Firefox. Should work with Safari too, but I'm pretty sure it won't work in Opera or IE. Try it out! If it doesn't appear to work and you visited this website recently, please clear the cache. If you have any comments or suggestions I'd love to know about it!


« Before 16 Oct 2012
Fork me on Github