# What is a good way to code long, complex, compilable algorithms?

The functional paradigm of the Wolfram Language used in Mathematica is all around wonderful.

For intense numerics, Mathematica comes with the ability to Compile sections of code to the Wolfram Virtual Machine (WVM). When written correctly, this can lead to speed boosts by orders of magnitude (I am particularly proud of the code in this question that computes the Dilogarithm). Also, it is totally portable, which makes it particularly useful to include in packages for public use.

But, for extremely long and complex algorithms, it is agonizingly clumsy to write the procedural code in Mathematica's functional syntax. Especially bad is if there are lots of nested If statements, and multiple subroutines that tend to require CompilationOptions -> {"InlineExternalDefinitions" -> True}. All the [[ [ [ [[ and ]] ] ] ]] drive me totally crazy.

Is there a way to write code that is closer in syntax to C that can also compile to WVM to preserve the overall portability?

• I try to modify individual functions for each if statement, but sometimes it becomes messy when the if statements need lots of arguments. – Bichoy Jun 7 '15 at 21:26
• I also try to use the prefix form to reduce the number of [ ] but you are right, it can be a pain sometimes... – Bichoy Jun 7 '15 at 21:28
• I'd disagree with the "opinion-based" close reason. Although a possible answer to this is opinion-based, I don't think this is a bad thing in this case. Such answers, opinion-based or not, will likely be useful. – LLlAMnYP Dec 1 '15 at 12:44
• Since I wrote this question, I found out that Which is compilable, and really helps cut down on nested If statements. – QuantumDot Dec 1 '15 at 15:00