Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. From where should the index start?

From where should the index start?

Scheduled Pinned Locked Moved The Lounge
questionphpdatabasedesignhelp
114 Posts 31 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Wjousts

    nikunjbhatt84 wrote:

    the function can return Zero and thus making the IF condition false.

    No, because using zero as false is dangerous. That's why strongly typed languages (such as C#) have an actual bool class. So you don't accidentally mix up using an int as a bool when it was supposed to be an int.

    N Offline
    N Offline
    Nikunj_Bhatt
    wrote on last edited by
    #21

    I mostly like loosely typed languages, it decreases programming code. When I program, I know that what type of value the function will accept and return, and I can trap it in anyway by the language's features. So I don't need to know the exact data type.

    W 1 Reply Last reply
    0
    • W Wjousts

      nikunjbhatt84 wrote:

      the function can return Zero and thus making the IF condition false.

      No, because using zero as false is dangerous. That's why strongly typed languages (such as C#) have an actual bool class. So you don't accidentally mix up using an int as a bool when it was supposed to be an int.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #22

      This was my exact thought when I saw he wrote this. When I first started in C# (from C++), this was a feature that I was OOOHHHHH SOOOO HAPPPY with. I thought, wow! How many hours have I spent debugging code that was setting a value to zero when I meant to check the value? [EDIT] This deserves a 1 because why??? Oh and no commment either...

      Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

      1 Reply Last reply
      0
      • B BobJanova

        It's pretty difficult to work without lists, and you need to get things out of a list. Unless you count '1', '2' etc as 'meaningful symbols' in which case you still have indexing really. You can help a lot by having enumerations (foreach doesn't require indexing) and array-based functionality (so you can add two vectors without needing to loop around them), but a lot of real world problems would be much more difficult without being able to look things up by index in arrays or collections.

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #23

        BobJanova wrote:

        It's pretty difficult to work without lists, and you need to get things out of a list.

        Iteration doesn't require indexing to be exposed. If I need to index something by a hard-coded value, then that's bad. If it's a computed value (like a portion of a string) then it should be able to be represented in a better way, again hiding the details of indexing.

        BobJanova wrote:

        but a lot of real world problems would be much more difficult without being able to look things up by index in arrays or collections.

        For example? Even matrix operations can be coded with more clarity if the matrix array could be mapped onto a structure so one didn't have to write "[0]". Marc

        My Blog

        B 1 Reply Last reply
        0
        • N Nagy Vilmos

          nikunjbhatt84 wrote:

          In modern programming (languages), importance of pointer is decreasing.

          What is an 'object'? Once you've got to the machine code, it is a lot of data held in memory location. How do you think the machine knows where to find that data? #ping# using pointers! Just because we don't call them pointers in the code does not mean they don't exist. Every object reference compiles down to a memory pointer. You are showing a huge level of ignorance if you really believe pointers are not important. A big mistake being made today is the lack of knowledge of the low level. By studying a bit of machine code you will see very quickly how the computer actually processes a program. Go study the Von Neumann architecture[^] to understand how a computer works. The less memory you use, the faster things can load. The less process steps you use, the faster things can run. Wow! Computing-101 and you don't have a fucking clue why it is important!


          Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

          N Offline
          N Offline
          Nikunj_Bhatt
          wrote on last edited by
          #24

          I know that programming languages are highly depending on pointers. You know that what an Object is, but do you know Why the Object is introduced?. Languages are made more and more feature rich to let programmers make solutions by as much less code as possible. What I mean to say by "In modern programming (languages), importance of pointer is decreasing." is, nowadays, programmers do not need to deal with pointers directly, and these increases productivity and actually much higher reliability of code.

          N 1 Reply Last reply
          0
          • G gumi_r msn com

            If it were to be a clean start, I'd definitely have an index start with '1'. As to why, the reason is simple, it's they way we count since we're 2 years old. How does a small kid learn his numbers? I find it hard to imagine some little boy counting 0, 1, 2, ... We start at 1, and do so even when we are grown ups. Zero based indexing is just a legacy of array pointers and offsets. It doesn't help in any useful way in modern languages, it only makes things more confusing, its cumbersome to referrence the last item of an array and it doesn't agree with how we normally count things; when you go to a grocery store and you ask for 10 apples, you expect to get ten apples, them being apple nº1, apple nº2, ... , apple nº10, definitely not apple nº0, ..., apple nº9. So why when you "buy" a 10 item array you get the latter and not the former? WTF?!?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #25

            gumi_r@msn.com wrote:

            How does a small kid learn his numbers? I find it hard to imagine some little boy counting 0, 1, 2, ...
            We start at 1, and do so even when we are grown ups.

            You eventually teach children the concept of 0. It is something you must teach them. However, we need not teach computers the concept of 0. The fact is if a person is counting objects they do use 0, it is just omitted. For example, I have 6 apples all lined up. I want to count them. Now I am a smart chap so I can just look and say there are 6 apples. Someone else may need to at the minimum count by 2's (omitting the odds). And yet another will count from 1 to 6 (omitting the 0). The fact is all counting of objects (which is what your comparison is about) start with 0, we just choose to omit for efficiency. Well starting the index at 1 for computers is inefficient because the fact is 0 exists, and the computer knows that. If you start at 1 you now have to proram at the base level speacial instructions for it to understand 0. Why would you do that? So you example of going to the grocery store. What are you going to do when the clerk hands you 1 Orange, 1 watermelon and 1 zuchini?? "Hey I didn't ask for these!" "Oh sorry, you forgot to say 0 of those items..."

            Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

            G B R 3 Replies Last reply
            0
            • L Lost User

              gumi_r@msn.com wrote:

              How does a small kid learn his numbers? I find it hard to imagine some little boy counting 0, 1, 2, ...
              We start at 1, and do so even when we are grown ups.

              You eventually teach children the concept of 0. It is something you must teach them. However, we need not teach computers the concept of 0. The fact is if a person is counting objects they do use 0, it is just omitted. For example, I have 6 apples all lined up. I want to count them. Now I am a smart chap so I can just look and say there are 6 apples. Someone else may need to at the minimum count by 2's (omitting the odds). And yet another will count from 1 to 6 (omitting the 0). The fact is all counting of objects (which is what your comparison is about) start with 0, we just choose to omit for efficiency. Well starting the index at 1 for computers is inefficient because the fact is 0 exists, and the computer knows that. If you start at 1 you now have to proram at the base level speacial instructions for it to understand 0. Why would you do that? So you example of going to the grocery store. What are you going to do when the clerk hands you 1 Orange, 1 watermelon and 1 zuchini?? "Hey I didn't ask for these!" "Oh sorry, you forgot to say 0 of those items..."

              Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

              G Offline
              G Offline
              gumi_r msn com
              wrote on last edited by
              #26

              From your post you seem to be implying we should just do without levels of abstraction. So what if the compiler has to do some dirty work for you just because you start at 1 and not at 0? I wouldn't care less, there is no meaningful implication anyhow. Also, the way we count apples, apple nº0 is not meaningful, it is not an apple. Having 0 apples means you have...well no apples at all. We start to count in 1 because that is the first meaningful number when we have apples to begin with, that's why we count all the way up to apple nº10 and do not stop at apple nº9 (apple nº9 is the 10th apple...hmm isnt that obvious? now try explaining that to somenone who has never programmed and you'll really see how intuitive zero based indexing is).

              L 1 Reply Last reply
              0
              • N Nikunj_Bhatt

                In almost all programming languages, the index number of arrays, strings and other starts with 0 (Zero). Now suppose, presently you are going to design a new language and forget that any programming language already exist. Then from where would start the index number? Zero or One or something else? Here I am mentioning the reason behind coming this question in my mind. The problem with Zero based index is faced (a little) in the function of finding position of a string inside another string and/or checking existence of one string into another. When the searched string is found at the first character (index=Zero), the function will return Zero and if it is found elsewhere, it will return that Zero based position, and it is NOT found, it may return -1 (depending on the language). { In PHP, however there is a good function which return "false" if the string is not found. } But what if we just want to check weather a string exist in another string or not? There could be another function for this purpose OR you may need to check 2 conditions, one for its index and second for its existence. Now, if the index starts from 1, the function will return 1 if the searched string found at the first character, and this will make easy for checking existence of one string into another, because if the string is not found, the function can return Zero and thus making the IF condition false. So, what do you think about starting number for index in a language if you are going to be the founder of the language?

                D Offline
                D Offline
                Dr Walt Fair PE
                wrote on last edited by
                #27

                I'd make it specifiable so you could decide in each case what made better sense as the base index. (Didn't Algol have that?) I certainly wouldn't mix boolean and integers, though. That's why there are two types!

                CQ de W5ALT

                Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                L 1 Reply Last reply
                0
                • N Nagy Vilmos

                  BobJanova wrote:

                  It would be simple enough for a compiler to calculate the offsets to put into the byte code, anyway.

                  How? See my comment above, by reducing the number of steps, you produce more efficient programs.


                  Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #28

                  The compiler could simply do the -1 calculation, at least for any static indices. You'd have a language where you don't need to do for-loop indexing of arrays if possible (by permitting array operations as a language feature – think APL or R) and anywhere where the looping over an array is done as part of the language, the compiler knows the fixed offsets and can generate the appropriate native code. Only in the case of indexing a fixed-memory array directly by specifying a calculated index would there be an extra operation. And, frankly, that operation is of zero importance for performance on a modern system, where performance is far more about data volumes fitting in chip caches and the parallelisability of algorithms.

                  N 1 Reply Last reply
                  0
                  • N Nikunj_Bhatt

                    I know that programming languages are highly depending on pointers. You know that what an Object is, but do you know Why the Object is introduced?. Languages are made more and more feature rich to let programmers make solutions by as much less code as possible. What I mean to say by "In modern programming (languages), importance of pointer is decreasing." is, nowadays, programmers do not need to deal with pointers directly, and these increases productivity and actually much higher reliability of code.

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #29

                    Do some research Bubba. The point of OO is to provide another level of abstraction from the machine. The amount of code in an OO language based solution is much greater than for a traditional procedural language. However by using classes, the amount of code in one place can be reduced and, more importantly, the code is more tightly connected to the data. The languages are abstracting away the complexity of pointers, but every object is a pointer, we are helped by the fact that a lot of the handling that we had to do by hand in a language like C is now done 'for free' by C# for example. This does not get away from the fact that, at some point, the instruction has to be reduced to finding the memory address containing the item you need. By using zero based arrays, there is one calculation removed, a single machine step. So, this goes back to my original comment. Zero based makes sense because it is better once everything is compiled down. Now which part don't you understand?


                    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                    N 1 Reply Last reply
                    0
                    • B BobJanova

                      The compiler could simply do the -1 calculation, at least for any static indices. You'd have a language where you don't need to do for-loop indexing of arrays if possible (by permitting array operations as a language feature – think APL or R) and anywhere where the looping over an array is done as part of the language, the compiler knows the fixed offsets and can generate the appropriate native code. Only in the case of indexing a fixed-memory array directly by specifying a calculated index would there be an extra operation. And, frankly, that operation is of zero importance for performance on a modern system, where performance is far more about data volumes fitting in chip caches and the parallelisability of algorithms.

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #30

                      BobJanova wrote:

                      The compiler could simply do the -1 calculation

                      It can't. It would need to place an extra step into the machine code to subtract 1 from the index.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      B 1 Reply Last reply
                      0
                      • M Marc Clifton

                        BobJanova wrote:

                        It's pretty difficult to work without lists, and you need to get things out of a list.

                        Iteration doesn't require indexing to be exposed. If I need to index something by a hard-coded value, then that's bad. If it's a computed value (like a portion of a string) then it should be able to be represented in a better way, again hiding the details of indexing.

                        BobJanova wrote:

                        but a lot of real world problems would be much more difficult without being able to look things up by index in arrays or collections.

                        For example? Even matrix operations can be coded with more clarity if the matrix array could be mapped onto a structure so one didn't have to write "[0]". Marc

                        My Blog

                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #31

                        Iteration requires looking at all the items, sometimes you don't want to do that. For example? You've got a list of purchase records in some form of ID-indexed structure, and presented to the user is a list of their titles. When they select one, you want to generate a report of the details of the record they selected (i.e. records[record_id]). You've got a network protocol where the last byte of a message (bytes[bytes.length - 1]) is a checksum. Various string manipulations as currently done with Substring methods (extracting particular fields from a combined text string of some kind). One of the parameters to that method in all conventional languages is an 'index' (actually an offset in most of them).

                        M 1 Reply Last reply
                        0
                        • N Nikunj_Bhatt

                          In almost all programming languages, the index number of arrays, strings and other starts with 0 (Zero). Now suppose, presently you are going to design a new language and forget that any programming language already exist. Then from where would start the index number? Zero or One or something else? Here I am mentioning the reason behind coming this question in my mind. The problem with Zero based index is faced (a little) in the function of finding position of a string inside another string and/or checking existence of one string into another. When the searched string is found at the first character (index=Zero), the function will return Zero and if it is found elsewhere, it will return that Zero based position, and it is NOT found, it may return -1 (depending on the language). { In PHP, however there is a good function which return "false" if the string is not found. } But what if we just want to check weather a string exist in another string or not? There could be another function for this purpose OR you may need to check 2 conditions, one for its index and second for its existence. Now, if the index starts from 1, the function will return 1 if the searched string found at the first character, and this will make easy for checking existence of one string into another, because if the string is not found, the function can return Zero and thus making the IF condition false. So, what do you think about starting number for index in a language if you are going to be the founder of the language?

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #32

                          Simply put it should be 0 or it becomes more confusing. Many have pointed out why it is 0 and to not grasp that is then dangerous for you to program. The reasoning is simple. You are working with a system that reconizes 0 implicitly. There is no changing that. The reasoning for this is that 0 does exist. In human languages we tend to use 0 implicitly. This means that unless I say otherwise assume 0. Example, I want to order 5 Chicken strips. The waitor will hopefully not bring me 1 of everything else on the menu. Collections being 0 based indexing are indirectly related to this. Define Chicken stripsBasket (implicityly I have 0 chicken strips but I have my basket) Fill basket with 5 chicken strips Now to access your chicken strips you have a reference to the basket... Not your friends basket... Not the basket on the table next to you. Your basket. For efficiency referencing the basket gets you a chicken strip, unless you wanted to actually eat the basket. By requiring 1 based indexing you are adding a step to the chicken strip access which when compounded with the complexity of systems we create today would have horrible performance (and for no reason). If one does not grasp why computer languages use 0 based indexing (more importantly that they do), one should not be a programmer IMHO.

                          Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                          G W R 3 Replies Last reply
                          0
                          • N Nagy Vilmos

                            BobJanova wrote:

                            The compiler could simply do the -1 calculation

                            It can't. It would need to place an extra step into the machine code to subtract 1 from the index.


                            Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                            B Offline
                            B Offline
                            BobJanova
                            wrote on last edited by
                            #33

                            Did you read the rest of the post? As I said there, "Only in the case of indexing a fixed-memory array directly by specifying a calculated index would there be an extra operation". And most of the times you have to do that now are because of a language deficiency. And finally one instruction is so trivial that who cares anyway (on a 4Ghz machine it will cost you 0.25ns, and that's if getting the data your algorithm is working on onto the core cache isn't the limiting factor already) – language design should not be constrained by such trivia.

                            N 1 Reply Last reply
                            0
                            • I Ian Shlasko

                              Clearly, all indices should start from -2 and count in base 13.

                              Proud to have finally moved to the A-Ark. Which one are you in?
                              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                              R Offline
                              R Offline
                              realJSOP
                              wrote on last edited by
                              #34

                              Great. Now I'm going to have to find/edit all of my messages where lists start with 0.

                              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                              -----
                              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                              -----
                              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                              1 Reply Last reply
                              0
                              • G gumi_r msn com

                                From your post you seem to be implying we should just do without levels of abstraction. So what if the compiler has to do some dirty work for you just because you start at 1 and not at 0? I wouldn't care less, there is no meaningful implication anyhow. Also, the way we count apples, apple nº0 is not meaningful, it is not an apple. Having 0 apples means you have...well no apples at all. We start to count in 1 because that is the first meaningful number when we have apples to begin with, that's why we count all the way up to apple nº10 and do not stop at apple nº9 (apple nº9 is the 10th apple...hmm isnt that obvious? now try explaining that to somenone who has never programmed and you'll really see how intuitive zero based indexing is).

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #35

                                gumi_r@msn.com wrote:

                                From your post you seem to be implying we should just do without levels of abstraction.

                                Not at all. I am implying there is no reason to abstract it. A programmer should understand the bases of what they are programming in (for efficiency). Yes the compiler can handle it. But when it comes to dynamic allocations you end up in the run time. Now it is about perfomance of the app (rather than speed of the build) so not such a good thing. When you count Apples you DO start with 0. You used the word APPLE No? In computers that is where 0 starts, The definition. In Human tounge it is an implicit deffinition. Computers must work in concrete terms. You can't change that. Yes you can abstract it. But at a cost of efficiency.

                                Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                                G 1 Reply Last reply
                                0
                                • N Nikunj_Bhatt

                                  I mostly like loosely typed languages, it decreases programming code. When I program, I know that what type of value the function will accept and return, and I can trap it in anyway by the language's features. So I don't need to know the exact data type.

                                  W Offline
                                  W Offline
                                  Wjousts
                                  wrote on last edited by
                                  #36

                                  nikunjbhatt84 wrote:

                                  I mostly like loosely typed languages

                                  I don't

                                  nikunjbhatt84 wrote:

                                  it decreases programming code

                                  By increasing (potential) bugs.

                                  nikunjbhatt84 wrote:

                                  When I program, I know that what type of value the function will accept and return

                                  So what's the problem with specifying that in the code, since you know it already.

                                  nikunjbhatt84 wrote:

                                  and I can trap it in anyway by the language's features.

                                  Sounds like more code to me :confused:

                                  1 Reply Last reply
                                  0
                                  • D Dr Walt Fair PE

                                    I'd make it specifiable so you could decide in each case what made better sense as the base index. (Didn't Algol have that?) I certainly wouldn't mix boolean and integers, though. That's why there are two types!

                                    CQ de W5ALT

                                    Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #37

                                    Walt Fair, Jr. wrote:

                                    I'd make it specifiable so you could decide in each case what made better sense as the base index.

                                    That seems dangerous. If the system is changing its base index how is a maintainer of the system suppose to understand the logic of the one whom developed it in the previous decade? Yes in some cases you want 1 base. The only time I run into this is if some values are making it to the UI. E.g. I have a grid displaying products. Users understand it as 1,1; 1,2; 1,3 but the system understands it as 0,0; 0,1; 0,2 This is exactly why patterns exist for what we display versus the business logic (MVVM, MVC etc.) Your business logic should NOT be using a modified index as it is leads to confusion in other parts of the system (non viewable). I have seen code where the developers tried to be clever and do these things. You end up with a freaking mess. Keep it consistent across the board.

                                    Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                                    D 1 Reply Last reply
                                    0
                                    • N Nagy Vilmos

                                      Simply put, it makes sense to have it start at 0. The array variable will be a pointer to a memory address p and each item is an offset from there so, for item n where each element is size s the memory address is p+n*s. If you want 1 based arrays then the element would be found at p+(n-1)*s. Which is easier to compute?


                                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                      W Offline
                                      W Offline
                                      Wjousts
                                      wrote on last edited by
                                      #38

                                      I agree with you, and I absolutely believe in counting from zero, but to be fair, if a language is compiled, then all those MyArray[n] can be replaced with MyArray[n-1] by the compiler making it a moot point at run time. [Edit: actually ignore that. It would only work for statically indexed arrays and maybe for loops. For calculated indexes, the -1 has to be done at runtime]

                                      1 Reply Last reply
                                      0
                                      • L Lost User

                                        gumi_r@msn.com wrote:

                                        How does a small kid learn his numbers? I find it hard to imagine some little boy counting 0, 1, 2, ...
                                        We start at 1, and do so even when we are grown ups.

                                        You eventually teach children the concept of 0. It is something you must teach them. However, we need not teach computers the concept of 0. The fact is if a person is counting objects they do use 0, it is just omitted. For example, I have 6 apples all lined up. I want to count them. Now I am a smart chap so I can just look and say there are 6 apples. Someone else may need to at the minimum count by 2's (omitting the odds). And yet another will count from 1 to 6 (omitting the 0). The fact is all counting of objects (which is what your comparison is about) start with 0, we just choose to omit for efficiency. Well starting the index at 1 for computers is inefficient because the fact is 0 exists, and the computer knows that. If you start at 1 you now have to proram at the base level speacial instructions for it to understand 0. Why would you do that? So you example of going to the grocery store. What are you going to do when the clerk hands you 1 Orange, 1 watermelon and 1 zuchini?? "Hey I didn't ask for these!" "Oh sorry, you forgot to say 0 of those items..."

                                        Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                                        B Offline
                                        B Offline
                                        BobJanova
                                        wrote on last edited by
                                        #39

                                        This makes no sense. Counting and indexing are completely different things – even the 0 based computing world accepts that a collection of things A, B and C has 3 items, even if it calls them '0', '1' and '2'. The fact is if a person is counting objects they do use 0, it is just omitted. That doesn't mean anything either. A count of 0 is when there are no things to count. But if there are 6 apples, it doesn't matter what indexing system you use, or how many you count at once, there are always 6. What 'indexing' is about it labelling. Ask anyone to label those apples with numbers and everybody (unless they're being deliberately silly) will call them '1', '2', '3', '4', '5' and '6'. Look at things which are labelled in the real world: bases on a rounders/baseball field, quarters or halves in a sports match, aisle numbers in the supermarket. Even in the computing world this is often true; look at the MRU on Excel or Word, it numbers your recently used files from the first (1) up. Well starting the index at 1 for computers is inefficient As I'm discussing with Nagy above, technically true in a small number of cases (many of which are due to language deficiencies regarding array operations in C family languages) but so small as to be irrelevant as a consideration in the modern world. The fundamental question is really: do you want a language for the computer, or one for the people who write it? I would prefer to write one for people and let the compiler or interpreter deal with the translation.

                                        L 2 Replies Last reply
                                        0
                                        • L Lost User

                                          Simply put it should be 0 or it becomes more confusing. Many have pointed out why it is 0 and to not grasp that is then dangerous for you to program. The reasoning is simple. You are working with a system that reconizes 0 implicitly. There is no changing that. The reasoning for this is that 0 does exist. In human languages we tend to use 0 implicitly. This means that unless I say otherwise assume 0. Example, I want to order 5 Chicken strips. The waitor will hopefully not bring me 1 of everything else on the menu. Collections being 0 based indexing are indirectly related to this. Define Chicken stripsBasket (implicityly I have 0 chicken strips but I have my basket) Fill basket with 5 chicken strips Now to access your chicken strips you have a reference to the basket... Not your friends basket... Not the basket on the table next to you. Your basket. For efficiency referencing the basket gets you a chicken strip, unless you wanted to actually eat the basket. By requiring 1 based indexing you are adding a step to the chicken strip access which when compounded with the complexity of systems we create today would have horrible performance (and for no reason). If one does not grasp why computer languages use 0 based indexing (more importantly that they do), one should not be a programmer IMHO.

                                          Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                                          G Offline
                                          G Offline
                                          gumi_r msn com
                                          wrote on last edited by
                                          #40

                                          As I posted before you'r reasoning IMHO is not solid. The fact is that array[0] is a meaningful item in a zero based indexing system, while in our everyday life, 0 is the contrary; it can be omitted, as you well say, precisely because it is not meaningful, we live in a 1-index based world like it or not. And I absolutely disagree with the supposedly overhead paid when the compiler has to correctly interpret array[1] as the first item of the array (that is, offset zero in the uderlying pointer) when it spits out machine code, CIL or what have you. Why should there be any performance issue at all? Let the compiler transform everything to zero based indexing that the computer natively understands at compile time (we may have a 1 ms compile time overhead in there somewhere...). Or should we also start writing our programming in assembly code just to make the computers understand us better? Obviously this is of course a hyothetical discussion. We are stuck with zero based indexing and it is after all trivial to understand how it works.

                                          L J 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups