Python To LiveScript @PythonCon APAC 2014

  • 664 views
Uploaded on

introduction of LiveScript for Python programmer.

introduction of LiveScript for Python programmer.

More in: Technology , Sports
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
664
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
8
Comments
0
Likes
12

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Python to LiveScript @hychen for PyCon APAC 2014
  • 2. Star to learn LiveScript after join a g0v.tw, a open civic hacking community.
  • 3. 劣即 是夯JavaScript everywhere
  • 4. LiveScript • concise syntax. • say bye to bad parts of JavaScript. • many improvements for OOP. • many features of FP. • http://livescript.net/ • go there and try compiling
  • 5. JS LS use -> to replace anonymous function
  • 6. LS LS use bound call to remove `that = this`
  • 7. LS LS @ = this
  • 8. LS LS func! === func()
  • 9. LS LS ‘foo’ === foo
  • 10. LS LS use back call
  • 11. LS LS use bound back call
  • 12. JS LS
  • 13. Package Manager you can use any JavaScript modules in LiveScript. NPM PyPi
  • 14. Import Import os ! require! os PY LS PY LS from os import path ! path = require os .path
  • 15. REPL user@host: python Python 2.7.6 (default, Nov 17 2013, 16:03:54) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> user@host: lsc LiveScript 1.2.0 - use 'lsc --help' for more information ls> Python LiveScript
  • 16. Inspect attributes of an object Object.keys dir >>> dir(path) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_joinrealpath', '_unicode', '_varprog', 'abspath', 'altsep', 'basename', 'commonprefix', 'curdir', 'defpath', 'devnull', 'dirname', 'exists', 'expanduser', 'expandvars', 'extsep', 'genericpath', 'getatime', 'getctime', 'getmtime', 'getsize', 'isabs', 'isdir', 'isfile', 'islink', ‘ismount', …. ls> Object.keys path [ 'resolve', 'normalize', 'join','relative','sep','delimiter', 'dirname', 'basename','extname','exists', 'existsSync', '_makeLong' ]
  • 17. Help PY LS X pydoc
  • 18. Object Model Please check the slide “Python New-Style Objec v.s. JavaScript prototype, COSCUP 2012” The basic object model of LiveScript should be the same as JavaScript.
  • 19. List construction [1, 2, [3, 4], [5,6]]PY & LS 1 spaceLS
  • 20. List Property Access [1, 2, [3,4]][0]PY & LS LS LS [1, 2, [3,4]].0 [1, 2, [3,4]].2.0
  • 21. Dict construction PY & LS LS quotes of the keywords are optional use object to simulate Python dict in LiveScript.
  • 22. Dict construction(cont.) PY & LS LS another better represent way use object to simulate Python dict in LiveScript.
  • 23. Dict Property Access {‘a’:1, ‘b’}[‘a’]PY & LS LS {‘a’:1, ‘b’}.a
  • 24. unpacking function arguments LS PY
  • 25. unpacking function keyword argument LS PY
  • 26. packing function arguments PY LS
  • 27. packing function keyword arguments PY LS
  • 28. destructing assignment PY & LS LS
  • 29. destructing assignment (cont.) LS Python does not support.
  • 30. destructing function arguments LS Python does not support.
  • 31. List Comprehension PY LS result: [‘a1', 'a2', 'b1', 'b2']
  • 32. Dict Comprehension PY LS result: {‘a': 2, 'b': 4}
  • 33. File Reading ⼤大家 ! 好 ! 我是 ! [Name] file: memo.txt PY
  • 34. File Reading(cont.) callback 2 callback 1 LS
  • 35. Backcall callback1 callback2 LS
  • 36. Backcall(cont.) LS LS
  • 37. Class PY
  • 38. Class(cont.) LS … means arguments of current function
  • 39. Python Super • super(type, obj) -> bound super object; requires isinstance(obj, type)
  • 40. LiveScript Super • is a reference to the appropriate function. • If you want to call it with all arguments, use super … • … implies calling it with the arguments of the current function.
  • 41. LiveScript Mixing You can extend only 1 parent but can implement many interface.
  • 42. Many more… LS Curried Function
  • 43. Many more… LS
  • 44. Conclusion • change mind to code with callbacks. • functional style programming with prelude.ls • use class rarely after use LiveScript. • LiveScript does not have debugger now, testing is highly important! • You may need to check compiled JavaScript even your LiveScript code are correctly rarely.
  • 45. Questions?