Author Topic: Serious Versus Scripting Languages  (Read 4569 times)

JRS

  • Guest
Serious Versus Scripting Languages
« on: November 12, 2010, 11:06:35 pm »
Quote
There's no good reason to build systems in the "serious" languages any more. Build your system in a soft language, profile it, then replace the bottlenecks with "serious" snippets. The result is something that is vastly more flexible and maintainable, but which performs exactly the same.

Serious Versus Scripting Languages

Has scripting languages changed how maintainable applications are written?

« Last Edit: November 25, 2010, 12:58:10 am by JRS »

JRS

  • Guest
Re: Serious Versus Scripting Languages
« Reply #1 on: November 22, 2010, 03:18:12 pm »
In an effort to expand on this concept a bit, here is an example ScriptBasic extension module using BCX Universal (Ubuntu 32) to create the Linux shared object. (libtrial.so) This allows you to use ScriptBasic to get the meat of your project defined and use BCX to create dynamic called C functions to increase performance in sections of your code. In the end, your are able to compile your project to a small footprint executable (wrapped PCODE in C) and link dynamically to SB's runtime and extensions.

trial.bas
Code: Text
  1. $DLL
  2. $EXECON "-I/usr/src/scriptbasic"
  3.  
  4. #include <basext.h>
  5.  
  6. 'besVERSION_NEGOTIATE
  7. FUNCTION versmodu(Version as integer, pszVariation as string, ppModuleInternal as void ptr ptr) as integer export
  8.   FUNCTION = INTERFACE_VERSION
  9. END FUNCTION
  10.  
  11. 'besSUB_START
  12. FUNCTION bootmodu(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
  13.   DIM pEo AS pExecuteObject
  14.   DIM pL AS long ptr
  15.   besMODULEPOINTER = besALLOC(sizeof(long))
  16.   IF besMODULEPOINTER = NULL THEN FUNCTION = 0
  17.   pL = (long *)besMODULEPOINTER
  18.   *pL = 0
  19.   FUNCTION = 0
  20. END FUNCTION
  21.  
  22. 'besSUB_FINISH
  23. FUNCTION finimodu(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
  24.   DIM pEo AS pExecuteObject
  25.   FUNCTION = 0
  26. END FUNCTION
  27.  
  28. 'besFUNCTION
  29. FUNCTION trial(pSt as pSupportTable, ppModuleInternal as void ptr ptr, pParameters as pFixSizeMemoryObject, pReturnValue as pFixSizeMemoryObject ptr) as integer export
  30.  
  31.   DIM pEo AS pExecuteObject
  32.   DIM pL AS long ptr
  33.  
  34.   PRINT "Function trial was started..."
  35.   pL = (long *)besMODULEPOINTER
  36.   (*pL)++
  37.   besRETURNVALUE = besNEWMORTALLONG
  38.   LONGVALUE(besRETURNVALUE) = *pL
  39.  
  40.   PRINT "Module directory is ";(char*)besCONFIG("module")
  41.   PRINT "dll extension is ";(char*)besCONFIG("dll")
  42.   PRINT "include directory is ";(char*)besCONFIG("include")
  43.  
  44.   FUNCTION = 0
  45. END FUNCTION
  46.  

ttbcx.sb
Code: Text
  1. DECLARE SUB trial ALIAS "trial" LIB "libtrial"
  2.  
  3. modptr = trial()
  4.  
  5. PRINT "Module Pointer = ",modptr,"\n"
  6.  

Results

root@Laptop:/home/jrs/bcx# scriba ttbcx.sb
Function trial was started...
Module directory is /usr/local/lib/scriba/
dll extension is .so
include directory is /usr/share/scriba/include/
Module Pointer = 1
root@Laptop:/home/jrs/bcx#

A good example of how a C function can speed things up dramatically is the use of the SPLITA() function. You will see what I mean if you try to take a delimited string and build an array from it with a loop structure compared to using SPLITA() to do it.
« Last Edit: November 22, 2010, 09:33:16 pm by JRS »