Page 3 of 4
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 3:11 pm
by ic2
Hello Karl, Hansjoerg
HansjoergP wrote:t is also a lot easier to get an element with the key and not to search for the index and than get the element.
FFF wrote:the other way round: if your "list" is LONG, Dictionary is a LOT faster...
I know, that's why I wrote "...makes
coding slightly shorter but
performance, with many elements, much
higher."
Dick
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 3:15 pm
by ic2
Hello Arne,
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.
Dick
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 4:38 pm
by wriedmann
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
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 4:41 pm
by Chris
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...
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 5:05 pm
by wriedmann
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
X# Example Project for various DotNet functionality
Posted: Thu Aug 26, 2021 5:13 pm
by Chris
Hi Wolfgang,
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..
X# Example Project for various DotNet functionality
Posted: Fri Aug 27, 2021 6:10 am
by ArneOrtlinghaus
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.
X# Example Project for various DotNet functionality
Posted: Fri Aug 27, 2021 6:50 am
by wriedmann
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
X# Example Project for various DotNet functionality
Posted: Fri Aug 27, 2021 7:13 am
by robert
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
X# Example Project for various DotNet functionality
Posted: Fri Aug 27, 2021 7:15 am
by ArneOrtlinghaus
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