Re: An interesting blog




"jacob navia" <jacob@xxxxxxxxxxxx> wrote in message news:i2hsdk$djo$1@xxxxxxxxxxxxxxxxxxxx
Dennis (Icarus) a écrit :

"jacob navia" <jacob@xxxxxxxxxxxx> wrote in message news:i2fm7j$vet$1@xxxxxxxxxxxxxxxxxxxx
http://apenwarr.ca/log/?m=201007#22

<quote>

Okay, one more example of C++ terribleness. This one is actually a tricky one, so I can almost forgive the C++ guys for not thinking up the "right" solution. But it came up again for me the other day, so I'll rant about it too: dictionary item assignment.

What happens when you have, say, a std::map of std::string and you do m[5] = "chicken"? Moreover, what happens if there is no m[5] and you do std::string x = m[5]?

Answer: m[5] "autovivifies" a new, empty string and stores it in location 5. Then it returns a reference to that location, which in the first example, you reassign using std::string::operator=. In the second example, the autovivified string is copied to x - and left happily floating around, empty, in m[5].

Ha ha! In what universe are these semantics reasonable? In what rational

Mine, and likely several others :-)

set of rules does the right-hand-side of an assignment statement get modified by default? Maybe I'm crazy - no, that's not it - but when I write m[5] and there's no m[5], I think there are only two things that are okay to happen. Either m[5] returns NULL (a passive indicator that there is no m[5], like you'd expect from C) or m[5] throws an exception (an aggressive indicator that there is no m[5], like you'd see in python).


How about foo(m[5]) Same thing right? m[5] is being assigned/copied/rererenced to the first argument of foo. Thart won't be helped by defining a new operator.

Look, he wrote:

when I write m[5] and there's no m[5], I think there are only two things that are okay to happen.

Either m[5] returns NULL (a passive indicator that there is no m[5], like you'd expect from C) or m[5] throws an exception (an aggressive indicator that there is no m[5], like you'd see in python).

My point was that
m[5] = some_value;
is no different than a function that'd write to m[5] as an output.

Dennis

.



Relevant Pages

  • Re: An interesting blog
    ... Maybe I'm crazy - no, that's not it - but when I write mand there's no m, I think there are only two things that are okay to happen. ... Either mreturns NULL (a passive indicator that there is no m, like you'd expect from C) or mthrows an exception (an aggressive indicator that there is no m, like you'd see in python). ...
    (comp.lang.c)
  • An interesting blog
    ... Maybe I'm crazy - no, that's not it - but when I write mand there's no m, I think there are only two things that are okay to happen. ... But in python, it works perfectly. ... They redefined things such that, if your optimizer is sufficiently smart, it can make all the extra crap go away. ... So actually C++ maps are as fast as python maps, assuming your compiler writers are amazingly great, and a) implement the ...
    (comp.lang.c)
  • Re: technologies synergistic with Python
    ... okay, okay -- what are some wide ranging ... That depends on what your dream job is using Python for. ... Integration with Java frameworks and applications? ...
    (comp.lang.python)
  • Re: using urllib2
    ... Okay, I tried to follow that, and it is kinda hard. ... did not post the html, but I mean if you want, right click on your ... and hit view source of the google homepage. ... 'Python Properties', ...
    (comp.lang.python)
  • Re: Some more notes
    ... >that is the language that you are accustomed to. ... You are right, I'm just a newbie in Python, and there are other ... Okay, I'll use os.path.normcase to convert them. ... with imperaive programming) and often it's also faster, ...
    (comp.lang.python)