Loading ...
Sorry, an error occurred while loading the content.
 

Is it "poor taste" to include type information in function definitions?

Expand Messages
  • Grant Rettke
    Is it poor taste to include type information in function definitions? It seems like very nice documentation, but then again, maybe it is nicer rely on the
    Message 1 of 5 , Mar 31, 2010
      Is it "poor taste" to include type information in function definitions?

      It seems like very nice documentation, but then again, maybe it is
      nicer rely on the inferencing engine to reduce the amount of code?

      In theory you write short, easy to understand functions; in practice
      it isn't always this simple though.
    • Sylvain Le Gall
      Hello, ... When you can avoid it, it is better to NOT include type information. Using a tool like ocamldoc will render the function and its inferred types in
      Message 2 of 5 , Mar 31, 2010
        Hello,

        On 31-03-2010, Grant Rettke <grettke@...> wrote:
        >
        > Is it "poor taste" to include type information in function definitions?
        >
        > It seems like very nice documentation, but then again, maybe it is
        > nicer rely on the inferencing engine to reduce the amount of code?
        >

        When you can avoid it, it is better to NOT include type information.
        Using a tool like "ocamldoc" will render the function and its inferred
        types in a real documentation format (e.g. HTML).

        There are cases where you need to include type information, but they are
        corner cases.

        Regards
        Sylvain Le Gall
      • Martin Jambon
        ... Well, we can say it s a matter of taste :-) There are cases where it really helps when writing or modifying source code. That s when you re using objects
        Message 3 of 5 , Mar 31, 2010
          Grant Rettke wrote:
          > Is it "poor taste" to include type information in function definitions?

          Well, we can say it's a matter of taste :-)

          There are cases where it really helps when writing or modifying source code.
          That's when you're using objects and polymorphic variants, which are not
          recommended to beginners.

          You may also make your code difficult to follow by using tuples excessively.
          When things get complicated, it may be a good idea to use records instead of
          tuples.

          > It seems like very nice documentation, but then again, maybe it is
          > nicer rely on the inferencing engine to reduce the amount of code?

          Interface files (.mli) are usually the main place for documentation.
          Within the .ml files, you can explain your algorithms but it's usually just
          plain comments, not so much type annotations.

          > In theory you write short, easy to understand functions; in practice
          > it isn't always this simple though.

          I agree with easy-to-understand, but then why should short be a requirement?

          What should be small in general is the complexity of the function (or block of
          code) and of its environment, but using more lines of code can make things
          more readable.


          Martin
        • Dario Teixeira
          Hi, ... Sylvain and Martin have already mentioned the few cases where declaring function signatures is required and/or sensible in Ocaml. As to the matter of
          Message 4 of 5 , Mar 31, 2010
            Hi,

            > Is it "poor taste" to include type information in function definitions?

            Sylvain and Martin have already mentioned the few cases where declaring
            function signatures is required and/or sensible in Ocaml. As to the matter
            of "taste", note that this practice is not idiomatic in Ocaml, in contrast
            to Haskell where it seems current. I'm not sure if that's your case, but
            people coming to Ocaml from Haskell may at first tend to exaggerate on
            this aspect...

            Cheers,
            Dario Teixeira
          • Grant Rettke
            ... Thanks everyone. [Non-text portions of this message have been removed]
            Message 5 of 5 , Apr 3 2:06 PM
              On Wed, Mar 31, 2010 at 1:28 PM, Dario Teixeira <darioteixeira@...>wrote:

              > Sylvain and Martin have already mentioned the few cases where declaring
              > function signatures is required and/or sensible in Ocaml. As to the matter
              > of "taste", note that this practice is not idiomatic in Ocaml, in contrast
              > to Haskell where it seems current. I'm not sure if that's your case, but
              > people coming to Ocaml from Haskell may at first tend to exaggerate on
              > this aspect...
              >

              Thanks everyone.


              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.