It's a nice feature but I can't help feeling like, if you need a stable pointer to an item in a collection, ArrayList is the wrong data structure to use? Maybe someone can chime in and give me an example of when you'd do this instead of, e.g., just storing an index. Alternatively, you could use an Unrolled Linked List (FKA SegmentedList in Zig before it was removed in 0.16, not sure why).
I count this as a "rookie at system programming" mistake alongside returning a reference to a local variable. Rust is great at this because borrow checker can catch those at compile time and it can _teach_ devs to not do that.
I don't know Zig, but conceptually: a direct pointer is the fastest way to access an object. An arraylist is the fastest dynamic sequence of objects (fattest in access, not in growth). You use these when you need the performance. It's not often but it certainly happens. The most trivial example is a string that you append to but still need to pass to a C API in between that expects it to be contagious, but it's far more useful than just for storing characters.
Indexing into an array is direct pointer access, there's just an addition in front of it but it's hard to imagine that showing up at all in even the tightest of benchmark loops
I can't speak for your imagination, but this absolutely does come up if you're writing high-performance code.
Also note that being able to access arbitrary objects (as opposed to objects in the same array) requires storing two pieces of information: an index and a pointer to the beginning of the array. So it can use twice as much memory, which affects your cache etc., though you don't even need that to see the effect.
The addition is much cheaper than the memory access. The register pressure is worse than the addition. The size reduction of the index (versus the pointer) and resulting cache pressure reduction can outweigh the register pressure and the addition if you are storing many indices.
Sure, in cases where you need elements to be contiguous in memory then certainly an unrolled linked list is not appropriate. There's usually not a meaningful performance difference between a pointer deref and an indexed array access, however.
SegmentedList had a weird API, especially the way you control the list growth factor by the size of an inline array. And it hadn't kept up with stdlib norms in recent versions. I do hope it comes back eventually with an improved API.
At least we got Deque in exchange. I use that far more often than I used SegmentedList.
Aha, gotcha. To tell you the truth, I don't think I ever used it. I have a custom implementation I wrote because I didn't realize at the time that SegmentedList was an unrolled linked list :p
I use it in a lot of places where I know the max capacity ahead of time -- ensureCapacity() followed by a lot of *AssumeCapacity()-styled commands. It's convenient for all of the ... convenience ... methods (append() requires some bookkeeping somewhere, appendSlice() requires more, and so on). In those usages, it's basically syntactic sugar over a slice. That's not a perfect solution, but it's reasonably good often enough that I keep doing it.
The proposed change doesn't do much for me personally (memory safety is ensured in other ways, and if it weren't I wouldn't be annoyed debugging the allocator-observed errors), but I could see myself using it at some other point in time for the same class of usages, or I could see other people relying on it when they choose that class of coding.
ArrayList is a very generic (pun not intended) structure and could be stretched quite freely in any direction with useful property of owning underlying slice. Like readonly preallocated ArrayList is a thing.
My mental model of Zig is that it is explicitly the language for developers who prefer using pointers in business logic (instead of just in MMIMO, and are looking for something with improvements over C); i.e. exactly this class of abstraction.
Having written a bunch of Zig, I wouldn't say that the language design or culture explicitly encourages the use of pointers over indices in such situations. I would say it's more a language which trusts the programmer to make correct decisions about which constructs are appropriate in any given circumstance.
Hasn't the past 30 years of the Internet age taught us that given such trust, programmers will make the incorrect decision with horrifying predictability? The most trivial level of software security requires that pointer safety needs to be mathematically proven not up to human (or LLM) judgment.
I appreciate the explanation! I'm a noob at this sort of thing. (My experience with pointers is limited to MMIO and C FFI).
Regarding trusting the programmer: is that in the context of pointers, or more broadly? I'm betting I'm missing more, e.g. maybe mutation control too across threads/cores etc? Or as a broad design principle? (I have written some Zig as a learning dive, but don't Grok it, as am waiting for some core functionality like HALs, GUI libs, 3D libs etc. Was also a bit miffed by the 'operator overloading will never be allowed' as the use cases where I use low level languages have a near total overlap with the ones where I use vectors, quaternions, and matrices.
Stated another way: I learned with higher level langs first, which I believe biased my mental model. Example: Say I want to use a C library in my rust program/lib. (Example: CMSIS DSP). One of the actions I take in the wrapper is convert the pointer to an array ref; my mental model is the param is a list of items; it is divorced from memory. If I want to read/write a reg, or access FLASH, that's where I look to pointers. I e I think zig vs others is about if you want to conflate or divorce collections and memory.
I’m writing a game engine in Zig and after tens of thousands of lines written, I have to say my mind has totally melded to the language. It really hits a sweet spot for me between being expressive enough, and there only being one way to do something most of the time.
I can guarantee you that the overwhelming majority of low-income people who are delinquent on their rent have no clue who Cea Weaver is. Nor is there any kind of organized rent strike occurring. Do you live in NYC?
What a strange remark, both the 'no way' as well as the ad-hominem related to the odd choice of a 'democratic socialist' as mayor for NYC. There was a time when people with differing political opinions could get along outside of the realm of politics but this has been made impossible by people who react like you just did here.
The reason why nobody gets along with you has literally nothing to do with your "differing political opinions" and everything to do with the fact that I have to tell you that.
Why do you think nobody gets along with [me] and what is it that you assume gives you such insight into other people's life? Take a mirror, have a good look at it and notice that the problem is staring right at you.
Sure, Israel played a hand here, but it’s hard to believe they’re getting exactly what they wanted out of all of this either. Regime change does not seem like it’s coming any time soon. Unless that happens, any reductions in Iran’s capacity will be temporary.
As for the Iraq war, Israel was supportive, but it would be incorrect to say the war was at their behest.
I don't see why Israel would want regime change in Iran. The current one may hate them, but it's keeping the country poor and weak. Previous regime was starting to be a threat.
Who do you think the previous regime was? The Shah was installed by the US and was friendly to Israel. Under the Islamic Republic, Iran has been hostile to Israel and funded proxy organizations that have been in conflict with it.
Shah Pahlavi was installed by the US but soured with us later on. OPEC involvement was a big part of that. By the end of his reign, he was openly calling the US a puppet of Israel and criticizing both countries' actions there, and the US considered Iran a free agent.
I think an honest assessment of the history reveals that the Islamic Republic has been far more hostile to Israel and far stabler than the Shah, who oversaw a deeply unpopular monarchy and was deposed by his own people
I don't disagree with this, it's just that there's no reason to assume Israel simply wants the least hostile Iranian government. We never saw a real effort to replace the Islamic Republic, not even now. Likewise there was never an attempt to replace Hamas in the Palestinian territories.
Well also, about Pahlavi being deposed by his own people, who really knows.
What do you think Israel’s objective is then? It seems rather clear to me that they have expansionist ambitions which necessitate defeating their neighboring foes, who are backed by Iran. A non-hostile Iran is an Iran that does not back these foes. There has been no attempt to replace Hamas because Israel’s goal is the ethnic cleansing of Gaza.
They want to expand into the Palestinian territories and also want to not be existentially threatened, both of which require weakening their enemies. They aren't going to get a friendly Iran no matter what, but they can get a weak one.
They also need to maintain Western support. That's billions in both military aid and payoffs to neutral countries like Egypt and Saudi Arabia, plus diplomatic ties. Netanyahu's administration wants to maintain support from its own people too. Having enemies isn't a completely bad thing for those reasons.
Curious what design changes you're referring to specifically. I've been using the language for a couple years now and the language itself has undergone pretty minor changes, perhaps the biggest one being the removal of `usingnamespace`, which I don't think was that big a deal. Or are you referring to changes in the stdlib?
“Revealed preferences” are not the same as actual preferences. Treating them the same is what led us to the current situation we have with everyone addicted to social media and miserable. Also, expectations are not the only thing that could pressure someone to use these tools. If all your peers were using these tools and finishing their work in a fraction of the time it takes you, and getting the same or better grades, you would probably use them too.
What you do says a lot more about you than what you answer in a survey.
The obvious difference between LLM adoption and social media, if you think about it for longer than 10 seconds, is that there is social pressure to use social media. Your friends are organizing and bonding on social media. None of this exists with LLMs. There is no social pressure to have an AI girlfriend, quite the opposite.
Also I preempted the "if all your peers were using these tools..." none of this applies to students. In fact i'm sure most teacher would prefer not getting AI slop. Standards have not increased.
Please read the entire comment next time before replying
Social pressure from one's peers is not the only form of pressure. I don't think I'm the one who can credibly be accused of not reading the entire comment or not thinking for longer than 10 seconds in this exchange.
I will take you at your word that you genuinely want a politics free of racial discrimination, but all of the points you’re trying to make here are being immediately disproven by the reality on the ground. Florida has already passed a redistricting that massively and transparently disenfranchises black voters as a direct result of this decision. Louisiana is currently trying to postpone their already-underway primaries to push through a redistricting which I expect will do the same.