Skip to content
rdbyk edited this page Mar 24, 2018 · 133 revisions

Hints for Efficient Balisc/Scilab 6.x Coding

  • Use type instead of typeof, whenever possible.
  • Use nargin, nargout instead of argn.
  • Use x==[] instead of isempty(x), whenever possible.
  • Use x<>[] instead of ~isempty(x), whenever possible.
  • Use issquare instead of size, whenever possible.
  • Use length(x) instead of size(x,'*'), whenever possible.
  • Use x(length(x)) or x(size(x,'*') instead of x($), whenever possible.
  • Use &&, || instead of &, |, whenever possible.
  • Use ~(A || B) instead of ~A && ~B (cf. De Morgan's Laws).
  • Use ~(A && B) instead of ~A || ~B (cf. De Morgan's Laws).
  • Use execstr instead of evstr, whenever possible.
  • Use tokens instead of strsplit, whenever possible.
  • Use matrix(A,length(A),1) instead of A(:), whenever possible.
  • Use A.B instead of A("B") or getfield("B",A), whenever possible.
  • Use ones(m,n).*.A instead of repmat(A,m,n), whenever possible.
  • Use size(x)==1 instead of isscalar(x), whenever possible.
  • Use A=[] instead of A(:)=[], whenever possible.
  • Use .* and ./ instead * of / for integer types, whenever possible.
  • Use a & b instead of bitand(a,b), whenever possible.
  • Use a | b instead of bitor(a,b), whenever possible.
  • Use (a | b) & ~(a & b) instead of bitxor(a,b), whenever possible.

"Fifty" Ways to Kill Your Scilab 6.x (and Sometimes even Balisc)

  1. %t./%f
  2. sleep 1
  3. 1./int8(0)
  4. sparse(1,1)
  5. mprintf("%%")
  6. msprintf("%%")
  7. triu([%s+%i,1;1,1])
  8. strsubst("","","","r")
  9. surf(1:2e3,1:2e3,(1:2e3)'*(1:2e3))
  10. f=gcf();xdel();save(TMPDIR+"/f.sod","f")

to be continued ...

Predefined (and Protected) Variables Unique to Balisc

  • %balisc

    • Useful to check whether it is Balisc, e.g. use exists("%balisc").
    • Returns a single integer (e.g. 0), which indicates the version of Balisc

Functions Unique to Balisc

  • isprotected, protect, unprotect

    • Provide an interface to the protection mechanism of arbitrary variables
    • They supersede predef and are easy to use (cf. #420)

Clone this wiki locally