3 ms·
> var game_piece, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _n; I dont see why he didn't use do "var game_piece , _i , len;" He doesn'
by eekfuh 15y ago
> var game_piece, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _n;
I dont see why he didn't use do "var game_piece , _i , len;"
He doesn't need multiple i's nor lengths. The JS example is just a very poor example of coding. (in fact he could of just simplified it further down by having one loop and a variable to the method, to be executed on those pieces.)
CoffeeScript is very nice, but I want to see examples of why to use it that will actually save me time. Compared to the examples, there are better ways to code and tons of easy ways to do OO with certain frameworks/toolkits.
- reaktivo 15y agovar keydown_action_map = { 37: 'pan_left', 38: 'pan_up', 39: 'pan_right', 40: 'pan_down', 189: 'zoom_out', 187: 'zoom_in' } document.addEvent('keydown', function(event) { var action = keydown_action_map[event.keyCode]; game_pieces.each(game_piece[action], game_piece); });
- Klonoar 15y agoI came here to post just this. While I like CS, JS isn't this horrid beast people keep making it out to be; often the solutions can be incredibly simple, it's just a matter of thinking about it.
- rimantas 15y agoThis can be written like this too: keydown_action_map = 37: 'pan_left' 38: 'pan_up' 39: 'pan_right' 40: 'pan_down' 189: 'zoom_out' 187: 'zoom_in' document.addEvent 'keydown', (event) -> action = keydown_action_map[event.keyCode] game_pieces.each game_piece[action], game_piece If you can write terse code in JS you can write it even more terse way in CS.
- masklinn 15y agoWhere "more terse" means "removing a useful keyword and replacing parens by spaces". Not exactly impressive (and coffeescript's symbolless maps read horribly badly, imo).
- rimantas 15y agoWhich keyword is useful? Var? CS will put it back at compile time, don't worry. And it will do it in more consistent manner than many coders will manually. I have no problems with symbolless maps, and CS will save your ass from being bitten by IE because of stray comma.
- thezilch 15y agoI protect my ass with VIM -- any "IDE" likely has an equivalent. au BufWrite *.js mark` | silent!%s/,\(\_s*[}\]]\)/\1/g | norm``
- masklinn 15y ago> Which keyword is useful? Var? Yes. > CS will put it back at compile time, don't worry. May I ask why you're assuming I'm a moron, exactly? > And it will do it in more consistent manner than many coders will manually. I don't know who your coders are, but you should fire them. > CS will save your ass from being bitten by IE because of stray comma. Yep, confirmed, and you should probably fire yourself as well.
- deleted 15y ago[deleted]
- masklinn 15y ago> The JS example is just a very poor example of coding. That's because it's the output of the coffeescript compiler, it's not "actual" javascript code.
- bcrescimanno 15y agoIt makes the article very misleading. Yes, CS looks great next to garbage output--but there are about a dozen ways to accomplish these tasks in JS and most are almost as concise as the CS examples. Honestly, if that type of output is why people think Javascript is "hard" or "convoluted," then maybe CS is right for them. As with any tool, a proper knowledge of its use is required and anyone who would write code like that clearly doesn't really know their tool.