Hello everyone.
I’m learning the wolfram language.
My difficulty is the readability of the code.
In fact I get all nested functions and I don’t understand anything anymore.
Is there a way to make the code more readable?
Thank you
Hello, Blu. The best way to learn to read Wolfram Language code is to read and write much code. Stephen Wolfram’s “An Elementary Introduction to the Wolfram Language” provides an excellent set of examples. There are exercises at the end of each chapter. There is a whole interactive course designed around the text of this book. You can access the free course here. After each chapter, there are a set of exercises to do that can be automatically graded. If you don’t get an exercise right, you can re-submit your answer multiple times. As you complete a group of chapters, there are quizzes on that group of topic. If you go through all the exercises and quizzes in this courses, your skills to read and write Wolfram Language code will be markedly improved.
There are also a variety of courses available at Wolfram U . I think starting with the introduction interactive course is the best way to start. Good luck.
This a good question. How to make the structure of a piece of WL code, in a notebook, easier to understand? I dont know how to do this “automatically”. But it can be done manually. By rewriting the code in a Code cell (as opposed to to the standard Input cell) and inserting linebreaks and indentations.
The example below is from the Manipulate documentation
Copied from docs to an Input cell:
Manipulate[
ArrayPlot[
Take[data, h, w]], {{data, RandomInteger[{0, 1}, {10, 20}]},
ControlType -> None}, {{h, 5}, 1, 10, 1}, {{w, 5}, 1, 20, 1},
Dynamic[Panel[
Grid[Outer[Checkbox[Dynamic[data[[#1, #2]]], {0, 1}] &, Range[h],
Range[w]]]]]]
Copied to a Code cell and edited:
Manipulate[
ArrayPlot[
Take[data,h,w]
],
{{data,RandomInteger[{0,1},{10,20}]},ControlType->None},
{{h,5},1,10,1},
{{w,5},1,20,1},
Dynamic[
Panel[
Grid[
Outer[
Checkbox[
Dynamic[data[[#1,#2]]],
{0,1}
]&,
Range[h],Range[w]
]
]
]
]
]
This a good question. How to make the structure of a piece of WL code,
in a notebook, easier to understand?
Agreed: it’s a good question. I just didn’t sense that the OP was talking about refactoring code.
WRT automatically making code easier to understand, Theo Gray’s recent presentation on LLMs and the recent Notebook enhancements to version 13.2 had some interesting comments. Somewhere around 20 minutes into the hour-long presentation, Theo noted that he had asked the AI to put more appropriate variable names in his code, and he was thoroughly satisfied with the name-changes. He noted that the AI clearly understood what was happening in the code and made good name selections. These changes are a bit tangental to what you suggest, but they’re definitely in the same thinking of near-automatic improvement of code.
The presence of these LLMs will completely change the nature of programming. I hope that Wolfram figure out how to make those AI engines run locally in the FPUs and Neural Engines of modern computers. Those processors are mostly sitting around on my M1 Mac; it’d be nice to get them to start doing some crunching out of them.
