Questions tagged [guidelines]

General guidelines and best practices for Mathematica usage and programming.

Filter by
Sorted by
Tagged with
549 votes
37 answers
131k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
183 votes
6 answers
24k views

How to compile effectively?

What are the best practices of compiling functions? I understand that this is a vague question, but let me list some aspects that might trigger useful answers. Some of these have already been answered ...
István Zachar's user avatar
97 votes
4 answers
10k views

Functions with Options

Suppose you want to create a function which has optional arguments. Maeder's book Programming in Mathematica covers the topic extensively up to version 3, but some things have changed/evolved since ...
magma's user avatar
  • 5,290
58 votes
3 answers
5k views

Is manual adjustment of AccuracyGoal and PrecisionGoal useless?

This is a problem confusing me for years. AccuracyGoal and PrecisionGoal are two options that I never truly understand and, to ...
xzczd's user avatar
  • 66k
156 votes
9 answers
15k views

General strategies to write big code in Mathematica?

I think after six months of exposure to Mathematica and the Wolfram Language I am fairly OK with writing short codes and snippets. However, what are some general strategies to use in order to write ...
Ali Hashmi's user avatar
  • 8,950
33 votes
5 answers
1k views

Different strategies to get a clean Kernel. Quit, Exit, ClearAll, Remove, CleanSlate?

Often new users face problems with lingering definitions that, if unaware, may cause unexpected and frustrating behaviour. There are several answers that illustrate different aspects of the solution, ...
rhermans's user avatar
  • 36.5k
32 votes
5 answers
2k views

Resource management in Mathematica

I am using a library that has functions like createSomeObject[] and deleteSomeObject[obj]. It is an interface to a C language ...
Szabolcs's user avatar
  • 235k
52 votes
3 answers
6k views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
Jon F.'s user avatar
  • 645
43 votes
2 answers
5k views

What are some common issues with fitting functions to data?

Mathematica has numerous functions designed to, or capable of, fitting known functions, and finding unknown functions to match data sets. What are some common issues that come with finding those fits?
Feyre's user avatar
  • 8,597
36 votes
4 answers
2k views

What are the most common (usual) ways to make palettes with non-trivial functionality?

What are the best (most robust and most convenient) ways to create palettes that can be installed permanently (using Palettes -> Install Palette...) and are safe ...
Szabolcs's user avatar
  • 235k
34 votes
2 answers
1k views

Custom atomic expressions - modern tutorial

Atomic but sophisticated expressions are all around for a long time: Graph SparseArray. More are coming with each new release, ...
Kuba's user avatar
  • 137k
19 votes
2 answers
3k views

How to unload automatically loaded packages?

I know that this has been discussed here (How do I clear all user defined symbols?), but my case is somewhat different. How does one unload packages during runtime that were loaded with the start of ...
István Zachar's user avatar
38 votes
2 answers
3k views

Best practice of passing a large number of parameters to functions

I have a number of functions that all take a large number of parameters. I am wondering what is the best practice of passing these parameters to those functions. I could, of course, simply specify ...
U.T.'s user avatar
  • 573
35 votes
2 answers
2k views

What are recommended guidelines for developing packages?

This might be of general interest – I have different questions regarding naming conventions, contexts, subcontexts, shadowing, etc., but I do feel that they are closely related, thus I don't really ...
István Zachar's user avatar
45 votes
7 answers
5k views

Mathematica style guide?

I encountered this site today https://code.google.com/p/google-styleguide/ regarding the programming style in some languages. What would be best programming practices in Mathematica, for small and ...
faysou's user avatar
  • 11k
14 votes
2 answers
756 views

Good clearing practices

I have been using Mathematica for about 2 years and I'm pretty ok to write and optimize my code. Wanting to improve my practice, I often look at code examples. However, I can not determine if there is ...
physicien's user avatar
  • 407
73 votes
6 answers
5k views

Q&A Mathematica v.11 Neural Networks: A comprehensive look at Layers, Net Functions, and pioneering into this [[experimental]] code

Motivation As Mathematica v.11 was released earlier this month with a host of new [[experimental]] functions and a limited number of examples on curated data that ...
SumNeuron's user avatar
  • 5,422
28 votes
1 answer
5k views

Error checking and trapping techniques with Throw and Catch

Mathematica provides several mechanisms for checking arguments and trapping errors in a function definition. Typical methods are : Definitions with argument patterns, definitions with ...
magma's user avatar
  • 5,290
19 votes
1 answer
502 views

Any manual on cell grouping management?

Recently I come back to the problem of cell grouping and performed extensive search on this site and on MathGroup archive for information on how to use the possible values of the ...
Alexey Popkov's user avatar
19 votes
4 answers
638 views

Internal DynamicModule steals scope of external DynamicModule

I have two dynamic objects, one nested in the other. Both have their own functions defined, as follows. I have simplified them to the point where they don't make much sense, but can still illustrate ...
István Zachar's user avatar
14 votes
2 answers
11k views

How to draw confidence ellipse from a covariance matrix?

I am studying a two-dimensional dataset, whose mean vector and covariance matrix are the following: ...
Abhijit Saha's user avatar
70 votes
2 answers
2k views

Guidelines for planning custom GUI in Mathematica

This post is here to save your time during GUI development in Mathematica. And one way to do this is to know where limits are and to be aware of features that are awaiting. Background Usually I don't ...
Kuba's user avatar
  • 137k
34 votes
15 answers
120k views

Alternatives to Mathematica

Inspired by the recent question Alternatives to LaTeX on tex.stackexchange.com. Are there any paid-for or open source alternatives to Mathematica which produce equal or even better functionality, ...
19 votes
1 answer
2k views

What is the difference between MathLink and WSTP? Which one should I use?

What is the difference between MathLink and WSTP programs? Will the use of MathLink protocol be maintained or not?
Ph L's user avatar
  • 191
46 votes
3 answers
21k views

Guidelines on giving readable names to variables [closed]

I know that one cannot use underscore to a variable name, like degree_of_The_First_Polynomial. But for a long variable name, it ...
user565739's user avatar
  • 1,119
22 votes
2 answers
2k views

How are Accuracy and Precision related Mathematica for a given operation?

The common understanding for Accuracy and Precision in English language is given by this figure. Inspired by this question I have a follow up question relating ...
rhermans's user avatar
  • 36.5k
16 votes
2 answers
988 views

Remove versus ClearAll

What is the difference between Remove and ClearAll? I thought that "not being recognized by Mathematica", which is the effect ...
Hector's user avatar
  • 6,428
14 votes
1 answer
299 views

Clean package update for API/FormFunctions on Wolfram Cloud

Cross posted on community.wolfram.com (new comments) TLDR There is a pool of kernels/sessions available for each user, you don't have control over the pool only over specific kernel you currently ...
Kuba's user avatar
  • 137k
14 votes
2 answers
561 views

Wolfram Cloud deployment obstacles

What are official restrictions about FormFunctions/general deployment contents? There are problems with many things which sometimes I have workarounds for but I ...
Kuba's user avatar
  • 137k
30 votes
5 answers
775 views

Unexpected behaviors in built-in functions

Existence of this topic is discussed in this mathematica.meta post. I'm sure I am not the only non-beginner in WL who from time to time finds themselves not being able to predict an outcome of a ...
25 votes
3 answers
1k views

Package organization

When writing a Mathematica package Foo, with functions f1, f2 and f3, one can use the template: ...
Picaud Vincent's user avatar
16 votes
1 answer
2k views

Efficient backtracking with Mathematica

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("...
a06e's user avatar
  • 11.3k
15 votes
1 answer
353 views

Working with DynamicModule: SetDelayed + OwnValues

Shortly, definitions in form of e.g. x:= RandomReal[] have to be avoided inside DynamicModule[{x}, ...]. Why?, this ...
Kuba's user avatar
  • 137k
11 votes
1 answer
216 views

Nested association values validation. POJsO handling

Sometimes it is convenient to work in your package/app with "objects" like: ...
Kuba's user avatar
  • 137k
39 votes
2 answers
2k views

General techniques for creating complex animations

I love good animations of abstract concepts, and when I try to create them myself, I prefer doing so in code to make sure they are exact (and because some things are just way too fiddly to do by hand)....
Martin Ender's user avatar
  • 8,774
19 votes
3 answers
4k views

Programming Mathematica in plaintext, i.e. no formatting, non-notebook

I'm new to Mathematica and I've just begun reading Paul Wellin's Programming in Mathematica. The book, like many other books and online tutorials, revolves around using the notebook, with all its ...
Andrew Cheong's user avatar
18 votes
1 answer
934 views

How to handle package dependencies?

When an application written in C++ depends on some libraries, the libraries are usually shipped together with the application. Two applications that depend on the same library will not share the same ...
Szabolcs's user avatar
  • 235k
15 votes
2 answers
355 views

Hold attributes vs performance

Is there a reason to use Hold* attributes for functional code (e.g. no intention to mutate input)? I'd expect performance gains as in pass by value vs pass by ...
Kuba's user avatar
  • 137k
13 votes
2 answers
3k views

How to train a convolutional neural net on images?

The functions Predict[] and Classify[] both have the option Method -> "NeuralNetwork", ...
M.R.'s user avatar
  • 31.4k
10 votes
0 answers
163 views

URL functions overload

All these functions seem capable of doing the same things: Import, URLFetch, URLSave, ...
M.R.'s user avatar
  • 31.4k
10 votes
2 answers
404 views

Naming convention for symbols exported from package

I know this is a little opinion based, but so is Mathematica style guide and similar topics. The issue is important so I think this topic will be beneficial for future visitors. Q: So ...
Kuba's user avatar
  • 137k
7 votes
2 answers
204 views

Impact of Linkage and DistanceFunction on Agglomerate clustering

I'm using Agglomerate function to find clusters of my experimental points. I have about 20 points with 10 parameters each. It seems it works fine, but there are plenty of Linkage and DistanceFunction ...
Филипп Цветков's user avatar
7 votes
1 answer
1k views

Begin["`Private`"] vs Module

So, if you have a package formatted like so: ...
Joe Blow's user avatar
  • 417
7 votes
3 answers
362 views

What is the recommended way to define numeric function with special cases?

What is the recommended way to define a purely numeric function with special cases? Should I define many special cases with pattern matching? ...
QuantumDot's user avatar
  • 19.6k
7 votes
1 answer
282 views

Understanding Dynamic, Refresh, and TrackedSymbols

I thought I had a pretty good handle on Dynamic, but some recent examples have made me suspect that I may have some misconceptions, and I am not finding good ...
Kevin Ausman's user avatar
  • 2,267
6 votes
0 answers
360 views

Multipart package creation, development and maintenance [closed]

I am a physics major. I focus on theoretical and mathematical physics. After spending some time with Mathematica I found that it is not straightforward to create separate files for logically distinct ...
Subho's user avatar
  • 1,534
6 votes
1 answer
137 views

How to work with BoxOptions (ButtonBoxOptions, PanelBoxOptions, etc.)

The main question is in the title. Here are subtopics I'd like to focus on: Is there a tutorial related to them anywhere in documentation? How can I check what are current values of e.g. ...
Kuba's user avatar
  • 137k
6 votes
1 answer
151 views

To TagSet or not to TagSet when using MakeBoxes

What is the difference between the following two: ...
QuantumDot's user avatar
  • 19.6k
5 votes
0 answers
84 views

Handling rendering delays gracefully

I moved the second issue to a separate topic: 162013 Please run the code sample As you can see there is a delay between the moment the calculation is finished and when the graphics is shown. And ...
Kuba's user avatar
  • 137k
3 votes
1 answer
131 views

Questions about InlineCell vs InlineFormula vs DisplayFormula cells

I'm having trouble with typesetting, and can't get these questions straight in my head. What is the difference between "InlineCell" and ...
B flat's user avatar
  • 5,513