|
Klaus-Werner Konrad wrote: At first your parents had NO childs (count=0)
AFTER you were born the have 1 child (except you are a twin ...)
Good example. So what the hell child[0] represents ?
My parents have three children.
Let them be child[1], child[2], child[3], and the array size to be 3, so that I can be the "first" and not the 0th
(Yes: the array size was 0 when they did not have children yet, and [] was meaningless).
We are speaking about high level languages. Don't think in C++! An "index" is not necessarily a "counter". Starting at 0 or at 1 is a matter of context. Not something that is "always good" or "always bad"... You didn't demonstrate anything.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Well - in your FIRST year of life you are 0 years old
Generally an array index is not more than the OFFSET from the start of the array, and the count is the length.
So the first element is from offset 0 to offset 1, the second element is from offset 1 to offset 2 and so on.
And, NO, it shouldn't be context sensitive, just for consistency.
It would be absolutely confusing if one array would start with 0, the next with 1, the third with 19.75 ...
|
|
|
|
|
Klaus-Werner Konrad wrote: Generally an array index is not more than the OFFSET from the start of the
array, and the count is the length
Wrong.
A C array index is not more than the OFFSET from the start of the
array, and the count is the length. (C array, not generally).
But the question was another. "Should in high level programming language ..."
So, first, before teaching me the C language read carefolly the question (including the puctuation), than define:
1) What is an "high level language"? Is it ASM? C? C++? D? LISP? English? TNPL(aka "the new programming language": I just inventing it right now?)
2) What is an "array"? a "bouch of continguos memory holding identical objects"? a "set of identical object identifyed by an index"? a "set of similar objects identifyed by a key"?
3) What is the behavior of elements and indexes respect to insertion removal? Shold the indexes remain contiguous? Shuold them remain stable?
If you think to a well specific language (like C) every of the above question has an exact precise ansewr.
If you are designing something on a higer abstraction level ... all of those answers can be true. Of course, you'll come to different implementations. Sometimes even not based on C arrays.
Just as am example, give a look on how the "D laguage" defines arrays[^].
Yes, in their simple declination they start at 0, but can have even whatever kind of key!
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Ok -you're right !
I'm just another 'old-fashioned' programmer, who start ist's life with BASIC (Sharp PC1211), learned PL/1 and FORTRAN at university, followed by FORTH at Sharp PC 1512, proceeded to ASM Z80 while adapting my own built Z80 computer system to CP/M, then switched to C.
But in those old days memory was a real issue - a Z80 can only access 64 KB of memory, and this with memory mapped display space ...
Today memory isn't a real issue anymore, and processing speed doesn't (really) matter, too - my original Z80-system was by far the fastest system possible, built purely with 8 MHz-parts (1983). This was by far more than the original IBM PC speed (not to mention the ability of vectored interrupts etc.)
So, today, we as developers, should say 'don't bother' to performance issues ????
Just an example:
i < count in pseudo-assempler means i-count; if (sign_flag==-1) THEN ...
i a<= count means i-count; if (sign_flag==-1 OR zero_flag==TRUE) THEN ...
As you can see, the latter is less optimal, even if we talk about nanoseconds, but in summarize it can be a real difference in performance.
And: I Like PURE C - *I* can allocate memory, when I need it, and *I* decide, when to release it !!!
Of course, one have to be very careful about it, but - correct used - it gave you the most control, and the most power !
Another question is: WHO needs more 'abstraction level' ?
If I have a well done codebase fore the basic tasks (i.e. wrappers to WIN API and other basics) then I can do my buisiness layer even in pure C (or C++) as well ...
|
|
|
|
|
Bacon or CListCtrl are involved: it should obviously not be possible to have
Bacon[0] or
CListCtrl[0] As that would imply that we have run out...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Bacon[AsMuchAsPossible] ????
I'm not heavy - I'm KIDNAP RESISTANT... ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, September 7, 1924
|
|
|
|
|
Bacon[int64.MaxValue]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OriginalGriff wrote: Bacon[int64.MaxValue]
You have no ambitions, I'm sure you get more.
BTW is that bacon by weight [kilos? ] or slices?
Panic, Chaos, Destruction.
My work here is done.
or "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 always count my bacon by the Buttie.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
...because it makes loops work more obviously:
for (int index = 0; index < array.Length; index++) Rather than
for (int index = 1; index < array.Length + 1; index++)
(by the way, I'm a C# developer which never uses unsafe pointers and things like that).
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
So don't do that - use foreach instead... Then it doesn't matter anyhow.
I'm not heavy - I'm KIDNAP RESISTANT... ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, September 7, 1924
|
|
|
|
|
Not always possible: what if you are removing all entries with "XXX" in the name? You can't use a foreach where the IEnumerable changes...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
|
What about this?
for (int index = 1; index <= array.Length; index++)
That's what I used to do in BASIC (of course the syntax was different)
BTW I voted for 0. Habit.
modified on Monday, March 7, 2011 9:46 AM
|
|
|
|
|
If you did that you'd fall off the end of the array - you need:
for (int index = 1; index <= array.Length; index++)
|
|
|
|
|
Copy & paste mistake. Fixed, thanks
|
|
|
|
|
for (int index = 1; index <= array.Length; index++)
Ya i am agree this is the right way.........
|
|
|
|
|
You misunderstand. There is no right way, I only pointed out a different method
|
|
|
|
|
Mathematically,
for (int index = 1; index <= array.Length; index++) would be the right way to say it and count it.
It's been drilled into programmer's heads that 0 is better than 1 that it has become a religious offense to state otherwise.
|
|
|
|
|
|
We're all someone's infidel. Death to all, and to all a good night.
|
|
|
|
|
And double death to all who can't use a spell-checker!
------------------<;,><-------------------
|
|
|
|
|
OriginalGriff wrote: it makes loops work more obviously:
for (int index = 0; index < array.Length; index++)
A really obvious way would be something like:
for i in (1, array.Length]
|
|
|
|
|
To be fair, you could write
for (int index = 1; index <= array.Length; index++)
(but I prefer 0-based arrays too)
Regards
Thomas
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
...because it represents a higher abstraction semantic (first item) rather than an implementation technicality (address offset).
This is what I spect from a programming language not close to the machine.
(by the way, I'm a C# developer which never uses unsafe pointers and things like that).
Wake up! The Singularity is coming.
|
|
|
|