Forum > General

Sets Vs Arrays. When to use and why.

<< < (2/5) > >>

n7800:
Actually, there is a good description in the documentation (here and here). It will be useful not only for beginners. For example, I did not know about the possibility of using the operator ">=".

440bx:

--- Quote from: n7800 on March 07, 2025, 11:37:14 pm ---
--- Quote from: 440bx on March 07, 2025, 10:29:28 pm ---3. the first element has an ordinal of zero and the last an ordinal of 255

--- End quote ---

This can be controlled, for example, like this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  sign = (negative = -1, none = 0, positive = 1); 
But it is almost never necessary.

--- End quote ---
That works but, that opens the door to unexpected situations where things don't work anymore.  It opens the door to the same problem caused by 4,000,000..4,000,100.

I strongly recommend keeping the first and last index in the range 0..255.  Anything else may or may not work and, sometimes it will not be obvious why it doesn't.


 

n7800:

--- Quote from: 440bx on March 08, 2025, 12:01:22 am ---I strongly recommend keeping the first and last index in the range 0..255.  Anything else may or may not work and, sometimes it will not be obvious why it doesn't.

--- End quote ---

This causes even more problems than it seems at first glance. There is a large discussion on the compiler bug tracker about what to do with range "gaps" when specifying indices: #33603.

440bx:

--- Quote from: n7800 on March 08, 2025, 12:36:53 am ---
--- Quote from: 440bx on March 08, 2025, 12:01:22 am ---I strongly recommend keeping the first and last index in the range 0..255.  Anything else may or may not work and, sometimes it will not be obvious why it doesn't.

--- End quote ---

This causes even more problems than it seems at first glance. There is a large discussion on the compiler bug tracker about what to do with range "gaps" when specifying indices: #33603.

--- End quote ---
I'm not sure I follow what you are really saying but, anytime a set has a starting index other than zero, the potential for unexpected problems is present.

Here is a discussion about some of the problems associated with that.
https://forum.lazarus.freepascal.org/index.php/topic,49640.0.html
I suggest you pay particular attention to PascalDragon's comments and the one about the range specifically.

n7800:

--- Quote from: 440bx on March 08, 2025, 02:06:47 am ---I'm not sure I follow what you are really saying but, anytime a set has a starting index other than zero, the potential for unexpected problems is present.

Here is a discussion about some of the problems associated with that.
https://forum.lazarus.freepascal.org/index.php/topic,49640.0.html
I suggest you pay particular attention to PascalDragon's comments and the one about the range specifically.

--- End quote ---

Yes, another issue is discussed here. But it is also useful to read, thank you.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version