• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

zero-based or one-based records

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm in dubio about wether my field and record numbering should be zero-based (as arrays are) or one-based (as jdbc is). Anyone got any thoughts about this ?

Thanks.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's is a matter of taste. Nonetheless, I would recommend 0-based for two reasons:

  • 0-based will make your arithmetics simpler (you'll avoid something like recordPos = recordLength * (recordNumber - 1) + offset)
  • I think 0-based is "most" standard since it is used for arrays and the list/vector classes, which are used everywhere by everyone


  • [ October 14, 2004: Message edited by: Nicky Bodentien ]
     
    Sven Mari�n
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, I was only considering one-based to be equal with the JDBC way of saying 'this is the first record' or 'the first field'. However, I can compensate it with constant representations of the fieldnumbering in my specialized Record class. Thinking about specialization by the way, how far would you go in specializing the Record/Field representation? I mean, me myself created Record and Field classes containing the data values as Objects opposed to the Data class representation, which uses String for every value. And from that class I'm thinking about creating a BNSRecord containing the correct fieldnames and values perhaps stored in a Hashmap...
     
    Ranch Hand
    Posts: 531
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Sven Mari�n:
    I'm in dubio about wether my field and record numbering should be zero-based (as arrays are) or one-based (as jdbc is). Anyone got any thoughts about this ?

    Thanks.



    Hi, Swen. I would make them zero-based just for convenience; that's the way I implemented them in my own project. It's better to keep track of data structures that way, too, and that's an added bonus.
     
    Maybe he went home and went to bed. And took this tiny ad with him:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic