Results 1 to 2 of 2

Thread: C-style #DEFINEs

Share/Bookmark
  1. #1

    C-style #DEFINEs

    Consider this code:
    Function HALQuote(myname as string) as string
    return "I'm sorry, "& myname &", I'm afraid I can't do that."
    end function
    
    When "HALQuote(*)" is evaluated, thinBasic has to bear the runtime costs of one function call, checking the argument's type, allocating two strings, and copying the argument's value twice. Compare that to the following:
    '#define HALQuote(myname) "I'm sorry, "& myname & ", I'm afraid I can't do that."
    
    When this "HALQuote(*)" appears in source code, thinBasic only needs to allocate one string and copy the argument's value once, without calling a function and without checking types. Although there will be some increased cost in preprocessing time or even runtime, depending on how this concept gets implemented in thinBasic. Also, macros like that must be used carefully, but I think this would be a nice option to have.
    Last edited by Vandalf; 06-03-2017 at 19:25. Reason: style

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,063
    Blog Entries
    2
    Rep Power
    10
    I'm sorry, Vandalf, I'm afraid I can't do that.

    sorry, Just joking a bit.

    Considering thinBasic fully interpretative engine ... this would not speed thinBasic execution unless that function is executed some many thousands of times.
    Macros is something I tried to implement in the past but never had enough time to dedicate to them.

    thinBasic has a lot of other functions able to simplify work.
    For example your example can be written in something like that:
    string MyName = "Vandalf"msgbox 0, Expand$("I'm sorry, $myName, I'm afraid I can't do that.")
    '---Or
    msgbox 0, StrFormat$("I'm sorry, {1}, I'm afraid I can't do that.", MyName)
    
    http://www.thinbasic.com/public/prod...ml?expand$.htm
    http://www.thinbasic.com/public/prod...strformat$.htm

    Anyway I understand what you mean, I will add to my ToDo list.

    Thanks for testing thinBasic.
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Tab control style
    By zlatkoAB in forum UI (User Interface)
    Replies: 1
    Last Post: 18-10-2013, 22:07
  2. MLGRID Style and ExStyle Options
    By RADRAD in forum UI (User Interface)
    Replies: 2
    Last Post: 14-05-2013, 20:55
  3. Dialog style updates
    By Michael Clease in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 08-11-2007, 07:52
  4. Coding Style Ideas
    By kryton9 in forum thinBasic General
    Replies: 2
    Last Post: 13-12-2006, 21:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •