3 ms·
> pointers aren't complex They are complex if you are coming from the Python world. To truly know their recursive declaration syntax, you have to see it from a
by bluetomcat 3y ago
> pointers aren't complex
They are complex if you are coming from the Python world. To truly know their recursive declaration syntax, you have to see it from a compiler's perspective. Pointer arithmetic isn't something you do often even in C++. It's a crude kind of reference that can be mutated arithmetically and doesn't provide any safety whatsoever. It maps well to the indirection mechanisms and addressing modes provided by the underlying hardware.
- seba_dos1 3y agoEverything is complex when you're barely starting, but in general, pointers aren't complex. Don't mistake the complexity with ease of making mistakes though.
- alexhutcheson 3y agoHonestly I find Python's value vs. reference semantics fairly confusing, and it's not always obvious whether an operation is going to make a copy or modify an existing instance of an object. Good API design and docstrings mitigate this, but it's one more source of complexity to think about. I run into this much less frequently in C++ code - it's normally pretty clear from parameter and return types whether I'm dealing with a copy or a reference. This might just be because C++ broke my brain into assuming: Object foo = other_object; is a copy operation, and taking a reference or pointer would require extra characters (e.g. copy by default). Most other languages are the opposite: assignment creates a reference by default, and making a copy would require extra characters (e.g. .copy() in Python or .clone() in Java). That's my biggest mental adjustment when moving back-and-forth between C++ and Python.
- nedbat 3y agoPython itself only has one kind of argument passing (neither by-value or classic C++ by-reference), and nothing is copied. Library functions could make confusing choices, it's true.