10 comments

[ 3.1 ms ] story [ 31.9 ms ] thread
C++ is amazingly distracting. There's an algorithm in here, but it's hard to see through all the

void fractal(window<int> &scr, window<double> &fract, int iter_max, std::vector<int> &colors, const std::function<std::complex<double(std::complex<double>, std::complex<double>)> &func, const char *fname, bool smooth_color);

Does slightly seem like some typedefs might have helped. Particularly the `func` type signature.
That's unfair! The algorithm is in the function "escape", not the function "fractal".

escape's function signature is much simpler:

    int escape(std::complex<double> c, int iter_max, const std::function<std::complex<double>(std::complex<double>, 
	std::complex<double>)> &func)
At least we get to use "auto" when we define func, though:

    auto func = [] (std::complex <double> z, std::complex<double> c) -> std::complex<double> {return z * z * z + c; };
You could always let the compiler work it out for you.

template< typename Func > int escape(std::complex<double> c, int iter_max, Func& func)

It's a shame, actually i like C++11 and the new features but seeing the lambda is instantly pushing me away again:

auto func = [] (std::complex <double> z, std::complex<double> c) -> std::complex<double> {return z * z + c; };

Why isn't there some nicer and more readable syntax for some of that basic stuff?!

You can leave out the explicit return type.

  auto func = [] (std::complex<double> z, std::complex<double> c) { return z * z + c; };
You could also typedef the number type somewhere:

  typedef std::complex<double> Complex;
  // ...
  auto func = [] (Complex z, Complex c) { return z * z + c; };
I think that last one looks ok.
(comment deleted)
Maybe we have different aesthetic objections, but isn't all of the ugliness in that example due to the templated std::complex class, and unrelated to lambdas? If you make a typedef first, it becomes considerably nicer:

auto func = [](cdouble z, cdouble c) -> cdouble { return z * z + c; }

I looked at the first block of code of the article when the page loaded and thought "Hey! That's pretty expressive for C++- It's almost as compact now as Haskell for a mandelbrot program!"

...then I realized that it was only a baroque type declaration and that scrolling down the page reveals tons of additional code blocks... and those aren't actually all the code.

(C++ is still a great language for many problem domains... Code brevity/elegance is not its strength however.)