15 Replies - 1041 Views - Last Post: 05 March 2012 - 09:03 AM
#1
Is 'Option Base #' a good thing?
Posted 24 February 2012 - 03:43 PM
(optional)
Bald statement: True should ONLY be a +1. (positive only)
I almost always create my variables in base 1. The only other time I could think of is when I create my own stack or recursion routines which would have to be two different sets of variables (basically 2 stacks). I've never mixed the two, sounds ugly (shiver).
The difference/difficulty is only in remembering which are zero based or the ones that I create which are almost always 1 based.
Who likes zero based and who likes one based arrays?
Replies To: Is 'Option Base #' a good thing?
#2
Re: Is 'Option Base #' a good thing?
Posted 24 February 2012 - 03:54 PM
Why do you prefer One-Base Indexing?
Show us an example of the code you write.
This post has been edited by AdamSpeight2008: 24 February 2012 - 03:55 PM
#3
Re: Is 'Option Base #' a good thing?
Posted 24 February 2012 - 04:22 PM
dim variable(20) as integer 'rem I know long has no processor penalty I just like int
for i=1 to 16 'less than max '16 is likely a variable
'....execute stuff
next
A benefit I like is to use the zero element of the array to hold a last used index or element.
That makes for tighter code. I have written working code of 8 bytes. (boast smiley)
#4
Re: Is 'Option Base #' a good thing?
Posted 24 February 2012 - 04:54 PM
Rhymer, on 25 February 2012 - 12:22 AM, said:
This only works for Numeric Types
For the follow examples, that strategy won't work.
Dim myString(9) As String Dim myClasses(9) As ComplexType
If everything is 0-based you don't have remember, if the collection is or isn't.
One based Arrays are a was of memory space, if the type is large in bytes.
Plus it's not that hard to write a "wrapper" around the array, which implements Last Accessed Index.
This post has been edited by AdamSpeight2008: 24 February 2012 - 04:55 PM
#5
Re: Is 'Option Base #' a good thing?
Posted 29 February 2012 - 04:17 PM
Quote
No, it works for any array that does not hold a value in its 0'th (zero'th) element.
Quote
That is the problem with LOTS of VB's controls. I wish they would have a zero based array but START their element insertion at 1 (one).
Quote
I absolutely agree.
and especially as the array and its type gets bigger as you say too.
Quote
I'll have to admit your class 'wrapper' is over my head.
Bold statement: Not counting commenting (which can grow quite large), about a minimum1/3 of a (any size?) ROBUST program will be used for: check for errors, incorrect type input, divide by zero, beyond type limit (either in value or length or both), assure proper directory and file name and other non-MEAT program material overhead.
I also have trouble with OOP or/and encapsulation. I understand the concept though but not their difference. I suppose my scope is limited but I learn and, more importantly, I have fun while I write programs.
Bold statement: implementing your own stack is better than Llambda (Lisp)
#8
Re: Is 'Option Base #' a good thing?
Posted 01 March 2012 - 05:06 PM
Rhymer, on 24 February 2012 - 03:43 PM, said:
Just thought I'd tackle this one by making it even more benign. You want true to only be one? Define it as such. You want true to be 0? You can do that. You want true to be 3/2? I can totally do that.
Point being: True and False are definitions that you can change to whatever you want in any coding language. However, the logical definition of true in our case is !0. It is not any number, it is not any positive number, it is not any negative number, it is: Any number BUT 0. That's the only case for true.
You know what False's definition is? It's !True.
So in other words, in programming.
True: !0
False: !True (!(!0))
Rhymer, on 24 February 2012 - 03:43 PM, said:
Zero, because one based arrays are an annoyance that should burn. Bytes start at 0, Binary starts at 0, arrays should start at 0 because the first number in binary is not 1, it's 0.
#9
Re: Is 'Option Base #' a good thing?
Posted 01 March 2012 - 06:05 PM
in VB6 when you declare arry like this:
Dim Arr(5)
it will hold 6 elements (0,1,2,3,4,5)
but with Option base 1 turned on it will hold 5 (1,2,3,4,5)
#10
Re: Is 'Option Base #' a good thing?
Posted 01 March 2012 - 06:15 PM
We talking a modern vb.net.
#11
Re: Is 'Option Base #' a good thing?
Posted 01 March 2012 - 07:55 PM
#12
Re: Is 'Option Base #' a good thing?
Posted 02 March 2012 - 11:13 AM
Neku, on 01 March 2012 - 06:05 PM, said:
in VB6 when you declare arry like this:
Dim Arr(5)
it will hold 6 elements (0,1,2,3,4,5)
but with Option base 1 turned on it will hold 5 (1,2,3,4,5)
...No, either one holds 5. Arr(5) is an array of five items regardless of starting at 0 or 1.
#13
Re: Is 'Option Base #' a good thing?
Posted 03 March 2012 - 02:25 PM
ccubed, on 02 March 2012 - 01:06 AM, said:
You know what False's definition is? It's !True.
So in other words, in programming.
True: !0
False: !True (!(!0))
Your premise is only True if your doing Value Comparisons.
Which is a differet operation Not-Equal To to Not
True:= Value ≠ 0 False:= Value = 0
Which holds true for values, but not on a strictly binary view.
Computer languages (Assembly and up) use in general Two-Complements representation for Integer Numbers.
The value for
False:= 0 True:= -1
Boolean Values are of represent by the bits in the word size of the processor. 32bits system it int32.
-1 since that is result of Flipping (NOT) all of the bits on Zero (in 2-Complement representation.) At a logic gate level is simple to reduce this to 1 or 2 gates.
False:= Nor( B0 ... Bn)
True:= And( B0 ... Bn)
So when you say Not Zero, which do mean?
This post has been edited by AdamSpeight2008: 03 March 2012 - 02:31 PM
#14
Re: Is 'Option Base #' a good thing?
Posted 03 March 2012 - 05:59 PM
#15
Re: Is 'Option Base #' a good thing?
Posted 05 March 2012 - 08:21 AM
|
|

New Topic/Question
Reply



MultiQuote






|