Hacker News new | ask | show | jobs
by ktpsns 2980 days ago
Just to give an example why a "domain specific" language like Julia is more appealing then a "general purpose" language like Swift: I would like to demonstrate this on the old and classy Fortran vs C++ discussion in numerical computing.

In Fortran, you can write linear algebra on n-dimensional arrays (similar as in numpy and julia) very compactly, i.e.

   d(i) = TRANSPOSE(MATMUL(B(i,:),c))
Writing something like this in C++ is absolutely possible and elegant with modern templates libraries such as `eigen`. However, the compilation will be slower, the compiler errors will be hard to read and it is hard to beat Fortrans runtime efficiency of such code.

But it get's more interesting. Think of tensor contractions. This is something where you probably want to implement your own algebra (say for relativistic quantum mechanics or for general relativity) -- or you just stick to the n-dimensional array again and use index-wise loops:

   DO i=1,4
   DO j=1,4
   DO k=1,4
   DO l=1,4
     A(i,j) = B(k,l)*C(i,k)*D(l,j)  ! note: compe up with better examples
   END DO
   END DO
   END DO
   END DO
I maintain a templated C++ library to write such expressions in one line instead of 4 loops. But contrary to this Fortran code, in order to understand my code, you first have to learn this library. Means you need to learn C++, then the library. In Fortran, it is just Fortran. Nothing more.

Believe it or not: Many scientists are no good programmers. Cut-down domain specific languages are perfect to avoid them to loose time on weird compiler features such as "const", templates and all that overhead which is hard to regain in time.

1 comments

> But contrary to this Fortran code, in order to understand my code, you first have to learn this library

Do you ? I've used Eigen and boost a lot of times and didn't ever need to "learn how the sausage is made", just looking at examples is enough to get stuff to work.

Whether you look up examples or a reference documentation does not change the fact that ontop of a given language, you learn new concepts of a library.

In contrast, domain specific languages have exclusive support for certain data types built right into the heart. There is a need for that.

I don't really understand the difference between reading three pages of documentation on a language website or two pages on a language website and one page on a library website.