5
$\begingroup$

Is there any code formatting style reference for Wolfram Language similar to https://www.python.org/dev/peps/pep-0008/ and https://google.github.io/styleguide/javaguide.html? I'm teaching some people programming in WL and would like to have to read something about formatting style if there is anything recommendable.

$\endgroup$
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/72669/… $\endgroup$ – Szabolcs Dec 4 '17 at 23:17
  • $\begingroup$ Why other programming languages' communities have such standard but not Mathematica. Is it because the community too small or the syntax intrinsically is hard to have formatting styles defined? $\endgroup$ – qazwsx Dec 5 '17 at 7:52
3
$\begingroup$

I did a Google search on "mathematica coding conventions" and came up with several pages of suggestions in this area, but nothing that anyone has standardized on. The last few paragraphs of Mathematica style guide? has many statements which could serve as a basis for a style guide. A search on 'mathematica style guide' also returns many results.

In my Mathematica learning journey, I was constantly urged to use Map and MapThread for looping constructs, instead of For and Do, etc. Once one gets used to using Map and MapThread for this purpose, it becomes quite natural, and it does usually result in faster code.

In computer science we are constantly urged to make code readable. Making code readable has a number of benefits:

  1. It teaches others how to operate in the domain, the application area. It also teaches readers how to use standard coding paradigms, patterns, and constructs to solve particular problems. It leaves a legacy for others to build on.

  2. It makes code much easier, and therefore less costly, to maintain, and there will be changes.

  3. It is much easier and faster to find mistakes.

One is constantly amazed at the code that appears on Mathemetica Stack Exchange: It can solve important, interesting, and difficult problems in small fractions of a second. Yet no one would accuse that code of being readable. It takes hours to figure out what the author is doing and why he is doing it. If there is any gift you could give to your students, it is the instruction to make their code readable and use comments so others can easily figure out what the intent of the code is, what is being done, and why it is done that way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.