Main Menu

Shoutbox

Baggey

2025-09-24, 17:57:11
They'll be using Expanding foam to glue bricks together next  :-X

Dabzy

2025-09-24, 06:09:52
You can also get the expanding foam post fix, but, I wouldnt trust it really, especially where I live on the side of a valley and when the storms blow in the right direction, whistling down the valley, nowt is safe!

Baggey

2025-09-23, 08:53:01
That Postcrete stuff is amazing. I never know how much water to add. May be i should read the Instructions  ;D 

Dabzy

2025-09-22, 21:33:46
Cannot beat a breaky uppy mode, saves the hand cramps and chipped knuckles knocking ten bells out of a chod of conc with a hammer and chisel.

GfK

2025-09-22, 21:28:44
I have a massive JCB drill with a concrete breaky uppy mode which has got me out of jail free a couple of times replacing rotted fence posts that has been concreted in.

Amon

2025-09-22, 19:23:30
What about Roly?

Dabzy

2025-09-22, 19:22:35
Putting my 2 deckings in.... I've dug enough post holes to last me a life time... I feel sorry for the future poor sod who may want to shift'em... Like most things I do, I tend to go over the top, and as such, I've probably got shares in postcrete! :D

GfK

2025-09-22, 19:10:57
Round is a shape.

Baggey

2025-09-22, 19:04:49
Consult a qualified electrician for compliance with BS 7671 and local building Regs! Avoid areas where future digging is likely. ;)

Jackdaw

2025-09-22, 18:18:24
That depends on where the cable is to run. Minimum depth in a garden in 450mm. Under pavements 600mm.

Members
  • Total Members: 55
  • Latest: Amon
Stats
  • Total Posts: 1,607
  • Total Topics: 198
  • Online today: 12
  • Online ever: 54 (Sep 14, 2025, 08:48 AM)
Users Online
  • Users: 0
  • Guests: 3
  • Total: 3
Welcome to SyntaxBoom. Please login or sign up.

Recent

Random programming thought bubble I had over lunch today

Started by Matty, Aug 16, 2025, 04:28 AM

Previous topic - Next topic

Matty

Why don't programming languages allow for negative array indexes?

Sure I understand I'm guessing it has to do with the underlying c code about basically moving forwards by a block of memory equal to the datatype's sizeof value from the first element onwards.

But from a mentally logical way of thinking about it - allowing indexes that used the full signed integer range to access them would allow for some interesting programming features.

This is just thinking out loud though, and I'm sure there's a million and one practical reasons why it simply doesn't exist.

Dabzy

I'm guessing it's just the way it maps it along with memory... Though thinking about it, I have seen something similar with strings, which is essentially an array of characters, but all it did was loop back on itself, so if you put -1 as an index, you'd be at the character at the end of the string.

P-code:

local str:string = "hello"
print str[-1]

Output: o

Dabz
Intel i7-13620H, nVidia GerForce RTX 4060 Laptop GPU (8GB GDDR6), 16GB LPDDR5X, 1TB SSD, Windows 11 x64 piss flap of an OS!

GfK

What would be a use case for negative indices?

Midimaster

The question is never "why" but "how":

Global MyArray:Negative = New Negative(1000)
MyArray.Set -111, 5
Print MyArray.Get(-111)



Type Negative
    Field array:Int[], DimHalf:Int
    
    Method New(Dimension:Int)
        array = New Int[Dimension]
        DimHalf   = Dimension/2
    End Method 

    Method Set(Element:Int, Value:Int)
        array[Element+DimHalf] = Value
    End Method
    
    Method Get:Int(Element:Int)
        Return array[Element+DimHalf]
    End Method
End Type

Matty

A use case: imagine a 2d array for a world map where each index refers to an X or z co-ordinate.  Typically you adjust the world position before putting into the array to avoid going out of bounds.  But if negative indexes were allowed it would mean you wouldn't need to adjust the coords before putting into the array.

Steve Elliott

That's why other data structures to arrays were invented - because they can be more flexible.

_PJ_

I get the idea, but it seems very limited use really.

You could simulate this just by having some offset to references of the positivie integer elements.

The 'reason' behind having a zero or 1 initiated positive count is ( I believe, may not be the actual reason ) due to the array representing a structured count of items. Any such list will always be positive -

Similar to measuirng a distance. You can have a negative quantity in terms of vector direction, but the magnitude will always be positive since it is "number of steps taken" -



blinkok

How can you traverse an array if you don't know ehere to start?