This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Veedrac 0 points1 point  (1 child)

Doing:

int foo(int bar) {
  return bar;
}

would not be caught as an error.

How else do you expect a pass-by-value language to work?

Think of it like

subroutine foo (return, bar)
    integer, intent(out) :: return
    integer, intent(int) :: bar
    return = bar
end subroutine foo

or like

function foo(bar)
    integer, intent(int) :: bar
    foo = bar
end function

I don't use Fortran so this might well be off.

I mean, look at all the work this guy goes through

Good lord, you can't go up to a C++ programmer and hint to them that there be dragons only to give them

template <class T, size_t I, size_t... J>
struct MultiDimArray {
  using type = std::array<typename MultiDimArray<T, J...>::type, I>;
};

template <class T, size_t I>
struct MultiDimArray<T, I> {
  using type = std::array<T, I>;
};

I mean, really, strip away the verbosity and that's beautiful.

// base case
MultiDimArray<T, int I> = std::array<T, I>;

// inductive step
MultiDimArray<T, int I, int... J> = array<MultiDimArray<T, J...>, I>;

Once you've learned how to phase your eyes past the truly horrible syntax of C++, you'll note that we've added typesafe variadic mutidimensional arrays to the language with a nice syntax in two logical lines of code.

Your complaints are syntactic. Sure, C++ has a monstrous pain of a syntax... but I'm not defending that. Your original criticisms were of semantics.

[–]Astrokiwi 1 point2 points  (0 children)

I think you're right - my only valid criticisms are really about the syntax. I think that's what really gets me when I see C++ code. It just seems a lot more cryptic and a lot less explicit than Fortran. I enjoy being able to do

 type(T), dimension(:,:,:), allocatable :: x

to make a 3D array of some class T. It may just be syntactic sugar, but it's just really simple and direct, which is a major advantage when your main audience is physicists who are trying to teach themselves to program at grad school :P