Author Topic: QB64 REPORT S01E01: "OPTION _EXPLICIT"  (Read 8089 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
« Reply #15 on: June 11, 2020, 10:23:14 am »
  • Best Answer
  • Here is a comment on OPTION _EXPLICIT in comparison to other languages.  Someone mentioned how setting option explicit takes away the convenience of quick and easy introduction of variables for debugging and development.  Other languages that force variable declaration will allow the declaration of local variables within a block such as a FOR or IF block.  For example, in QB64:

    Code: QB64: [Select]
    1. IF 1 = 1 THEN
    2.     DIM z AS INTEGER
    3.     z = 3
    4.     ? z
    5. ? z
    6.  

    the code will output

    Code: [Select]
    3
    3

    but the equivalent code in, say, a language such as C or freebasic will throw the error on the last print statement, variable not declared.  In QB64, variables can only be local to SUBs or FUNCTIONs.  I think this is an important difference because it means that you don't necessarily have to pre-plan every single variable and it is a lot more natural to introduce temporary variables within deep sections of code that are then released.

    A major example of this is FOR loops, in C you'd often see the declaration in the for itself:  for (int i=0; i<10; i++).  And in freebasic:
    Code: [Select]
    for i as integer = 0 to 9
        ? i
    next
    ? i 'would throw an error

    For something like traversing arrays or just repeating statements you probably don't want a global 'i'.

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #16 on: June 11, 2020, 11:58:55 am »
  • Best Answer
  • Speaking of OPTION _EXPLICIT, when I am NOT using it, I did stumble upon the same trick Fellippe mentioned in broadcast. To use camel where it is first seen or used in program (that could be a little tricky) and then ever after use all lowercase, if the varaible or subroutine does not change to camel, I know I have a typo, very convenient when you don't use the OPTION of explicit declarations.

    There is at least one place that this little trick does not work and that is your quiz for today ;-))

    Update: Quiz continues

    Honestly I can't remember exactly what that case is to state it in words, I am completely positive I will know it when I see it. I am remembering it as is something enclosed in parenthesis.
    « Last Edit: June 12, 2020, 10:37:58 am by bplus »

    FellippeHeitor

    • Guest
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #17 on: June 12, 2020, 10:37:20 am »
  • Best Answer
  • Thanks @Dimster and @Dav! Glad you guys enjoyed this new material.

    We're hoping to come up with a new episode soon, still deciding on frequency.

    @_vince I honestly had no idea variables would have block scope in those languages as you mentioned. You learn something new every day. I must say I usually do my DIMming as I go, so I'll end up with code like you showcased, with variables being declared in IF blocks or the like, even though I don't have intention of containing the declarations. I will eventually have a DIM i AS LONG at the beginning of programs and SUBs, so that I don't have to bother with other variable names for simple iterations.

    @bplus camelCase was my default alternative before OPTION _EXPLICIT was introduced in the language. Now I can't live without it for bigger projects.

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #18 on: June 12, 2020, 10:42:27 am »
  • Best Answer
  • Ah @FellippeHeitor , do you remember the exception to the rule where the camel case version won't be recognized by IDE even though properly DIM'd?

    Another little problem is if the variable is only one letter, syllable or word, you'd have to hump the first Letter which is not my habit.
    « Last Edit: June 12, 2020, 10:43:44 am by bplus »

    FellippeHeitor

    • Guest
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #19 on: June 12, 2020, 10:43:38 am »
  • Best Answer
  • Ah @FellippeHeitor , do you remember the exception to the rule where the camel case version won't be recognized by IDE even though properly DIM'd?

    Are you talking about when you're working on an $INCLUDE module?

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #20 on: June 12, 2020, 10:46:30 am »
  • Best Answer
  • Are you talking about when you're working on an $INCLUDE module?

    No in regular main code or subroutine. It might be REDIM _PRESERVE of an array name or variable ubound or lbound or it might be with UDT items.
    « Last Edit: June 12, 2020, 10:47:47 am by bplus »

    FellippeHeitor

    • Guest
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #21 on: June 12, 2020, 10:47:34 am »
  • Best Answer
  • Ah, no. Only case it won't work under normal conditions is when it's used in LBOUND() or UBOUND() calls.

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #22 on: June 12, 2020, 10:53:36 am »
  • Best Answer
  • Ah Fellippe's got it!

    Code: QB64: [Select]
    1. REDIM Array(0)
    2.  
    3. REDIM _PRESERVE Array(LBOUND(array) TO 20)
    4.  

    Offline OldMoses

    • Seasoned Forum Regular
    • Posts: 469
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #23 on: June 12, 2020, 01:09:36 pm »
  • Best Answer
  • I've been sitting in the corner, wearing my dunce cap lately, since some of my coding is running up against the limits of my math chops. So I haven't been around as much, spending much of my online time being tutored by Youtube's "Professor Leonard".

    Imagine my delight at popping in and finding this podcast. Thanks for doing this, I'll be listening with great interest.

    I've used OPTION _EXPLICIT for a program or two, but not exclusively. Interesting discussion.

    Offline Petr

    • Forum Resident
    • Posts: 1720
    • The best code is the DNA of the hops.
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #24 on: June 12, 2020, 02:48:32 pm »
  • Best Answer
  • I'm just listening to your conversation, I'm so glad to hear you. Unfortunately, I understand little, I have significant shortcomings in spoken English.

    Offline TempodiBasic

    • Forum Resident
    • Posts: 1792
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #25 on: June 13, 2020, 06:54:13 am »
  • Best Answer
  • about podcasting
    I'm new to this way of communication... but they can have subtitle as youtube? In other words if I hear a audio file in the browser it is possible to see subtitle as youtube let do (subtile loaded or selfgenerated by software),  I remember that it works in the same manner the RDS of radio station.

    Who can give me these informations?
    Programming isn't difficult, only it's  consuming time and coffee

    FellippeHeitor

    • Guest
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #26 on: June 13, 2020, 08:29:39 am »
  • Best Answer
  • Here's the latest episode hosted on YouTube. You can enable closed captions (the CC button) and see YouTube's auto-generated subtitles. Not the same as a human would do but it's pretty good.

    Offline TempodiBasic

    • Forum Resident
    • Posts: 1792
      • View Profile
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #27 on: June 13, 2020, 06:44:29 pm »
  • Best Answer
  • Thanks Fellippe
    so I must understand that for get subtitle original or generated by machine it is good to hear on youtube.
    Programming isn't difficult, only it's  consuming time and coffee

    FellippeHeitor

    • Guest
    Re: QB64 REPORT S01E01: "OPTION _EXPLICIT"
    « Reply #28 on: June 15, 2020, 08:29:22 pm »
  • Best Answer
  • « Last Edit: June 15, 2020, 08:32:15 pm by FellippeHeitor »