Group Abstract Group Abstract

Message Boards Message Boards

0
|
13.8K Views
|
11 Replies
|
16 Total Likes
View groups...
Share
Share this post:

Understanding Wolfram Language programs

Posted 11 years ago

I am very new to Mathematica, and the Wolfram Language. I have been going through various demonstration files, and I am finding it surprisingly difficult to 'grok' the code. I have experienced this problem with other Lisp-like languages, and it seems to be driven by having to read the programs 'inside out'.

What I would like to understand is whether this is something that just goes away with time & experience, i.e. for highly experienced Mathematica programmers, do you find you just read the code naturally. Or, do you break apart people's code, perhaps using intermediate variables, in order to understand the various elements?

If you do break it apart, are there any tools that help? For instance, is there a way to unbundle function calls, and format them as chained functions - which is what I find myself doing.

POSTED BY: Andrew Burnett
11 Replies
Posted 11 years ago
POSTED BY: Andrew Burnett
Posted 11 years ago
POSTED BY: David Keith

Hi Andy,

yes, it definitely has a huge potential! But one has to pay a price in terms of effort. When I started learning Mathematica only three years ago, we had version 8 and there the Virtual Book was very explicit to find. And the best and fastest way to get familiar with WL is to work through the capter "Core Language" entirely. I do not understand why something that useful as this Virtual Book is now in V10 so completely hidden - you will not find it unless you know that there is one.

Debugging is in my opinion not that a big problem, because it is an interpreter language after all. And there the notebook environment is helpful, e.g. the possibility of double/triple/multiple clicks to make whole expressions visible - very simple, but effective!

But anyway - you made a top decision! I use MMA every day and I am sort of addicted!

Henrik

POSTED BY: Henrik Schachner
Posted 11 years ago
POSTED BY: Andrew Burnett
POSTED BY: Jake Trexel

I just want to second the above.

In general, displays of data, especially as in data-driven programming, make Mathematica code much easier to read and understand.

-- Mark

POSTED BY: Mark Tuttle

Hi Andy,

the relevant things are already said above. I just want to make a minor remark: One can easily write simple "help functions" to make complicated pieces of code more understandable, e.g.:

Attributes[makeObviousFrame] = 
  Attributes[makeObviousTree] = {HoldAllComplete};
makeObviousFrame[expr_] := Map[Framed, Inactivate[expr], {0, -2}];
makeObviousTree[expr_] := TreeForm[Inactive[expr]]

Putting these function in front of some "complicated" expression, e.g.:

makeObviousFrame @
 Flatten[mkArray1D /@ 
   Partition[
    Select[mccRaw, (NumberQ[#[[1]]] || 
        StringMatchQ[#[[1]], "INPLANE" ~~ ___]) &], 28], 1]
makeObviousTree @
 Flatten[mkArray1D /@ 
   Partition[
    Select[mccRaw, (NumberQ[#[[1]]] || 
        StringMatchQ[#[[1]], "INPLANE" ~~ ___]) &], 28], 1]

gives: enter image description here

Maybe this is helpful.

Henrik

POSTED BY: Henrik Schachner
Posted 11 years ago
POSTED BY: Andrew Burnett

The Virtual Book was easier to find in versions 8 and 9.

The on-line version is at http://reference.wolfram.com/language/tutorial/VirtualBookOverview.html .
In Mathematica, you can go to Help menu - Wolfram Documentation, and search for "virtual book". It is found at tutorial/VirtualBookOverview.

POSTED BY: Bruce Miller
Posted 11 years ago
POSTED BY: Andrew Burnett

The demonstrations code isn't good code to start with. I would have found it overwhelming and confusing when I started. I always recommend going through the virtual book and reading documentation examples.

You're right that it's very easy to make dense unreadable code in practically any lisp like language. Some of the coding styles I've seen used in the demonstrations are very difficult to piece together.

I find well written Wolfram Language code easy to read. More so than even, say, Python. But badly written code is always hard to read.

I don't know of any tools like you describe existing in any language. I'm not sure how it would know how to unbundle and un-nest the functions in a way that made it readable. Ideally, well written code is like that anyway.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard