Timeline for Is there any reason to use C++ instead of C, Perl, Python, etc.?
Current License: CC BY-SA 2.5
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 12, 2016 at 10:02 | comment | added | underscore_d | This answer just substitutes a few characters and then asserts this proves the superiority of references, with no information on what "the problems and pitfalls of pointers" were or why references solve them. | |
| Oct 30, 2015 at 19:43 | comment | added | martinkunev | @NathanOsman - The C++ standards is the only place where NULL references don't exist. | |
| Jul 25, 2011 at 12:44 | history | made wiki | Post Made Community Wiki by user32315 | ||
| Dec 27, 2010 at 0:51 | comment | added | Nathan Osman | @Ben: When I say the reference is always valid, I don't mean that it always points to valid memory - I meant that there's no such thing as a NULL reference. | |
| Dec 27, 2010 at 0:47 | comment | added | Ben Voigt | @George: "the reference is always valid" is flat out false. I'll give an example if you need one, but I'm hoping that you're expert enough to already be aware of this. And I'm not talking about forming an invalid reference using an invalid pointer, either. Functions that use pointers need documentation stating the preconditions on the arguments. But practically speaking, all functions need that level of documentation, so it's absurd to call that a strike against pointers. | |
| Dec 27, 2010 at 0:19 | comment | added | Nathan Osman | @Ben: You're forgetting something - the reference is always valid. Pointers can point to anything (including NULL) which can lead to all kinds of memory errors if things aren't done right. References can never be NULL and the address that they point to can never be changed. | |
| Dec 26, 2010 at 2:16 | comment | added | Ben Voigt | @George: Because nothing changed, except it's two (count 'em) characters shorter? It's not solving any problems, it's not highlighting any pitfalls, it doesn't even do anything cool like extend the lifetime of a temporary variable (which references are good at). | |
| Dec 26, 2010 at 1:45 | comment | added | Nathan Osman | @Ben: Then can you please explain why it's a bad example? | |
| Dec 25, 2010 at 23:11 | comment | added | Ben Voigt | Also much less flexible. References (C++-style) are good at simplifying certain common constructs in a language that also has pointers, but they fall so far short of being a replacement for pointers, it isn't even funny. And your example is not-at-all a good case for references. | |
| Dec 23, 2010 at 8:31 | history | answered | Nathan Osman | CC BY-SA 2.5 |