Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why this?

// Shorten some names. var math = Math;



Capital letters are bigger, and therefore take up more space.


No.


For minification, as someone else said. I originally wrote this for a JS1K competition some years ago, so it's not geared towards readability, but towards small code size.

I had a really, really ugly trick that saved me a couple of bytes which I removed before posting to HN. I figured out I was using canvas.getImageData() and canvas.putImageData(). So I did this: var tID = "tImageDatA"; canvas["ge"+tID](); canvas["pu"+tID"](); You can see that in the original source: http://gabrielgambetta.com/tiny_raytracer_full.js

Not my proudest hack :D


I just looked at this childhood drawing of yours: http://www.gabrielgambetta.com/img/1986-listado.jpg

Is that BASIC CODE mixed in with bugs bunny??! Raytracer or no raytracer, this is exceedingly cool.


Yes, that is (my 5 year old idea of) ZX Spectrum Basic. It follows the format of the listings published in Microhobby (http://microhobby.speccy.cz/mhf/031/MH031_08.jpg - in particular, look at the "NOTAS GRAFICAS" sidebar). I grew up with that :) My programming has improved, my drawing abilities not so much.


I remember typing that listing, almost thirty years ago. I owe a lot of what my life is now to Microhobby.


Microhobby FTW. I have the exact same feeling, but more generally about the Spectrum.


Me too but more about the BBC B and the Amstrad CPC 464!

BBC Basic was amazing in hindsight.

Bugs Boni !


Because when it's run through the Google closure compiler it becomes

    E=Math,F=E.sqrt,G=E.max


That is before minifying. The variable name "math" was chosen for readibility in the non-minified version. The variable math can be renamed during the minifying process to a short identifier, in this case "E". Since the Math object is used quite a lot, it is worth the assignment to rename it.


Closure compiler will rename the math variable.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: