?

Log in

No account? Create an account

Previous Entry | Next Entry

Start Counting From    W H A T ? ! ? !

weather: clear
outside: 6°C
mood: hairy spazz
*SSCCRREEEEEEEEEAAAAAAAAARRR*

I'm developing a suite of internal tools using Microsoft's Application APIs through C#. It looks like C++, smells like Java, acts like VB, but has its own soul. It lets me do my thing with the occasional "s'cuse me, Ma'am, my leg is caught in the door". But it's generally Not A Problem®.

There are arrays of item objects in a structure in another object class. No problem. They're only one-dimensional arrays. That really should be no problem (not like the five-dimensional monsters I had to deal with once).

All these arrays start at index one. *dramatic pause*       1... ... ... ONE... ... ...

Who the hell starts counting from one?!?!?!

>K}


Comments

ntang
Jan. 8th, 2003 08:06 pm (UTC)
Re:
Ah, even worse.

Actually, one place I worked we had Microsoft as a client, and they seemed ok, although I never actually talked to anyone from Microsoft on that project.

Still, you have to wonder. Why break a rule that old and established, especially when making a language that's a derivative of several older and more established ones? It just doesn't make sense.
bride
Jan. 8th, 2003 08:28 pm (UTC)
Re:
It's an array setting that you can change. It looks like you can change it to start at whatever number you want. I just found that out. But that's even more scary. =O
ntang
Jan. 8th, 2003 08:42 pm (UTC)
Re:
Well, as long as it defaults to 0, that's actually not horrible. It leads to obfuscated code, which isn't a good thing, but it could be useful.

Then again, being mildly useful doesn't justify making code unreadable, so...
bride
Jan. 8th, 2003 09:39 pm (UTC)
It just means you'd have to keep checking the lower bound of arrays - Array.GetLowerBound( int dimension )

So, if you're traversing, instead of:

for( i = 0; i <= sizeof(Array); i++ ){
...
}


you'd have to go:

for( i = Array.GetLowerBound(1); i < Array.GetUpperBound(1); i++ ){
...
}


Which is a pain in the ass, but that's the way C# works.
pne
Jan. 8th, 2003 11:20 pm (UTC)
i < Array.GetUpperBound(1)
And I hope the compiler caches the result and doesn't make a method call on the array every time through the loop in the comparison function!

Or can arrays change size dynamically? I suppose so. In that case, you would need to recalculate each time through the loop.

(Oh, and wouldn't the "normal" example use sizeof(Array)/sizeof(Array[0]) rather than plain sizeof(Array)? After all, you want the number of elements in the array, not the number of bytes.)
bride
Jan. 8th, 2003 11:33 pm (UTC)
Re: i < Array.GetUpperBound(1)
And I hope the compiler caches the result and doesn't make a method call on the array every time through the loop in the comparison function!

Yeah, you'd stick it in a variable.

Or can arrays change size dynamically? I suppose so. In that case, you would need to recalculate each time through the loop.

Not that I know of... but it wouldn't surprise me if you could. You can do that in Perl and PHP, you just keep appending elements to the end.

(Oh, and wouldn't the "normal" example use sizeof(Array)/sizeof(Array[0]) rather than plain sizeof(Array)? After all, you want the number of elements in the array, not the number of bytes.)

Yeah, me and my pseudo-code =)

Profile

eLouai
bride
The Bride of the First House

Latest Month

March 2015
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031