j3-fortran / generics

BSD 3-Clause "New" or "Revised" License
39 stars 8 forks source link

Recent blog/talk about metaprogramming #70

Open septcolor opened 2 years ago

septcolor commented 2 years ago

I have come across this blog post recently, which might be of some example for the utility of templates for such simulations. (I have no experience with "gas dynamics", so not familiar with their calculations themselves.)

A Gas Dynamics Toolkit in D https://dlang.org/blog/2022/02/02/a-gas-dynamics-toolkit-in-d/

(Excerpts from the blog)

Features of D that have been of benefit to us include:

  • Template programming that other Mechanical Engineers can understand (thanks Walter!). Many of our numerical routines are defined to work with numbers that we define as an alias to either double or Complex!double values. This has been important to us because we can use the same basic update code and get the sensitivity coefficients via finite differences in the complex direction. We think this saved us a large number of lines of code.
  • String mixins have replaced our use of the M4 preprocessor to generate C++ code in Eilmer3. We still have to do a bit of head-scratching while building the code with mixins, but we have retained most of our hair—something that we did not expect to do if we continued to work with C++.
  • Good error messages from the compiler. We often used to be overwhelmed by the C++ template error messages that could run to hundreds of lines. The D compilers have been much nicer to us and we have found the “did you mean” suggestions to be quite useful.

The homepage of their software seems here: https://gdtk.uqcloud.net/ https://github.com/gdtk-uq/gdtk https://github.com/gdtk-uq/gdtk/tree/master/src/eilmer

I've also come across a recent talk in FOSDEM2022, which explains the utility of generics, templates, and macros in the Nim language. What I felt interesting is the classification of those things into "Level 1, 2, and 3" (where 1 => generics, 2 => templates, 3 => macro). I guess D's template and string mixin (that are mentioned in the above D blog) correspond roughly to Levels 1/2, while Julia's parametrized functions/types and macro correspond probably to Level 1 and 2/3, respectively (though the distinctions may be not so clear...)

https://www.youtube.com/watch?v=y6GQeWdmSb8 (youtube recording) https://video.fosdem.org/2022/D.nim/ (from the FOSDEM site, choose "metaprogramming.webm")

tclune commented 2 years ago

I'm a bit overwhelmed with multiple projects at the moment, so may not be able to dive into these materials. I will say that we (generics subgroup) are intentionally ovoiding metaprogramming which is related, but distinct to generic programming. (But the terms are often incorrectly used interchangably.)

septcolor commented 2 years ago

Thanks much for your message, and please do not worry about checking them so soon! I will post related materials here (in this thread) when I come across something interesting or potentially useful.