Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
option explicit
#11
Quote:How many of you guys use this?

Why do you use it if you do?

#1 most prevelent and nasty bug that you cant see is a typo, Option _Explicit prevents that.

So I use it when the code I wrote should work and it doesn't.

Udpdate: Option _Explicit helps find typos, I miswrote, it does not prevent typo's. My first step in tracking down bugs is this!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#12
There's also a middle ground command, OPTION _EXPLICITARRAY: https://qb64phoenix.com/qb64wiki/index.p...LICITARRAY

Normal variables are unaffected, but it forces you to DIM all your arrays - which you were almost certainly going to do anyway. Helps catch typos that can be very hard to track down with basically no downsides.
Reply
#13
Well, thanks to Unseen for asking the question.  I've seen it people's code and thought ("what's that doing there").  So, now I understand.
Reply
#14
I'm slightly dyslexic and have a real tendency to make errors like 

Code: (Select All)
DIM SHARED NumberofUglyMonsters AS LONG


REM Then later in the code

PRINT " There's ";NumUglyMonsters;" Chasing you !"

    Then pulling out what little is left of my hair trying to figure out why the Number is wrong !

_option explicit Saves me from that kind of error !
Reply
#15
(01-23-2026, 02:55 AM)Unseen Machine Wrote: How many of you guys use this?

Why do you use it if you do?

always. because it helps catch errors.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#16
I don't typically use it when doing little one off algorithms, but I've been warming up to OPTION _EXPLICIT more and more when writing big projects, where I really don't want to be dealing with typo errors in dozens of subroutines that are recycling local variables. It mostly catches when I do screw ups like using x and x% interchangeably. In fact, it's just about the first thing I will type in when starting a new large project. It's a lot easier to do it up front, and accept that discipline, than to add it later.

If I were to use any big variable names like SuperCalifragiVariable%, then I'd use it there as well. Those are the bugs that will drive you mad for hours without that tool.

I also find it helpful when I'm going back to clean up and optimize my algorithms. When I see a whole raft of DIMs at the head of a SUB or FUNCTION I start looking for ways to cut the number down while achieving the same results.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#17
Between this thread, the discussion on WITH ... END WITH, and a few others where we debated different approaches or aspects of coding, it is evident to me that there is no "one size fits all" when it comes to programming practices. Everyone has their own take. So it can be nice to have options to do things in different ways. It can complicate things from a support standpoint or if someone else has to work with code done with a different style, and that's the trade-off. But I like these threads, it gives us a chance to debate and be exposed to different approaches and maybe learn something. Carry on!
Reply
#18
My biggest shortcoming with this subject is with plural string names, like:

TrackingNumber$  vs  TrackingNumbers$

Sometimes I will type that name without the 's' when it belongs there.  You stare at the code and just don't see it...
Reply
#19
(01-25-2026, 12:40 PM)dano Wrote: My biggest shortcoming with this subject is with plural string names, like:

TrackingNumber$  vs  TrackingNumbers$

Sometimes I will type that name without the 's' when it belongs there.  You stare at the code and just don't see it...
That's a good one - I thought about this and decided to keep it singular. One less character to type (woo hoo) and the majority of the usage is in referencing a single element - MyItem(index) - so we're talking about one item. So I figure that singular makes sense.
Reply
#20
I think this explains it all

https://www.youtube.com/watch?v=EFmxPMdBqmU

Unseen
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An option to not need _GL sub Unseen Machine 4 1,054 10-17-2025, 02:41 PM
Last Post: Unseen Machine
  Found a BUG with the QB64 editor compiled with the -O3 option Coolman 2 821 06-02-2022, 06:27 PM
Last Post: Coolman
  A preview of a new QB64 option SMcNeill 12 2,678 05-04-2022, 01:11 PM
Last Post: DSMan195276

Forum Jump:


Users browsing this thread: