{"id":22447613,"url":"https://github.com/mattms/wd42_coffeescript_talk","last_synced_at":"2025-03-27T11:27:20.691Z","repository":{"id":145868830,"uuid":"43413002","full_name":"MattMS/WD42_CoffeeScript_talk","owner":"MattMS","description":"CoffeeScript talk at Web Developer 42 on 2015-09-30.","archived":false,"fork":false,"pushed_at":"2015-09-30T05:28:47.000Z","size":1604,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"gh-pages","last_synced_at":"2025-02-01T16:11:20.338Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://mattms.github.io/WD42_CoffeeScript_talk/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MattMS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-30T05:04:54.000Z","updated_at":"2015-09-30T05:53:38.000Z","dependencies_parsed_at":"2023-04-13T23:40:28.340Z","dependency_job_id":null,"html_url":"https://github.com/MattMS/WD42_CoffeeScript_talk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattMS%2FWD42_CoffeeScript_talk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattMS%2FWD42_CoffeeScript_talk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattMS%2FWD42_CoffeeScript_talk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MattMS%2FWD42_CoffeeScript_talk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MattMS","download_url":"https://codeload.github.com/MattMS/WD42_CoffeeScript_talk/tar.gz/refs/heads/gh-pages","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245835078,"owners_count":20680141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T04:17:52.988Z","updated_at":"2025-03-27T11:27:20.671Z","avatar_url":"https://github.com/MattMS.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoffeeScript\n\nStill worth a look\n\n\n\n## Me?\n\n- Matt McKellar-Spence\n\n- GitHub: [MattMS](https://github.com/MattMS/)\n\n- Twitter: [MattMS](https://twitter.com/MattMS)\n\n\n\n## Such magic?\n\n- [reveal.js](https://github.com/hakimel/reveal.js)\n\n- [Jade](http://jade-lang.com/)\n\n- [Stylus](https://learnboost.github.io/stylus/)\n\n\n\n...and a little [CoffeeScript](http://coffeescript.org/) :)\n\n\n\n## First\n\n- ES(6|7|201[56]) look (mostly) good.\n\n- I like CoffeeScript syntax, you may not.\n\n- Same idea as Sass, Less, Jade, etc.\n\n\n## Hard and fast\n\nBut totally worth learning.\n\n- Vim\n\n- Regular expressions\n\n\n\n## And now for something completely different...\n\n\n\n## Python!\n\n[python.org](https://www.python.org/)\n\nFirst step to liking CoffeeScript.\n\n\n\n## Pretty basic\n\n```python\nhopefully_a_name = input('Who be ye? ')\n\nprint('Yo', hopefully_a_name)\n```\n\n\n\n### Fully functional\n\n```python\ndef but_is_it_awesome(questionable_item):\n\tif questionable_item in ['CoffeeScript', 'Python']:\n\t\treturn 'yeah'\n\n\telif questionable_item != 'Java':\n\t\treturn 'maybe'\n\n\telse:\n\t\treturn 'nah'\n\nprint(but_is_it_awesome('Lua'))\n```\n\n\n### Stay classy\n\n```python\nclass MeatSack:\n\n\tdef __init__(self, name):\n\t\tself.name = name\n\n\tdef talk(self):\n\t\treturn 'Me {}'.format(self.name)\n\nmeaty = MeatSack('T-Bag')\n\nprint(meaty.talk())\n```\n\n\n### Reusing concepts\n\n```python\n10 in [2, 6, 12, 16, 60]\n\n'nah' in 'banana'\n\n'base' in {'base': 0xc, 'value': 'a'}\n```\n\n\n\n## Why Python?\n\n- Syntax is well-considered.\n\n- You were going to indent it anyway, right?\n\n\n\n## What about YAML!\n\n[yaml.org](http://yaml.org/)\n\n(nearly coffee-time)\n\n\n\n## Orderly but approachable\n\n```yaml\n- date: 2015-09-30\n  place: Typewriter Factory\n  task: Talk about CoffeeScript.\n\n- date: 2015-10-01\n  place: Antarctic Division\n  task: Last day shenanigans.\n\n- date: 2015-10-02\n  place: The Winston\n  task: Eat ribs and drink beer.\n```\n\n\n\n## Why YAML?\n\n- Safe for our puny human brains.\n\n- Only write what you need.\n\n\n### ...but\n\n- Better for configuration than transport.\n\n- Use `safe_load`.\n\n\n\n## CoffeeScript!\n\nYay?\n\n\n\n## Must know JavaScript\n\n- CoffeeScript is JavaScript.\n\n- Most documentation/libraries are in JavaScript.\n\n- You will probably debug the JavaScript with browser tools.\n\n\n\n## A simple function\n\n```coffee\ngreet = (name)-\u003e\n\t'Hello ' + name\n```\n\nFree returns!\n\n\n\n## Do you really like brackets?\n\n```javascript\nconsole.log(greet('World'))\n```\n\nor\n\n```coffee\nconsole.log greet 'World'\n```\n\n(Sorry Lisp folk)\n\n\nThink of the command line.\n\n`git add main.coffee`\n\n\nWell, think in reverse (if you must).\n\n`'World' \u003e greet \u003e console.log`\n\n\n\n### Yes, long lines are confusing\n\n```coffee\nwha = do_something with_this + this_too and_me / wait_what\n```\n\nwhich is apparently\n\n```javascript\nwha = do_something(with_this + this_too(and_me / wait_what))\n```\n\nSo instead...\n\n\n\n### Moar lines!\n\n```coffee\nchance_of_distracting_shopkeep = attractiveness * magic_skillz\n\nshopkeep_attention = 1 / shopkeep_hours_on_shift\n\npizza_slices_acquired =\n\tif chance_of_distracting_shopkeep \u003e shopkeep_attention\n\t\tall_the_slices\n\telse\n\t\tmoney_in_pocket / cost_of_pizza_slice\n```\n\n\n\n## Keep it simple\n\n- Everything is an expression (returns something).\n\n- One liners are fun to write, but to read?\n\n\n\n## Functions and arguments\n\n```coffee\npath = require 'path'\n\nparts = path.parse path.join site, folder, file\n```\n\ngives\n\n```javascript\nvar path = require('path')\n\nvar parts = path.parse(path.join(site, folder, file))\n```\n\n\nAlternatively\n\n```coffee\npath = require 'path'\n\nparts = path.parse path.join [\n\tsite\n\tfolder\n\tfile\n]...\n```\n\n\n\n## Literate CoffeeScript\n\nI love this stuff.\n\n\n\n### Have you ever\n\n- Separated your code with fancy comment lines?\n\n- Run out of space with indented comments?\n\n- Made up your own comment styles?\n\n\n\n### Describe, then code\n\n```coffee\n# My cool server\n\n\thttp = require 'http'\n\n\tserver = http.createServer (req, res)-\u003e\n\t\tres.writeHead 200, 'Content-Type': 'application/json'\n\t\tres.end JSON.stringify ok: true\n\n## Start server\n\nStart the server on [port 1337](http://localhost:1337).\n\n\tserver.listen 1337\n```\n\n\n\n### It's just Markdown\n\n- Break up sections with headings.\n\n- All comments get the same width.\n\n- Looks cool on GitHub.\n\n- [Readme Driven Development](https://tom.preston-werner.com/2010/08/23/readme-driven-development.html)\n\n\n\n## The big stuff\n\n\n\n### Big comments\n\n```coffee\n###\nSo much space to fill with (almost) whatever you like.\n\nLiterate CoffeeScript is nicer though.\n\nYou only get 2 Markdown heading levels with this.\n###\n```\n\n\n\n### Big strings\n\n```coffee\nreaction = 'Woah!'\n\nall_the_stuff = \"\"\"\n#{reaction}\n\nI \u003cem\u003estrongly\u003c/em\u003e dislike\n\u003cabbr title=\"Hypertext Markup Language\"\u003eHTML\u003c/abbr\u003e,\nbut how awesome is this!\n\"\"\"\n```\n\n\n\n### Big regexes\n\n```coffee\nOPERATOR = /// ^ (\n?: [-=]\u003e            # function\n| [-+*/%\u003c\u003e\u0026|^!?=]=  # compound assign / compare\n| \u003e\u003e\u003e=?             # zero-fill right shift\n| ([-+:])\\1         # doubles\n| ([\u0026|\u003c\u003e])\\2=?      # logic / shift\n| \\?\\.              # soak access\n| \\.{2,3}           # range or splat\n///\n```\n\nor\n\n```javascript\nOPERATOR = /^(?:[-=]\u003e|[-+*\\/%\u003c\u003e\u0026|^!?=]=|\u003e\u003e\u003e=?|([-+:])\\1|([\u0026|\u003c\u003e])\\2=?|\\?\\.|\\.{2,3})/\n```\n\n\n\n## Fancy functions\n\n\n\n### jQuery\n\n```coffee\n$ -\u003e\n\tconsole.log 'And so it begins.'\n```\n\ngives\n\n```javascript\n$(function () {\n\tconsole.log('And so it begins.')\n})\n```\n\n\n\n### Chaining functions\n\n```coffee\n$ '#much_win_button'\n\n.on 'click', -\u003e\n\tevil_corp_bank.receive user_bank.transfer_all()\n\n.text 'You won a goat!'\n```\n\n\n\n### Chaining arguments\n\n```coffee\nid = setTimeout -\u003e\n\tconsole.log 'Done!'\n\n, 6000\n```\n\n\n\n### Functions expecting objects\n\n```coffee\n$ '#lil_boxy_thing'\n\n.css\n\theight: '72px'\n\twidth: '72px'\n```\n\n\n\n## Stay safe\n\n\n\n### Equality\n\nAlways `===` and `!==`\n\n```coffee\non == true\nyes is on\n\noff != true\nno inst on\n```\n\n\n\n### Existence\n\n```javascript\nif person?\n\tperson.say_hi()\n```\n\ngives\n\n```coffee\nif (typeof person !== \"undefined\" \u0026\u0026 person !== null) {\n\tperson.say_hi()\n}\n```\n\n\n\n## CSON anyone?\n\n```coffee\n[\n\ttitle: 'Fight Club'\n\tyear: 1999\n,\n\ttitle: 'The Fifth Element'\n\tyear: 1997\n,\n\ttitle: 'The Matrix'\n\tyear: 1999\n]\n```\n\nRemember YAML.\n\n\n\n## Inspired ES/JS\n\n- [Classes with inheritance](http://coffeescript.org/#classes)\n\n- [Default values for functions](http://coffeescript.org/#literals)\n\n- [Destructuring items](http://coffeescript.org/#destructuring)\n\n- [Generator functions (yield)](http://coffeescript.org/#fat-arrow)\n\n- [List comprehensions/iterators](http://coffeescript.org/#loops)\n\n\n\n## LiveScript\n\n[livescript.net](https://livescript.net/)\n\n- \"Indirect descendant of CoffeeScript\"\n\n- Too many symbols for me, but no hating!\n\n\n\n## Why I still use CoffeeScript\n\n- Markdown for comments.\n\n- Reduces noisy characters.\n\n- Encourages me to write simpler code.\n\n- Fits my Jade/Stylus/Python style.\n\n\n\n## Want more?\n\n[coffeescript.org](http://coffeescript.org/) is totally worth looking over.\n\n\n\n## Thanks!\n\n@MattMS\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattms%2Fwd42_coffeescript_talk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattms%2Fwd42_coffeescript_talk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattms%2Fwd42_coffeescript_talk/lists"}