Introduction to Scripting Languages - CECI · Introduction to Scripting Languages...
Transcript of Introduction to Scripting Languages - CECI · Introduction to Scripting Languages...
![Page 2: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/2.jpg)
2
Goal of this session:
“Advocate the use of scripting languages and help you choose the most suitable for your needs”
![Page 3: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/3.jpg)
3
Agenda
1. Interpreters vs compilers
2. Octave, R, Python
3. GUIs & Literate programming
4. Packages/Libraries/Modules
5. When it is too slow
6. Bridges
![Page 4: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/4.jpg)
4
Interpreters vs Compilers
● A compiler reads the whole code and produces aseparate binary file that can be executed by the CPU.
C/C++, Fortran, Java, Go, Haskel, ...● An interpreter reads each line of code and executes it by
calling the corresponding functionalities in its own code.
Bash, Python, PHP, Javascript, Ruby, ...
![Page 5: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/5.jpg)
5
Interpreters vs Compilers
● The ugly truth...
– Many interpreters will pre-compile the code
– Some compilers compile not to CPU-specific machineinstructions but to bytecode
– The bytecode interpreters sometimes re-compile thebytecode just before execution (JIT compiling)
– Interpreters exist for C and C++
– Compilers exist for Python
– The interpreter can be compiled or himself interpreted
![Page 6: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/6.jpg)
6
Interpreters vs Compilers
Compilers
– can apply code-wise powerful optimization
– practically have no run-time overhead
→ Speed
Interpreters
– allow easy code introspection
– offer high-level language constructs and tools
→ Ease of use
![Page 7: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/7.jpg)
7
Interpreted languages
● Easier to learn
– Many implementation details hidden
– Can try and test code portions rapidly and easily
● Easier to exchange/reuse
– The scripts are cross-platform by design
– Often built-in package management
● Faster development
– More convenient programming and shorter programs
● Offers many simplifications and shortcuts – no need to micromanage memory● Built-in support for mundane tasks (handle files, dates, plots, Nas, NANs, etc.)
– Easier to debug and profile
● GUI
![Page 8: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/8.jpg)
8
Ex.1: argument parsing in Fortran
https://docs.python.org/3/library/argparse.html
![Page 9: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/9.jpg)
9
Ex.1: argument parsing in Fortran
![Page 10: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/10.jpg)
10
Ex.1: argument parsing in Fortran
![Page 11: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/11.jpg)
11
Ex.1: argument parsing in Python
https://docs.python.org/3/library/argparse.html
![Page 12: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/12.jpg)
12
Ex.2: Use XLS file in C
![Page 13: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/13.jpg)
13
Ex.2: Use XLS file in R
https://cran.r-project.org/web/packages/gdata/
![Page 14: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/14.jpg)
14
Ex.3: default args in Java
![Page 15: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/15.jpg)
15
Ex.3: default args in Octave
https://www.gnu.org/software/octave/doc/interpreter/Default-Arguments.html
![Page 16: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/16.jpg)
16
1.
Why those three?
![Page 17: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/17.jpg)
17
Why those three?
● All very much used in scientific applications
R (S/SPlus): strong for statistics
Octave (Matlab): strong for engineering
Python Scipy/Numpy (Canopy,Anaconda): strong for data science
● All free and free.
● Fun fact: All started as wrappers for Fortran code!
![Page 18: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/18.jpg)
18
Why those three?
S was designed by John Chambers (Bell Lags) as aninteractive interface to a Fortran-callable library, ca 1976.
MATLAB was built by Cleve Moler (University of New Mexico) togive students access to LINPACK and EISPACK without themhaving to learn Fortran
Python Numpy (Travis Oliphant, Brigham Young University)originates from f2py, a tool to easily extend Python with Fortrancode.
![Page 19: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/19.jpg)
19
Why those three?
Octave: Fortran optimized routines made easy to use. Easily handle (multi-dimensional) matrices, Nans, Infs, no need to worry about memory allocation, etc.
R: Easily handle matrices, strings, dates, and categories and missing values
Python: Full programming language, can handle custom objects
![Page 20: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/20.jpg)
20
Why those three?
By contrast,
Ruby, Perl: smaller bioinformatics-only community
Javascript, PHP, Bash, TCL, Lua: totally different goal
Matlab, IDL, Mathematica: not free
Julia: very young – good luck to get help when needed
![Page 21: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/21.jpg)
21
Why those three?
By contrast,
Ruby, Perl: smaller bioinformatics-only community
Javascript, PHP, Bash, TCL, Lua: totally different goal
Matlab, IDL, Mathematica: not free
Julia: very young – good luck to get help when needed
Not true anymore. Worth considering !
(but not yet in this session...)
![Page 22: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/22.jpg)
22
2.
TripleQuickstart
![Page 23: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/23.jpg)
23
Operators and assignment
http://sebastianraschka.com/Articles/2014_matrix_cheatsheet_table.html
![Page 24: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/24.jpg)
24
Building arrays/matrices
http://sebastianraschka.com/Articles/2014_matrix_cheatsheet_table.html
![Page 25: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/25.jpg)
25
Indexing/slicing
http://sebastianraschka.com/Articles/2014_matrix_cheatsheet_table.html
![Page 26: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/26.jpg)
26
Searching arrays/matrices
http://mathesaurus.sourceforge.net/matlab-python-xref.pdf
![Page 27: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/27.jpg)
27
Control structures
http://mathesaurus.sourceforge.net/matlab-python-xref.pdf
![Page 28: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/28.jpg)
28
Linear regression
http://mathesaurus.sourceforge.net/matlab-python-xref.pdf
![Page 29: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/29.jpg)
29
Linear regression
http://mathesaurus.sourceforge.net/matlab-python-xref.pdf
FortranC
![Page 30: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/30.jpg)
30
So..
http://mathesaurus.sourceforge.net/matlab-python-xref.pdf
Fast to learnFast to code
![Page 31: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/31.jpg)
31
Challenge.. Write 'sapin.[m|R|py]'
![Page 32: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/32.jpg)
32
Challenge.. Write 'sapin.[m|R|py]'
![Page 33: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/33.jpg)
33
Help
You will need for-loops, if-conditionals, variable assignment, and printingwhich you can find in the slides
Other resources:https://en.wikibooks.org/wiki/Octave_Programming_Tutorial/Getting_started
https://cran.r-project.org/doc/manuals/R-intro.htmlhttp://wiki.scipy.org/Tentative_NumPy_Tutorial
http://stackoverflow.com/questions/14395569/how-to-output-text-in-the-r-console-without-creating-new-lines
http://stackoverflow.com/questions/493386/how-to-print-in-python-without-newline-or-space
http://stackoverflow.com/questions/1012597/displaying-information-from-matlab-without-a-line-feed
![Page 34: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/34.jpg)
34
If you are that quick... Try this:
![Page 35: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/35.jpg)
35
Possible solution (C)
![Page 36: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/36.jpg)
36
Possible solution (C, cont'd)
![Page 37: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/37.jpg)
37
Possible solution (Octave)
![Page 38: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/38.jpg)
38
Possible solution (R)
![Page 39: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/39.jpg)
39
Possible solution (Python)
![Page 40: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/40.jpg)
40
Second challenge
![Page 41: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/41.jpg)
41
Second challenge
● Find for which value of 'parameter' is 'result' the lowest.
● Course of action:
– Read all files and parse them (you might need to installadditional packages/libraries/modules)
– Build two arrays one of parameter values and the otherone for result values
– Remove problematic values (plotting might help here)
– Find minimum
![Page 42: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/42.jpg)
42
Possible solution
- https://nl.mathworks.com/matlabcentral/fileexchange/17177-ini2struct- https://cran.r-project.org/web/packages/ini/index.html- https://docs.python.org/3/library/configparser.html
![Page 43: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/43.jpg)
43
Second challenge
![Page 44: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/44.jpg)
44
3.
Graphical User InterfacesEditing, debugging, accessing the doc, made easy
Literate programmingAuthoring dynamic documents with code in them
![Page 45: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/45.jpg)
45
Octave
![Page 46: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/46.jpg)
46
Rstudio
![Page 47: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/47.jpg)
47
Spyder
![Page 48: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/48.jpg)
48
3.
Graphical User InterfacesEditing, debugging, accessing the doc, made easy
Literate programmingAuthoring HTML or LaTeX documents
with code and results in them
![Page 49: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/49.jpg)
49
RMarkdown and KnitR
![Page 50: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/50.jpg)
50
Jupyter notebooks
![Page 51: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/51.jpg)
51
Shiny
![Page 52: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/52.jpg)
52
Dash
![Page 53: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/53.jpg)
53
4.
ExtensionsPackages – Libraries – Modules
![Page 54: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/54.jpg)
54
Octave Forge
![Page 55: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/55.jpg)
55
CRAN
![Page 56: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/56.jpg)
56
PyPI
![Page 57: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/57.jpg)
57
5. General tips when it is slow
● Program thoughtfully:
– Use vectorized functions
– Avoid loops
– Preallocate
– Force type
– Avoid copy-on-write● Link to fast libraries (C/C++, Fortran, Java)
● Write low-level parts in C or Fortran
● Compile – jit
● Go parallel
![Page 58: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/58.jpg)
58
6. Bridges
Python → R http://rpython.r-forge.r-project.org/
Octave → Python https://pypi.python.org/pypi/oct2py
R → Python http://rpy.sourceforge.net/
Octave → R https://cran.r-project.org/web/packages/RcppOctave
Python → Octave https://github.com/daniel-e/pyoctave
R → Octave http://www.omegahat.org/ROctave/
![Page 59: Introduction to Scripting Languages - CECI · Introduction to Scripting Languages damien.francois@uclouvain.be October 2017. 2 Goal of this session: “Advocate the use of scripting](https://reader030.fdocuments.us/reader030/viewer/2022040319/5e3fe983bb7be2219e648c54/html5/thumbnails/59.jpg)
59
Summary
Octave, R, Python (and Julia)
Much more programmer-friendly than C/C++/Fortran
Still able to use fast compiled code
Focus on the unsolved problems
Try all and choose one