Spot Your White Caml
Make Yourself Happy  in OCaml Projects
BTW J. Furuse aka CamlSpotter 15 years of OCaml programming 3 years of Functional Quants
Scenario You have jumped into an OCaml Project.
Congrats : Your Choice was Correct! OCaml is a good to get your work done: <ul><li>Type-safe
Enough Stable
Reasonably fast
Very simple </li></ul><ul><li>Readable
Scalable
Strong abstraction
Multi-paradigm </li></ul>
Typical Day 1 : Welcome! <ul><li>Nice and Kind Colleagues
New Cool Office
Good Machine
Even A Welcome Party! </li></ul>
Typical Day 2 : Real Job Starts
Typical Day 2 : Real Job Starts Overwhelmed type 'a desc = { position : Postion.t; value : 'a }  let rec typecheck env = f...
Typical Day 100
Typical Day 100 Still being Overwhelmed... type 'a desc = { position : Postion.t; value : 'a }  let rec typecheck env = fu...
Why <ul><li>You feel yourself Dumb ?
Seniors look Smarter than you ? </li></ul>You Senior
Answer : Curves Learning vs Code Growth  Time LoC Seniors
Answer : Curves Learning vs Code Growth  Time LoC Eternal Rookies Seniors
Improve Your Learning Curve How to <ul><li>Read the Code
Write Good Code
Ask Questions
Minimize Reading Effort </li></ul>
Read .mli First <ul><li>Read interfaces (=.mli) first
Skip implementations (=.ml) if possible </li></ul>
Write Good .mli Good for Yourself and the Others <ul><li>Hide implementation details
Show the things the users should care
With GOOD and SHORT comments
Let TYPES tell details of functions
ocamlc -i gives a good start point </li></ul>
Do NOT Guess .mli <ul>No GOOD .mli found ? <li>Do NOT waste time to guess interfaces
Ask the Authors write them </li></ul>Write them, or I get Home. Not something automatically created.
Do NOT Ask Silly Questions <ul>In OJT, your job is asking QUESTIONS, wisely. </ul>Where is it? In foo/bar.ml  Where is thi...
Ask Good Questions <ul><li>Read code to get HOW
Then Ask WHY, which the Code does NOT tell you </li></ul>Why this data type is  designed like this?  Some combinations nev...
Still NOT ENOUGH <ul><li>How to Read, Ask, and Write are important.
But  NOT the most Critical! </li></ul>
Where is Your White ?
80% of Your Energy is for Searching Where is the definition of this and that ? What the type of this ?
Syntax Hilighting It  improves   Local Vicinity  of  your Code. <ul><li>caml-mode.el  (with OCaml)
tuareg-mode.el  (1.45.6-2 / 1.46.2 / (2.0.1))
{syntax,ftplugin,indent}/ocaml.vim (2010 Aug 07) </li></ul>
Manual Search It NEVER Scales. You are warned. Names are defined <ul><li>above in the file
in Pervasives
in file system (include path)
in opened modules
Upcoming SlideShare
Loading in...5
×

Um2010

2,745

Published on

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,745
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Um2010

  1. 1. Spot Your White Caml
  2. 2. Make Yourself Happy in OCaml Projects
  3. 3. BTW J. Furuse aka CamlSpotter 15 years of OCaml programming 3 years of Functional Quants
  4. 4. Scenario You have jumped into an OCaml Project.
  5. 5. Congrats : Your Choice was Correct! OCaml is a good to get your work done: <ul><li>Type-safe
  6. 6. Enough Stable
  7. 7. Reasonably fast
  8. 8. Very simple </li></ul><ul><li>Readable
  9. 9. Scalable
  10. 10. Strong abstraction
  11. 11. Multi-paradigm </li></ul>
  12. 12. Typical Day 1 : Welcome! <ul><li>Nice and Kind Colleagues
  13. 13. New Cool Office
  14. 14. Good Machine
  15. 15. Even A Welcome Party! </li></ul>
  16. 16. Typical Day 2 : Real Job Starts
  17. 17. Typical Day 2 : Real Job Starts Overwhelmed type 'a desc = { position : Postion.t; value : 'a } let rec typecheck env = function Exp_int n -> open Utils open Sourceloc open Spot module Kind = struct include Kind let to_string = function Value -> &quot;Value&quot; let escaped pred s = let b = Buffer.create (String.length s) in String.iter (fun c -> if pred c then Buffer.add_char b 'apos;; module Make (M : Basic) : S with type 'a monad = 'a M.t = struct let bind = M.bind type error = E2BIG | EACCES | EAGAIN | EBADF let cflag_of_int = function | 0x0001 -> `CASELESS | 0x0002 -> `MULTILINE | 0x0004 -> `DOTALL | 0x0008 -> `EXTENDED class ['a] gobject_signals obj = object val obj : 'a obj = obj val after = false method after = {< after = true >} method private connect : 'b. ('a,'b) GtkSignal.t -> callback:'b -> _ =
  18. 18. Typical Day 100
  19. 19. Typical Day 100 Still being Overwhelmed... type 'a desc = { position : Postion.t; value : 'a } let rec typecheck env = function Exp_int n -> open Utils open Sourceloc open Spot module Kind = struct include Kind let to_string = function Value -> &quot;Value&quot; let escaped pred s = let b = Buffer.create (String.length s) in String.iter (fun c -> if pred c then Buffer.add_char b 'apos;; module Make (M : Basic) : S with type 'a monad = 'a M.t = struct let bind = M.bind type error = E2BIG | EACCES | EAGAIN | EBADF let cflag_of_int = function | 0x0001 -> `CASELESS | 0x0002 -> `MULTILINE | 0x0004 -> `DOTALL | 0x0008 -> `EXTENDED class ['a] gobject_signals obj = object val obj : 'a obj = obj val after = false method after = {< after = true >} method private connect : 'b. ('a,'b) GtkSignal.t -> callback:'b -> _ =
  20. 20. Why <ul><li>You feel yourself Dumb ?
  21. 21. Seniors look Smarter than you ? </li></ul>You Senior
  22. 22. Answer : Curves Learning vs Code Growth Time LoC Seniors
  23. 23. Answer : Curves Learning vs Code Growth Time LoC Eternal Rookies Seniors
  24. 24. Improve Your Learning Curve How to <ul><li>Read the Code
  25. 25. Write Good Code
  26. 26. Ask Questions
  27. 27. Minimize Reading Effort </li></ul>
  28. 28. Read .mli First <ul><li>Read interfaces (=.mli) first
  29. 29. Skip implementations (=.ml) if possible </li></ul>
  30. 30. Write Good .mli Good for Yourself and the Others <ul><li>Hide implementation details
  31. 31. Show the things the users should care
  32. 32. With GOOD and SHORT comments
  33. 33. Let TYPES tell details of functions
  34. 34. ocamlc -i gives a good start point </li></ul>
  35. 35. Do NOT Guess .mli <ul>No GOOD .mli found ? <li>Do NOT waste time to guess interfaces
  36. 36. Ask the Authors write them </li></ul>Write them, or I get Home. Not something automatically created.
  37. 37. Do NOT Ask Silly Questions <ul>In OJT, your job is asking QUESTIONS, wisely. </ul>Where is it? In foo/bar.ml Where is this? In bar/boo.mli What is that? Uh, oh...
  38. 38. Ask Good Questions <ul><li>Read code to get HOW
  39. 39. Then Ask WHY, which the Code does NOT tell you </li></ul>Why this data type is designed like this? Some combinations never appear in the algorithm. It could be simpler. Oh, this new guy is Strong...
  40. 40. Still NOT ENOUGH <ul><li>How to Read, Ask, and Write are important.
  41. 41. But NOT the most Critical! </li></ul>
  42. 42. Where is Your White ?
  43. 43. 80% of Your Energy is for Searching Where is the definition of this and that ? What the type of this ?
  44. 44. Syntax Hilighting It improves Local Vicinity of your Code. <ul><li>caml-mode.el (with OCaml)
  45. 45. tuareg-mode.el (1.45.6-2 / 1.46.2 / (2.0.1))
  46. 46. {syntax,ftplugin,indent}/ocaml.vim (2010 Aug 07) </li></ul>
  47. 47. Manual Search It NEVER Scales. You are warned. Names are defined <ul><li>above in the file
  48. 48. in Pervasives
  49. 49. in file system (include path)
  50. 50. in opened modules
  51. 51. , or in aliased modules </li></ul>
  52. 52. Grep OCaml syntax Verbosity helps, but not always... grep iter *.ml grep 'let iter' *.ml grep -n '(let|let rec|and) iter' *.ml find .. -type f -name '*.ml' | xargs grep -n '(let|let rec|and) iter'
  53. 53. Tags Tags do NOT help you lot in OCaml Just a clever Grep. <ul><li>Otags for OCaml 3.11.1 (http://askra.de/otags/)
  54. 54. Others (OCamlOTags, ocamlglobaltags, ...) </li></ul>
  55. 55. IGNORE your Seniors <ul><li>I am always OK with Grep
  56. 56. Manual Search is pain but also Educational
  57. 57. Don't worry. You will be soon Used to the code </li></ul>Your situation is Worse than them. You need something Different.
  58. 58. Use the Compiler Directed Tools Compiler knows HOW things are coded. Source Obj Useful Info
  59. 59. Types of Locals as Documents .annot by ocamlc -annot <ul><li>Types of local values and sub-expressions
  60. 60. caml-types.el (caml-mode)
  61. 61. ocaml.vim </li></ul>.annot
  62. 62. <ul>Search by Names </ul>CmiGrep .cmi search (= only for exported) <ul><li>cmigrep -v iter '*'
  63. 63. cmigrep -I .. -v iter '*' </li></ul>A bit tricky... <ul><li>cmigrep -v 'iter' '*.*' </li></ul>.cmi
  64. 64. <ul>Search by Type Algebra </ul>OCamlBrowser / OCaml API Search Graphical / Web search of .cmi <ul><li>Good for Writing
  65. 65. OK for Reading </li></ul>.cmi
  66. 66. Search by Position I want to know about .... THIS! It was impossible; OCaml compiler threw positions away. This This
  67. 67. OCamlSpotter Specialized to find your WHITE .spot / .spit files <ul><li>Def locations (including locals)
  68. 68. Use locations
  69. 69. Module abstractions
  70. 70. Types
  71. 71. Compilation flags </li></ul>.spot, .spit
  72. 72. Extended ocamlc / ocamlopt -annot ocamlc -annot creates .spot files <ul><li>.spot for .ml
  73. 73. .spit for .mli </li></ul>.spot, .spit
  74. 74. ocamlspot CLI % ocamlspot <file path>:<position> Type: <type> XType: <xtype> Use: <kind>, <xpath> Tree: <start pos>:<end pos> In_module: <module name> Spot: <file path>:<start pos>:<end pos>
  75. 75. OCamlSpotter Editor Integration Wrapper for OCamlSpotter CLI <ul><li>ocamlspot.el for Emacs
  76. 76. ocamlspot.vim for Vim (just done. Plz extend it.) </li></ul>
  77. 77. OCamlSpotter in Compiler Pros <ul><li>Dump during Type Checking
  78. 78. Compiler version dependent
  79. 79. No information gathering overhead
  80. 80. Just add -annot </li></ul>
  81. 81. OCamlSpotter in Compiler Cons <ul><li>You need the Patch
  82. 82. Patched compiler may be Buggy. </li><ul><li>Patched compiler produces the same objs for ocamlc
  83. 83. ocamlspot can be used for .spot creation tool </li></ul></ul>
  84. 84. Use OCamlSpotter. Be Creative. ½ Searching = x3 Creative Before After
  85. 85. Use OCamlSpotter. Be Creative. Trust me. It's worth Patching. <ul><li>Good even for One Man Army
  86. 86. No equivalent </li><ul><li>OCamlWizard (Stopped at 3.10.2) </li></ul></ul>OcamlSpotter is available for 3.12.0 : <ul><li>http://jun.furuse.info/hacks/ocamlspotter
  87. 87. hg clone http://hg.ocamlcore.org/cgi-bin/hgwebdir.cgi/ocamlspotter/ocamlspotter/ </li></ul>
  88. 88. Technical Details of OCamlSpotter <ul>Less interesting things. </ul>
  89. 89. Spot is a program It is not a simple name-position record. <ul><li>Late binding
  90. 90. Compute all at compile time is costy & impos. </li></ul><ul><li>Module as name-position record
  91. 91. Module alias as let
  92. 92. Functor as function
  93. 93. Recursion for Recursive modules
  94. 94. Laziness for efficiency </li></ul>
  95. 95. Spot is a program ocamlspot --dump-top
  96. 96. Late Binding
  97. 97. Late Binding New dependency between .spots, which is not known to the build system.
  98. 98. OCamlSpotter API Future Possibilities <ul><li>Finding “Where USED ?” not “Where defined ?”
  99. 99. Code refactoring
  100. 100. Jump to Document instead of Definition
  101. 101. Auto-recompilation independent from build sys
  102. 102. Co-op with other tools (.spot knows -I flags) </li></ul>
  103. 103. Other Tools for OCaml Reading <ul><li>Cameleon2 : Nice GUI tools.... But, GUI!?!?!
  104. 104. OCamlDoc depgraphs (in OCaml)
  105. 105. Oug
  106. 106. Some Eclipse plug-ins (Useful???) </li></ul>
  107. 107. OCamlSpotter is Proven <ul><li>It earns 1$ for each search!
  108. 108. When is it integrated into the official OCaml ?
  109. 109. I cannot live without it!! </li></ul>
  110. 110. And Now... I jumped into a Haskell Project. Same story begins.
  111. 111. Make Yourself Happy in OCaml Projects
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×