3 ms·
1. April joke :) The point of c/c++ in comparision to other languages is that you can do anything and having a huge toolbox for that. Pointers are excelent sle
by _o_ 9y ago
1. April joke :)
The point of c/c++ in comparision to other languages is that you can do anything and having a huge toolbox for that. Pointers are excelent sledgehammer. You can be perfectly fine with not using them but c++ need to have them. The pointers are not source of the problem, the developer is. That's why languages like java are prospering, it prevent incompetent people making stupid mistakes and that is fine. But some people need and want freedom that c++ offers.
- lucidguppy 9y agoRaw pointers are like "transporter scalpel" used by star trek doctors. When used with care it does the job and does it well. You need plenty of tests and valgrind. Its dangerous for most programmers to be cavalier with owning raw pointers. If we aren't we'll get another Java.
- laumars 9y agoYour point may be technically accurate but the elitism of the tone completely undermines it's point because even the best of us can and do write code with errors in it. I mean just look at all the mature code out there written by experienced developers which fails fuzz testing. I've been writing software for close on 30 years and I know damn well how easy it is to make mistakes. Even on days when I think I'm in the zone, there will be occasions when I'll go back to it and think "WTF was I thinking?" when it bombs out of the first round of automated testing.
- pjmlp 9y agoYou can have languages that prevent people making stupid mistakes and still offer full control over the hardware, that is what languages like Modula-2 and Ada offer.
- evincarofautumn 9y agoYeah, also Rust and ATS. A good systems language just needs to allow low-level and unsafe operations; nowadays the industry is warming up to the idea that such operations shouldn’t be available by default. Having to opt in with a machine-checked “unsafe” annotation means you have an explicit indication in the code of everywhere things could go wrong with type/memory safety, which means when something does go wrong, you know it must be caused by one of those unsafe regions.
- FrankHB 9y agoThe problem is that pointers almost totally violate the single responsibility principle. Technically, the only dependencies on pointers are types of the allocation/deallocation functions which are mandated in ISO C++ even for freestanding implementations (not the case in ISO C), and their derivations (new-expressions, etc). All other sane uses of pointers should be replaced by some better alternatives when appropriate (shared_ptr, unique_ptr, observer_ptr, reference, reference_wrapper without type completeness requirement, uintptr_t, iterator, etc). In that sense every pointer is a badly designed variant type; basically each occurrence of a pointer would likely be mostly incorrect (or not correct enough) in program semantics. I always treat that vagueness as a can of worms, so even merely replacing pointer by observer_ptr somewhere makes a big win to me. There do exist real costs like verbosity and bloating of binary size, but they have to be paid for sin of the father. The ship has sailed too far in a regretful direction; but this is not the excuse to fix it - which is one source of the problem from many developers.