Is 'Option Base #' a good thing?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1765 Views - Last Post: 05 March 2012 - 09:03 AM

#1 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Is 'Option Base #' a good thing?

Posted 24 February 2012 - 03:43 PM

Bald statement: Option base could be used in ANY programming language but should default to base 1.
(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?


Is This A Good Question/Topic? 0
  • +

Replies To: Is 'Option Base #' a good thing?

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Is 'Option Base #' a good thing?

Posted 24 February 2012 - 03:54 PM

Zero Based

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

Was This Post Helpful? 0
  • +
  • -

#3 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: Is 'Option Base #' a good thing?

Posted 24 February 2012 - 04:22 PM

I need 2 or 5 or 60 or 199 ...Integer good for 32,768 (-1)

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)

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Is 'Option Base #' a good thing?

Posted 24 February 2012 - 04:54 PM

View PostRhymer, on 25 February 2012 - 12:22 AM, said:

A benefit I like is to use the zero element of the array to hold a last used index or element.


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.

Spoiler

This post has been edited by AdamSpeight2008: 24 February 2012 - 04:55 PM

Was This Post Helpful? 0
  • +
  • -

#5 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: Is 'Option Base #' a good thing?

Posted 29 February 2012 - 04:17 PM

Quote

This only works for Numeric Types

No, it works for any array that does not hold a value in its 0'th (zero'th) element.

Quote

If everything is 0-based you don't have remember

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

One based Arrays are a was of memory space

I absolutely agree. :bananaman:
and especially as the array and its type gets bigger as you say too.

Quote

it's not that hard to write a "wrapper" around the array

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.

Why would, ahem. When would it be beneficial to use a class and (drum roll please), why?
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)



Was This Post Helpful? 0
  • +
  • -

#6 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4517
  • View blog
  • Posts: 28,417
  • Joined: 21-March 01

Re: Is 'Option Base #' a good thing?

Posted 29 February 2012 - 05:03 PM

Posted Image
Was This Post Helpful? 1
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Is 'Option Base #' a good thing?

Posted 29 February 2012 - 05:20 PM

All the standard .net collections are Zero Indexed based.
It's flexible enough that if you want One-Indexed based you can be implementing the correct interface.
Indexers
Was This Post Helpful? 0
  • +
  • -

#8 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 162
  • View blog
  • Posts: 1,409
  • Joined: 13-June 08

Re: Is 'Option Base #' a good thing?

Posted 01 March 2012 - 05:06 PM

View PostRhymer, on 24 February 2012 - 03:43 PM, said:

Bald statement: True should ONLY be a +1. (positive only)


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))

View PostRhymer, on 24 February 2012 - 03:43 PM, said:

Who likes zero based and who likes one based arrays?[/size]


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.
Was This Post Helpful? 0
  • +
  • -

#9 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Is 'Option Base #' a good thing?

Posted 01 March 2012 - 06:05 PM

but sometimes base 1 is needed
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)
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Is 'Option Base #' a good thing?

Posted 01 March 2012 - 06:15 PM

vb6 is dead, it's hanging around like a undead zombie.

We talking a modern vb.net.
Was This Post Helpful? 1
  • +
  • -

#11 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4517
  • View blog
  • Posts: 28,417
  • Joined: 21-March 01

Re: Is 'Option Base #' a good thing?

Posted 01 March 2012 - 07:55 PM

oh man i got my threads all confused. i thought someone deleted my puppy picture and it was just in a different thread. OH WELL MORE PUPPIES FOR EVERYONE.
Was This Post Helpful? 1
  • +
  • -

#12 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 162
  • View blog
  • Posts: 1,409
  • Joined: 13-June 08

Re: Is 'Option Base #' a good thing?

Posted 02 March 2012 - 11:13 AM

View PostNeku, on 01 March 2012 - 06:05 PM, said:

but sometimes base 1 is needed
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.
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Is 'Option Base #' a good thing?

Posted 03 March 2012 - 02:25 PM

View Postccubed, on 02 March 2012 - 01:06 AM, said:

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))


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

Was This Post Helpful? 0
  • +
  • -

#14 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 162
  • View blog
  • Posts: 1,409
  • Joined: 13-June 08

Re: Is 'Option Base #' a good thing?

Posted 03 March 2012 - 05:59 PM

View PostAdamSpeight2008, on 03 March 2012 - 02:25 PM, said:

So when you say Not Zero, which do mean?


Value Comparisons which is what I assumed the OP was talking about.
Was This Post Helpful? 0
  • +
  • -

#15 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Is 'Option Base #' a good thing?

Posted 05 March 2012 - 08:21 AM

Why the hell is anyone trying to have a constructive programming discussion in the Caffeine Lounge? I'm moving this to the Cubicle.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2