• kitikounel (unregistered)

    The language they use is C++, right ?

  • TheCPUWizard (unregistered)

    Sounds like there was also a set of WTF's when Merv did the "rewrite from scratch".....

  • Jezor (unregistered) in reply to kitikounel

    Pointers, operators overloading. Sounds like c++ to me.

  • gleemonk (unregistered)

    Assignment just copying a reference is the real WTF! I remember when PHP4 did the right thing and copied on assign. Still does too, for arrays. This spooky action-at-a-distance reference shit is very confusing to newbies. These days, I teach the novices to just use arrays instead of objects. Saves them a lot of headaches.

  • David (unregistered)

    Assignment just copying a reference is the only efficient option in many cases; making a complete copy of a complex data structure could end up thousands of times slower. If you can't figure references, you probably shouldn't be programming. Of course, functional programming is all about letting you copy those references and eliminating the worry of changing what's behind that reference.

  • Toby J (unregistered) in reply to David

    Uh, pretty sure you're being trolled there.

  • gleemonk (unregistered) in reply to David

    A thousand times slower? If you're pet language can't do COW it's shit. Millions of people have created successful apps in PHP thanks to the advanced interpreter. And now the purists have moved in and are destroying the language with shit nobody needs.

    Ah well, as long as they don't touch my arrays I can write code that works on PHP4 as well as PHP7. Just don't use the superfluous features.

  • Noughmad (unregistered)

    Assignment just copying a reference is fine, it's known as "pointer semantics", as your object behaves like a plain C pointer, and people understand pointers. However, it is only fine as long as you make it clear that this type uses pointer semantics, possibly by naming is something like "thingy_ptr". Now, changing semantics between build modes is just about the opposite of "making it clear".

  • Noughmad (unregistered) in reply to gleemonk

    PHP Right thing. Yep.

  • Bill (unregistered)

    The real WTF is not that there are two different ways a language can deal with assignment, it's that the method used changes between debug and release code!

  • gleemonk (unregistered) in reply to Noughmad

    "and people understand pointers"

    You don't talk to people often, do you?

  • I'm not a robot (unregistered) in reply to TheCPUWizard

    Nowhere does it say that the code under discussion here is the same code that he rewrote, just that they were (originally) written by the same person.

  • CrazyEyes (unregistered) in reply to gleemonk

    It's a mixed bag. I learned about pointers as early as high school, with Java. Yes, you can use pointer semantics in Java. My instructor made a point (no pun intended) of making sure that we understood the concept.

  • aoeuid (unregistered)

    Switching copying behaviour between debug and release builds is a wtf, no two ways about it. But the writer needs to take more time to produce a well-written story. Why are you introducing new characters in the last paragraph? It would be a much more relevant ending to document the time and effort of removing that oddity than to tell us the name of the guy who wrote it.

  • Moschops (unregistered)

    This one is mine. It's been dressed up a bit. A lot, in fact. A whole lot. But this:

    • Merv tapped the equals on screen. "What exactly does that copy assignment operator do, for this class?"

    is exactly what I did, and we did find that in release mode, it was a shallow copy; in debug, a deep.

    The 3000 line monstrosity I rewrote from scratch is now about a thousand lines and actually works, in stark contrast to its predecessor. However, an argument about the user-facing name of it is itself a whole new DailyWTF I'll submit soon enough :)

  • nb (unregistered)

    Core functionality change between Debug and Release? Sounds like maliciousness to me... Let's see... debug: Add symbols, enable Assert(0); 's (code not eligible for release if any of them hit), possibly add some reference counting/reporting, add stack and heap pre-init to CCCC CDCD etc.

    That's about it.

  • Herby (unregistered)

    You learn something every day. "Deep" vs. "Shallow" copy as terms. Quite interesting nomenclature. Of course, this lesson boils down to two WTFs: Operator overloading (what a fiasco!), and differing outcomes dependent upon debug/no debug mode of compiling. Both are disasters waiting to happen.

    Moral: If you do have differing compiles for debugging, make sure you don't change underlying behavior, only add nice debugging statements (I prefer 'printf').

  • siciac (unregistered) in reply to Bill

    The real WTF is ... that the method used changes between debug and release code!

    Thanks, Captain Obvious!

  • siciac (unregistered) in reply to Herby

    "Deep" vs. "Shallow" copy as terms.

    TRWTF is that shitty heap and vtable based type systems make trivial operations like equality an exercise in graph theory.

  • Nagesh (nodebb)

    This is most boring article I am reading on dailyWTF.

  • LCrawford (unregistered)

    Surprised I didn't see a debate about whether Yak milk is really dairy or not. (It is dairy). "a type of food produced from or containing the milk of mammals"

  • desertrat (unregistered) in reply to Bill

    Maybe they work for Volkswagen, in the emissions control management group :-P

  • Yazeran (unregistered)

    Shallow vs. deep copy.... Ouch

    Bit me once upon a time in my first database project. Had an array of hashes, and had to make a copy to change some of the values in one of the hashes.

    made the mistake of only copy the array... Changed a value in the copy and boom, the change showed up in the original as well. I remember that it took me far too long to figure out...

  • Ugh (unregistered)

    TRWTF is that shitty heap and vtable based type systems make trivial operations like equality an exercise in graph theory.

    It's not equality, it's assignment. In C++, := vs. ==. The former, rather than the latter. The fact that C++ allows you to override the assignment operator is quite powerful, but should mostly be left alone. That's why it's been removed from just about every language created since.

  • powerlord (nodebb) in reply to Herby

    Deep and shallow copies are terms used quite a lot in object oriented programming.

    Shallow copies means that for reference types, you're just copying their pointers.

    Deep copies means that you're creating brand new objects for reference types using the values the original objects had. This is basically why copy constructors are a thing. Which in turn is why a class can access private variables of the other objects of the same class.

    Addendum 2017-04-17 19:00: Edit: Right, should have mentioned that these apply to the properties of the object you're shallow copying rather than the object itself. i.e. shallow copying an object doesn't mean you just copy a reference to it, but the references it's storing.

  • Lerch98 (unregistered) in reply to CrazyEyes

    Apparently you were stoned in High School. Java does not use pointers.

  • OlegYch (unregistered)

    TRWTF is mutability

  • ph (unregistered)

    The poor bastards did not know how to use a data breakpoint. Bless their souls.

  • foxyshadis (unregistered) in reply to Lerch98

    You do realize references -- including object references -- are just pointers with a few restrictions, right? Most of the benefits of either apply to the other. And you could read that it was his teacher, and not CrazyEyes, that said that, right?

  • dkf (nodebb) in reply to gleemonk

    If you're pet language can't do COW it's shit.

    The problem with COW is that it doesn't work well with shared-memory parallel programming; either you end up making far more copies than you need (which has a very high cost) or the cost of deciding when you don't need to make a copy is very high (because of the locking required to make the decision consistently). OTOH, if you don't need shared-memory parallelism, COW is pretty awesome.

  • TheDailyWTF - Where every language choice is wrong (unregistered) in reply to ph

    "The poor bastards did not know how to use a data breakpoint. Bless their souls."

    Only in this version of the story. In reality, it was of course quite different. I am more familiar with the facts.

  • ichbinkeinroboter (unregistered)

    I learned about pointers (or at least the very same concept) doing Z80 machine code as a 9 yr old. I am SO glad I did. I have been surprised how many (otherwise totally decent programmers) really struggle with the concept. Though when they do get it, the mental images they use to "get it" can be highly entertaining (multi dimensional, in one case, you know, like space-time)

  • Quite (unregistered)

    Maybe I'm getting old, but I am losing patience with extraneous and irrelevant details. This "story" could (and I argue should) have been a quarter its length.

  • SomeDude (unregistered) in reply to Quite

    Yes ... I think you ARE getting old.

  • W.S.Gosset (unregistered) in reply to gleemonk

    Quite. Object-oriented code MEANS deep copy.
    "Shallow copy" is a compiler-driven bodge, or rather a compiler-writer's shortcut bodge. Makes life so much simpler for the compiler writer. Just copy the pointer. Its effect is to utterly bebuggerate the concept of object-oriented design/code.

    "Amusingly", this half-assed shortcut by Bjarne --another symptom of whose eye-watering pseudo-optimisation drive being C++ being a 2-pass compiler (argh)-- has culturally led to every man and his dog imitating it because "that's how you do it".

    Java is beyond excruciating, but the fact that even Python followed along still makes me weep. Can't code hard unless you learn the compiler rather than language. So near and yet so far.

  • Jerepp (unregistered) in reply to Lerch98

    Java is pretty much pointers all the way down... it just doesn't show them to you or allow you to talk about them.

  • W.S.Gosset (unregistered) in reply to Lerch98

    "Apparently you don't understand Java nor pointers."

    Wrong. Java uses double indirection rather than single indirection. Pointers are an indirection mechanism and the one used by Java. Your Java object handle is a pointer to a pointer. Absolutely standard double indirection. Very useful in the right circumstances if done properly. Java unfortunately decided to cock it up.

    Two key bodgearounds: The first is Gosling's insistence on Java being entirely pass-by-value. OK if done properly, carnage if not. Example: it is impossible to swap 2 objects in Java. Triumph!

    The second is actually worse: the eye-watering split between objects and "primitives". Primitives are deepcopied. Objects are shallowcopied AKA bodged as a value-only copy of the reference's first-pointer's value. This is a compiler-shortcut-driven bodge-around. This is actually worse than C++'s by-reference --or rather, manual/coder's-choice-- approach. At least there you aren't fooled by a few easy wins. But because primitives are deepcopied, crap pseudo-object structures can often hide the problem from coders who aren't very good, or else either haven't had much education or never really grokked what they were taught. Copy just works for them, because they're not trying to actually benefit materially from the concept of object-orientation.

    You see the same with most 3GL coders writing anguish code for RDBMSs. Oh sweet jesus make it stop, although you then understand the urge for "NoSQL" aka ISAM.

    An analogy is people extolling the virtues of a BMW M3 as a shopping cart, because you can get more inside the BMW than the average shopping cart. When you point out you can start the thing up and go 10 times faster, rather than pushing it, they say you're an idiot.

  • W.S.Gosset (unregistered) in reply to SomeDude

    Yes ... I think you ARE getting old.

    I agree. And more accurate with every day.

  • W.S.Gosset (unregistered) in reply to gleemonk

    Assignment just copying a reference is the real WTF!

    Quite. A short fast hack to shortcut the hard work so that a full complete (then)coder-friendly system could get out the door and usable before the sun cooled. More power to Bjarne, but, still, you wish...

    Don't underestimate the importance, though, of getting Something-Working out the door fast, in a timely fashion. Bear in mind the entire worldwideweb is in fact just the outgrowth of only one side of the original web intention. We are using solely the Read-Only Web. It was supposed to be Read-Write. Wossname punted his readonly example out the door as a frustrated ohforgodssakewontpeopleLISTEN example of what could one day be possible.

    Unfortunately, the whole original intention got lost.

    We are now using only the ReadOnly web. With a lot of stick-on stuff to bodge up the readwrite/interactive stuff, which is a pale shade of the original design's capabilities.

    Hey ho.

  • W.S.Gosset (unregistered) in reply to W.S.Gosset

    ... i.e., I'm posting this via a Prototype gone viral...

  • W.S.Gosset (unregistered) in reply to Bill

    The real WTF is not that there are two different ways a language can deal with assignment, it's that the method used changes between debug and release code!

    Very much so. I'm still boggling.

  • NoLand (unregistered)

    I'm rather astonished by the discussion on pointers/references: After all, these are an important and essential concepts of computing. You simply can't do strings or complex data structures or any kind of look-up or search without pointers (AKA indirect addressing, or at least, indices, which are yet another way of indirect addressing). Even the very first Turing-complete machines incorporated them in some way. Exposing some of this in a higher level language only makes sense, as it allows, in turn, the implementation of more complex logic. We may want to prefer implicit references over C-style pointers, because they provide a more controlled and restricted access to this feature, but this is rather a matter of taste, bravery, and debugging budgets. But, in general, shallow copies is pretty much what we want, when processing data. Where we need a deep copy, this is more often an edge case than the general routine.

  • hm (unregistered) in reply to LCrawford

    Well the conversation was about Yak butter, milk was only mentioned in passing. Butter is churned milk, so of course it's dairy.

  • Lerch98 (unregistered)

    Pointers and handles are references. But Pointers and Handles are not interchangeable. A pointer is an address. A Handle is just that, an abstract identification.

  • TheDailyWTF - Where every language choice is wrong (unregistered) in reply to Lerch98

    "Pointers and handles are references"

    Sure, in the common meaning of the words, but in the C++ language a "reference" and a "pointer" are different things; when dealing with C++ or people who think in C++, I tend to avoid using the words at all unless I specifically mean the specific thing in the C++ language spec.

  • Isn't the Point of debug... (unregistered)

    The biggest issue here is that the behavior is changing depending on what mode it's compiled in, that's pretty ridiculous.

  • akozakie (unregistered)

    Ahhh... Nothing like a good, well implemented heisenbug to warm up the brain...

  • urkerab (nodebb)

    Although copying primitives is straightforward, some data structures, such as doubly linked lists, need special behaviour. It's up to the object to ensure that it copies itself correctly.

  • raja tempat sampah (google)
  • raja tempat sampah (google)

Leave a comment on “What Equals Equals”

Log In or post as a guest

Replying to comment #:

« Return to Article