Unorganised notes about programming in Exodus: Difference between revisions

From NEOSYS Dev Wiki
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
== c++ exodus ==
The following is just a scrap pad of ideas to be incorporated in documentation


Following is VERY RANDOM and just ideas to be documented nicely later on.
== C++ exodus ==
 
#Just because you can write C in C++ doesnt mean you should! Dont include C libraries and you wont be able to.
#Just because you can write C++ in Exodus programs doesnt mean you should! Dont include C++ libraries and you wont be able to.


if you are only familiar with c then c++ has some improvements for examples like you can declare your variables at the point they are used (and not at the top of the routine like c)
if you are only familiar with c then c++ has some improvements for examples like you can declare your variables at the point they are used (and not at the top of the routine like c)

Revision as of 20:10, 17 October 2010

The following is just a scrap pad of ideas to be incorporated in documentation

C++ exodus

  1. Just because you can write C in C++ doesnt mean you should! Dont include C libraries and you wont be able to.
  2. Just because you can write C++ in Exodus programs doesnt mean you should! Dont include C++ libraries and you wont be able to.

if you are only familiar with c then c++ has some improvements for examples like you can declare your variables at the point they are used (and not at the top of the routine like c)

unlike many modern languages c++ retains the infamous goto statement making porting from pick basic much easier. you have to avoid declaring new variables (var xyz) within the scope of the jump but this is easily accomplished by moving the declaration just above the jump zone.

better to put print(a, " ", b) than print(a ^ " " ^ b) because it is faster to do three outputs instead of two concatenations and one output

The following will compile but give throw "unassigned variable" on execution.

var foo=foo.sum();

strings must all be wrapped in " double quotes and single quoted strings are not allowed - except for single character strings. To puta double quote character within a string you must prefix them with \ to be like \".

swap, match and index have an additional argument that can contain r for regular expression and ri for case insensitive regular expression. i by itself doesnt work at the moment.

note the double backslashes in regular expression strings (until we get the R string prefix for "raw strings"

if (word.match("\\d+","ri")) ...

using the results or comparisons as 1 or 0 is not supported so "xxx+(a eq b)" wont compile.

you could put the ugly "xxx+(a eq b?1:0)" but recoding is probably better ...eg "if (a eq b) xxx+=1;"

better than pick basic

there are a series of compromises in exodus design which are forced by the limitations of c++ syntax. with time you get used to these.

offset against the disadvantages are many advantages at multiple levels:

local subroutines have a) parameters and b) local variables

gosub/return style local subroutines can have parameters and their variables are private by nature. this allows monolithic programming with many subroutines in one file/compilation unit without all variables being global.

one way of looking at this is that you can now put all your associated external routines in the main program text and are not required to use separate edit/compile to get parameterisation and private variables.

another way of looking at this is that what used to be your external functions and subroutines (but are now are implemented as internal functions) now have access to the global variables of your main program without requiring setup of common variables.

many functions and subroutines per file

pick only allows one function or subroutine per file. c++ is happy with many.

in some cases, editing and compiling groups of associated subroutines and functions in a single file makes it easier to manage your source code base.

faster conditional expressions

the AND and OR operators "short circuit" ie do not evaluate the right hand side if the evaluation of the left hand side predetermines the final result. For example, in the evaluation of "aa() and bb()", if aa() returns false then bb() will never be evaluated.

multiple programming paradigms

object orientated programming - if you want. functional programming - if you want. procedural programming - if you want.

for application level programming you can follow a standard of only allowing the exodus header file to be included. not including any of the traditional c++ headers like <iostream>, <string>, <vector> etc. will prevent programmers getting out of their control. If you want to merge pick with traditional c++ programming you are free to include and header files you like. Just make sure to include the exodus.h AFTER all the other headers.

low level programming and interfacing with other languages

many operating system utilities can be programmed directly in c++ allowing you to do system programming in pick basic syntax

most languages allow interfacing at the C/C++ level so exodus can be used for this directly without depending on any interfaces.

OS level command shell

the bash command line shell treats various characters specially including " ' ( ) < > $ ! and others. You must escape/prefix them by \ to stop bash from messing with them.

so

list file with field = "xxx" (S)

becomes

list file with field = \"xxx\" \(S\)

or you can quote everything after the first word of the command. Single quotes allows all special characters to be used. Double quotes allows bash to continue to mess around with special cdoing macro expansion etc.

list 'file with field = "xxx" (S)'

list "file with field = 'xxx' (S)"

exodus allows the use {} can be used for () brackets if at the end of the command