ArneOrtlinghaus wrote:I am also using the examples from my colleague Volkmar to adopt some new programming techniques - it is not so simple to leave over 20 years of programming behind.
I am also trying to use methods of the standard types like strings instead of using the VO functions. Of course nothing is gratis - when having index variables as in string.substring, counting starts from 0 and not from 1...
Indeed. The designers of C#/.Net, not sure who, who thought starting an index with 0 was a good idea should have been brought to a mental institution before finalizing their devastating work.
It is always extra effort to realize your real world collection of data, e.g. users 1-4 needs to be 1 lower in your program and of course it is often forgotten, leading to runtime errors.
Hi Dick,
there are many languages that start with 0 and not with 1.
Take C and C++ as the predecessors of C#, and even PHP, probably the worlds most popular web applications language starts with 0. The same is true for Javascript.
That does not means that I prefer that - for me the most logical first member of an array is 1, but that is a minority opinion, I think.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Why a minority Wolfgang? Pascal uses 1-based, basic uses 1-based, clipper etc use 1-based. I think the only reason why c originally used 0 based indexes was that of absolute performance and minimum memory footprint, because when c was designed, every CPU cycle and byte of storage was extremely important in 1MHz CPUs with 1 kb of memory or even less. The problem is that we still have to deal with this nowadays...
Hi Chris,
personally I think if we put together C/C++/C#/PHP/Javascript/Perl/Python/Java we have a large majority. Maybe we should look at the TIOBE index: the first 5 languages in this list are 0 based, VB.NET on rank 6 is 1-based, and then again Javascript and PHP are 0-based.
So in the first 8 programming languages in this index of the most used programming languages only one (VB.NET on rank 6) is 1-based.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Yes, but most of those languages are descendants/highly influenced by c, aren't they? So they are continuing what was designed for a valid reason 40 years ago and IMO we are still stuck with this because it's impossible to change it now or there would be riots! The introduction of c# and .Net was probably a great opportunity to restore sanity , but sadly it didn't happen..
Fortunately the transformation rules between the 0- and the 1-world are quite simple: just add or subtract 1 and we are in the other world.
It is worse to make transformations between the Windows WinAPI-Screen coordinates and the VO-GUI Canvas coordinates and the VO-GUI logical dialog coordinates. But also here we have transformation rules that do not change over time, simple determinant algorithms.
Hi Chris,
as I wrote before: IMHO starting an index with 0 is illogic, but since we have no influence on this we have to accept that.
What makes it even more confusing in X# is the difference between arrays (for compatibility to VO/Clipper/VFP the first array index is 1) and collections (where the first array index is 0). But again: it is so, we cannot change it, so we have to accept it.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Wolfgang,
I agree that this is confusing.
The poor man's solution is to use a FOREACH loop to enumerate items in an array or collection.
Most likely this is a fraction slower but much easier to work with.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
We have the same problems every day in our languages:
- The first century of this millennium is the century with the 0 behind: 2000. The 18th century is 1700.
- When we go to the "first floor" of a building in many languages in reality it is the second floor of the building, because there is also the ground floor numbered 0.
- The first birthday is not the birthday but the first remembering of the birthday.
Arne