3 ms·
Probably a nitpick but Didn't read, got bored at having pointers explained, even if actively trying to skip it. I get a mix of: 1- you don't know your audienc
by TZubiri 2y ago
Probably a nitpick but
Didn't read, got bored at having pointers explained, even if actively trying to skip it.
I get a mix of:
1- you don't know your audience or are trying to cater to too wide of an audience
2- if someone doesn't know how pointers work, is there any merit in knowing syntax of a novel programming language?
So if you want the veterans to read this, you are going to have to make it less accessible.
Edit: it seems like the whole article is OP discovering pointers but zig is like his first language. Lol.
- jvanderbot 2y agoThat's the impression I got too. However, thinking long term, are we going to continue to introduce pointers via C to new students? If not, then how? C++ or Zig seem viable options, so this might be a long term proposition. Inb4 there won't be programmers
- tcfhgj 2y agoRust would be an option as well
- jvanderbot 2y agoRust does not in fact have a good way to introduce raw pointers that can be passed around, and can also be treated as addresses.
- 3836293648 2y agoSorry, in what language can you treat pointers as just addresses? Sure, assembly, but beyond that. Maybe Pascal? Everything else has provenance rules and magic unrepresented metadata around it that makes a pointer more than just an address.
- jvanderbot 2y agoI definitely remember casting pointers to ints and printing them to prove to myself what it was pointing to and what the offset was for the next value e.g. in an array. In C you can also do those fun array indexing and pointer arithmetic tricks that require you truly understand the concept of "address plus offset" that basically everything uses. But even if that's a hallucination, Rust does the hard work of keeping pointers off your mind by a combo of refs, box, etc. and Rust is not a good first language, I don't think, for a variety of reasons. My ultimate programing curriculum if I had to make one would teach you to program in python, then show you C via Cython or similar. Lots of allocation and free under the hood in Python.
- gizmo686 2y agoCasting pointers to ints is generally safe (at least as long as you use intptr_t instead of assuming that the size of pointers will never change). The issue comes when you try casting to pointers. Because of providence, aliasing rules, and a couple of dragons that built a nest in the C language specification, you could have two pointers to the exact same memory locations, but have the program be undefined if you use the wrong pointer. Granted, this doesn't stop you from doing things like foo_t *foo = (foo_t*) 0xDEADBEEF And in the few occasions where that is something you would reasonably want to do it does more or less what you would expect (unless you forgot that the CPU sticks a transparent cache between you and the memory bus; but not even assembly would save you from that oversight).
- tialaramex 2y agoProvenance (outside programming this is the distinction between "I reckon this old table is a few hundred years old" and "Here is the bill of sale from when my grandfathers ancestors had the table made from the old tree where that cherry tree is now in 1620") not Providence. In Rust pointer provenance is a well defined language feature and if you go to the language docs you can read how it interacts with your use of raw pointers and the twin APIs provided for this. In C the main ISO document just says basically here be dragons. There's an additional TS from 2023 with better explanation, but of course your C compiler even if it implemented all of C23 needn't necessarily implement that TS. Also of course the API is naturally nowhere near as rich as Rust's. C is not a language where pointers have an "addr" method so they also don't need a separate exposure API. I suspect that in Zig none of this is clearly specified.
- TZubiri 2y agoType (and word length as a derivate of it) anything else? Doesn't seem hidden to me
- pjmlp 2y agoIn systems languages that predated C like NEWP and PL/I variants, in Object Pascal, Modula-2, Mesa, BASIC, Ada. The different is that some of them have the knowledge between type safe pointers, i.e. can only be created by taking adresses of existing variables, and unsafe pointers, i.e. can be created out thin air like in C.
- tcfhgj 2y agoyes, it does https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html https://doc.rust-lang.org/book/ch20-01-unsafe-rust.html
- oconnor663 2y agoOn top of those fundamentals, there have been more recent developments: https://doc.rust-lang.org/std/ptr/index.html#strict-provenance https://doc.rust-lang.org/std/ptr/index.html#strict-provenan... https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html https://www.ralfj.de/blog/2020/12/14/provenance.html https://www.ralfj.de/blog/2020/12/14/provenance.html https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html
- TZubiri 2y agoNot at all, rust is more a successor to C than a replacement.
- TZubiri 2y agoIt's an interesting question. I first don't see a problem with C being a basal part of the curriculum for centuries, we are already at half a century going strong. Second, if this were to happen, it should happen with a mature language, and decided consciously by seasoned professionals. Third. I think more than looking at other languges we should look into other types of pointers, like files, hyperlinks, assembly addresses, inodes. To date C is the standard for pointer-pointer syntax, introducing new standards is fine, but it only makes sense with the standard syntax. It's the canon of programming. Long live C
- sureIy 2y agoI don't understand the snark. Is it not possible to write articles for beginners? There are also a lot of developers who have never dealt with memory allocation and are interested in Zig.
- TZubiri 2y agoYes it is possible to write articles for begginners, but they should be on begginner concepts. Writing about an advanced concept catering to begginners is a mess. It's like writing about logarithmic calculus and prefacing with an explanation on exponents.
- epolanski 2y agoHey I started using Zig after a decade of JS/Elm/Haskell/php/scala, such articles are very useful to me. Haven't used lower lever languages in a long time. You aren't always the audience, it's fine.
- barrenko 2y agoThis is the HN caveat.
- TZubiri 2y agoMakes sense, it seems like you missed languages with pointers. I would suggest going through C. Otherwise it's like learning C++ without learning C. Zig is similarly a successor to C, (it is phonetically named after it). That would address your blind spots and let you appreciate Zig's identity
- epolanski 2y agoLearn C so you can avoid beginner content on Zig /s. You're making many wrong assumptions at the same time: - that I've never used C or C++ (both wrong) - that I don't know pointers (also wrong, nor it is a particularly difficult topic) - that you need to go through C again to learn Zig. Have you met many people that picked up Zig as their first programming (or first system programming) language to make those statements? Because I am in both the IRC and discord and there's plenty of people that get proficient in Zig starting from it.
- pjmlp 2y agoSince at least C++14, no one should be learning C as means to learn C++, unless they want to keep writing security exploits on regular basis. CppCon 2015: “Stop Teaching C" https://www.youtube.com/watch?v=YnWhqhNdYyk https://www.youtube.com/watch?v=YnWhqhNdYyk
- TZubiri 2y agoWe might still be in a period where C can be both thought of as a historical didactical language and as a language to program in, I'm seeing the pushback from people that fear C as the second kind. With time, we will stop using C except for very specific things (it's only used for embedded, Open Source and Operating systems at this time anyways), and we will be able to focus on C as a historical and didactical step in a learning path. This is similar to why it's appropriate to joke about killing someone but it's not appropriate to make a joke about raping someone. Or we are ok with reading about the epic of gilgamesh, or the oddyssey or beowulf, but Bible readings might face more pushback. But I think we can all agree that learning C is a basic step in the formation of any classically trained programmer. P.S: Talk is good, I've definitely noticed a top-down approach becoming more popular than bottom-up. But I chose to start with C as a teen, and my uni started me up with Chem, physics and maths before going into programming. Definitely two separate paths. In other courses I don't enjoy skipping history either, I like learning calculus by learning about newton, it makes it easier to remember. I hate the gray approach of just going for the solutions and memorizing them.