1. 18
  1.  

  2. 5

    The raytracer is one of my favorite programs to write to learn a language. It’s complex enough that you can use relatively advanced language features, but simple enough that you can finish it quickly. You can also add a lot of detail to make it as complicated as you want.

    1. 2

      I am getting SERIOUS de ja vu reading this comment. Have you said this exact same thing before on the internet?

    2. 4
      1. 4

        This has been around a while. It’s not a bad comparison, but I wish the author would use a better coding style. Updating to C++11 would be nice, too, especially for iterating over containers, etc.

        C++ like this:

        Vec operator+(const Vec &a, const Vec &b)
        { return Vec(a.x+b.x, a.y+b.y, a.z+b.z); }
        

        And OCaml like this:

        let aux x' z' = create (level - 1) (c +| {x=x'; y=a; z=z'}) (0.5 *. r) in
        c, 3. *. r, [obj; aux (-.a) (-.a); aux a (-.a); aux (-.a) a; aux a a]
        

        are hard to read and just bad style.

        1. 4

          I also wish the author would update for more recent compilers – gcc 4.1 and ocaml 3.10 was current as of, what, like 8 years ago?

          1. [Comment removed by author]

            1. 4

              Because me running a quick personal benchmark doesn’t update a commonly referenced talking point article.

        2. 1

          Just as I was about to request that equivalent sections be aligned for better comparison, I scrolled down. :) For the most part, the code is very similar in length. The C++ is more verbose because it sets up extra types, though that’s a matter of style preference. I find code easier to read when tuples have names. Or the intersect function. It’s not obvious to me what the possible inputs are based on the patterns matched. OCaml may allow tossing around (this, that) but I’m not sure it’s best in the long term. Difference between clever and smart. :)