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: Type-safe
Enough Stable
Reasonably fast
Very simple Readable
Scalable
Strong abstraction
Multi-paradigm
Typical Day 1 : Welcome! Nice and Kind Colleagues
New Cool Office
Good Machine
Even A Welcome Party!
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 = 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 '\\';  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 -> _ =
Typical Day 100
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 '\\';  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 -> _ =
Why You feel yourself Dumb ?
Seniors look Smarter than you ? 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 Read the Code
Write Good Code
Ask Questions
Minimize Reading Effort
Read .mli First Read interfaces (=.mli) first
Skip implementations (=.ml) if possible
Write Good .mli Good for Yourself and the Others 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
Do NOT Guess .mli No GOOD .mli found ? Do NOT waste time to guess interfaces
Ask the Authors write them Write them, or I get Home. Not something automatically created.
Do NOT Ask Silly Questions In OJT, your job is asking QUESTIONS, wisely. Where is it? In foo/bar.ml  Where is this? In bar/boo.mli  What is that? Uh, oh...
Ask Good Questions Read code to get HOW
Then Ask WHY, which the Code does NOT tell you 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...
Still NOT ENOUGH How to Read, Ask, and Write are important.
But  NOT the most Critical!
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. 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)
Manual Search It NEVER Scales. You are warned. Names are defined above in the file
in Pervasives
in file system (include path)
in opened modules

Um2010

  • 1.
  • 2.
    Make Yourself Happy in OCaml Projects
  • 3.
    BTW J. Furuseaka CamlSpotter 15 years of OCaml programming 3 years of Functional Quants
  • 4.
    Scenario You havejumped into an OCaml Project.
  • 5.
    Congrats : YourChoice was Correct! OCaml is a good to get your work done: Type-safe
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
    Typical Day 1: Welcome! Nice and Kind Colleagues
  • 13.
  • 14.
  • 15.
  • 16.
    Typical Day 2: Real Job Starts
  • 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 '\\'; 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.
  • 19.
    Typical Day 100Still 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 '\\'; 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.
    Why You feelyourself Dumb ?
  • 21.
    Seniors look Smarterthan you ? You Senior
  • 22.
    Answer : CurvesLearning vs Code Growth Time LoC Seniors
  • 23.
    Answer : CurvesLearning vs Code Growth Time LoC Eternal Rookies Seniors
  • 24.
    Improve Your LearningCurve How to Read the Code
  • 25.
  • 26.
  • 27.
  • 28.
    Read .mli FirstRead interfaces (=.mli) first
  • 29.
  • 30.
    Write Good .mliGood for Yourself and the Others Hide implementation details
  • 31.
    Show the thingsthe users should care
  • 32.
    With GOOD andSHORT comments
  • 33.
    Let TYPES telldetails of functions
  • 34.
    ocamlc -i givesa good start point
  • 35.
    Do NOT Guess.mli No GOOD .mli found ? Do NOT waste time to guess interfaces
  • 36.
    Ask the Authorswrite them Write them, or I get Home. Not something automatically created.
  • 37.
    Do NOT AskSilly Questions In OJT, your job is asking QUESTIONS, wisely. Where is it? In foo/bar.ml Where is this? In bar/boo.mli What is that? Uh, oh...
  • 38.
    Ask Good QuestionsRead code to get HOW
  • 39.
    Then Ask WHY,which the Code does NOT tell you 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.
    Still NOT ENOUGHHow to Read, Ask, and Write are important.
  • 41.
    But NOTthe most Critical!
  • 42.
  • 43.
    80% of YourEnergy is for Searching Where is the definition of this and that ? What the type of this ?
  • 44.
    Syntax Hilighting It improves Local Vicinity of your Code. caml-mode.el (with OCaml)
  • 45.
    tuareg-mode.el (1.45.6-2/ 1.46.2 / (2.0.1))
  • 46.
  • 47.
    Manual Search ItNEVER Scales. You are warned. Names are defined above in the file
  • 48.
  • 49.
    in file system(include path)
  • 50.