Borderline Personality Disorder: Treatment Resistance Reconsidered - the-enemy http://www.psychiatrictimes.com/special-reports/borderline-personality-disorder-treatment-resistance-reconsidered <comment><AUTHOR> I'm a psychiatrist, and I'm heartened to see this show up in the HN top-10. Lots of people have someone in their life with Borderline PD (or at least features). It's a serious impairment that sometimes gets vilified or downplayed as "just a personality disorder." If people could "just stop doing it," they would.

It can be hard to maintain steady, honest empathy for people with Borderline PD, but their suffering is very real.

<comment><USER2> I was diagnosed in college. I went through a few relationships and got attached like crazy, early. That drove the person away and I'd get desperate/angry. Rinse, repeat.

Prescribed a drug that made me much more depressed and started cutting. I stopped taking it, and later met the person who is now my spouse. Early in the relationship I got fraught that it would end, so I tried to end it preemptively. That didn't work, thankfully.

It was really a relationship where I could for the first time just be myself and not "front", so it just felt right. My pysch was not convinced and warned me, rightly so. But, we moved away from that college, got married, have kids, and really haven't had any emotional rollercoasters since (over 10 years later).

But occasionally I have emotional scares/thoughts but they usually subside. Also, since I'm on a throwaway, when we first had our first child I kept getting murderous thoughts about how to kill it whenever I got frustrated. These scared me, and through some introspection, my own aim seemed to be to get an emotional response from myself. Especially since these thoughts typically included how I would immediately regret harming my child and how others would react.

So I feel like it's still there, but my hormones leveled out or something happened to allow me to manage it.

<comment><USER3> From my anecdotal experience, this kind of intrusive thoughts stems from being afraid of your emotions. Being afraid that anger of frustration overpowers you and you'd do things that would destroy your life.

It's important to understand that emotions can't 'force' you to do anything. You fuel your intrusive thoughts by not allowing your frustration to vent in an appropriate manner. Just sighing and saying 'I am frustrated, oh well' when you are can help a lot.

Intrusive thoughts are like a mild case of OCD, and with a bit of psychotherapy the will disappear.

<comment><USER2> Soon after I moved I also started working out. I've gained about 50 lbs (mostly muscle), and have much better self-confidence. I would also say that helped.

My diet has also changed a lot, like another commentator mentioned.

Too many variables!

<comment><USER3> Glad that you are doing better! I hope you are also able to unlearn the thought patterns that are learned during an emotional crisis. "Emotions are dangerous and I have to control them" is one of them. While these thought patterns subside when everything is fine they may come back when life goes into hard mode. There is a great comment in a psychologists AMA on reddit regarding thought patterns: [https://www.reddit.com/r/AskReddit/comments/4vwsqc/psycholog...](https://www.reddit.com/r/AskReddit/comments/4vwsqc/psychologists_of_reddit_what_are_some_very_common/d629eh8/?st=jaqvn2fq&sh=b9dc9ede)

</comment></comment></comment></comment></comment><comment><USER4> (Disclaimer: not a mental health professional, but someone with personal experience in this matter)

BPD is one of the cases where our current approach to mental health falls short in a way. We only consider someone mentally ill if their mental dysfunction impairs their life. If someone's mental dysfunction only ruins the lives of the people around them, that's not technically a mental illness.

Borderline is a perfect example of this. It's true that a borderline will compulsively sabotage their own relationships, as well as any other relationships surrounding them (borderlines are great at turning third parties against each other and are savants of "Lets You And Him Fight"), but if they manage to find the right enablers, or jump from relationship to relationship fast enough, they can manage to avoid suffering too much from their dysfunction while leaving a trail of damage in their wake.

That's why borderline is so fundamentally hard to treat. It's so easy for some borderlines to develop the coping mechanisms to evade the consequences of their actions that they're not affected, and "fundamentally caring about someone other than yourself" doesn't seem to come naturally to a borderline.

<comment><USER5> > That's why borderline is so fundamentally hard to treat. It's so easy for > some borderlines to develop the coping mechanisms to evade the consequences > of their actions that they're not affected, and "fundamentally caring about > someone other than yourself" doesn't seem to come naturally to a borderline.

I wonder how helpful psychedelics would be in treating the narcissistic aspect of BPD. Revelatory experiences (coming into contact with the Great Other) and ego death might reset the dysfunction of one's personality. Or at least give that person greater perspective and insight into their condition.

<comment><USER4> I wish research into psychedelics wasn't as stigmatized so we could find these things out. There's always going to be the problem of someone wanting to be treated before you can treat them though, which makes any narcissistic issues hard to deal with.

</comment></comment></comment><comment><USER6> > Recovery, that is attending work or school and sustaining at least one > meaningful relationship, occurred for 60% of patients for 2 years, and was > maintained in 40% over 8 years.

So is that the same 1 'meaningful relationship' for 8 years? Did they try asking the other person in the relationship whether the patient was in 'remission'?

<comment><USER7> I don't have enough upvotes for this.

Or working with someone who has BPD. They don't get anything done. They play office politics to a ludicrous degree. They blame everyone else for anything that happens. _But_ they know who to suck up to, and they know how to make it look like they're getting work done. So they don't get fired.

Keep a relationship or a job means _nothing_ unless you ask everyone _else_ if they're getting better. If the answer is "OMFG I'm still walking on eggshells around that person", then they only progress they've made is to fool the therapist.

<comment><USER8> I'm especially gutted to read stuff like this, having been recently diagnosed with a moderate to severe case after not understanding my behavior for over thirty years. Have you ever asked someone with BPD what it's like to live with themselves? To cry and drink themselves to sleep because they don't understand why they're like this? How they can't fathom why they're completely and utterly alone when it seems like they're doing everything right, but going off the deep end every now and then without any earthly idea why? How they'd much rather embrace a bullet to the fucking temple than deal with this godawful sickness and a world full of indifferent people like you for just _one more day?_ Pray tell, have you ever asked someone what it's like to feel like _life itself_ is a prison from which you can't escape, trapped with a person you can't even begin to explain nor relate to?

Didn't think so.

I get my work done, dude. It's like no matter how much I try to keep other people happy, _nobody_ gives a shit and assumes I'm like everyone else they've ever met who claims to have it, and they're confidently able to predict who I am based on a label. You sure have the leprosy of BPD figured out; sounds like I should be playing more office politics, since that's what I'm supposed to do, apparently.

A not-insignificant portion of this thread sucks, is just outright depressing, and suggests to me that there's little hope for ever successfully loving or communicating with other people. And you know the worst part? I fall in love easily because I want absolutely nothing more than to feel that connection with another human being. Comments like this remind me of the futility that lies therein. I shouldn't have read the comments, and I knew better when I clicked it, but I did it anyway in the vain hope that I would read something to inspire me to keep pressing forward. How's _that_ working out, you ask? Makes me relieved I bought a tall bottle of Goose at the store earlier, thank you.

Your other, horrible comment comparing BPD to incontinence makes me want to say something really nasty, emotional, and visceral to you, but I'm strongly resisting because it would just reinforce your fucked up belief structure about people who are genuinely suffering on a level that you can't even comprehend. Seriously, I've clicked Edit and typed some of the meanest things I've ever said several times now, but I also know to resist that overwhelming urge for both of our sakes. How's that for your opinion of people like me? Do I fit your box?

I genuinely hope you find it in yourself to develop empathy for people who aren't as advantaged and in control of their lives as you. I'm sorry to rebuke you so harshly, but Christ.

<comment><USER7> > Your other, horrible comment comparing BPD to incontinence makes me want to > say something really nasty, emotional, and visceral to you, but I'm strongly > resisting because it would just reinforce your fucked up belief structure > about people who are genuinely suffering on a level that you can't even > comprehend.

As is typical in borderlines, you missed my point entirely. My comment was about the impact this disorder has on others. Because of the disorder, your pain is so large that you _are blind_ to the impact that the disorder has on others.

That's the problem.

I sympathize with you, I really, really, do. I wouldn't wish it on anyone. But ultimately, it's _your_ disorder, and is _your_ responsibility to fix.

If you want to help yourself, read:

[https://news.ycombinator.com/threads?id=throwaway29845](https://news.ycombinator.com/threads?id=throwaway29845)

Then, take the advice to heart. You will be happier by far.

One problem with the disorder is that the lows are tempered by highs. It's _exciting_ to be emotionally involved, to think the world of someone, to be on the "high". And then it crashes, and you feel like shit.

I've read a lot about BPD, and things written by BPD sufferers. Despite the lows, most are _also addicted to the highs_. And they can't deal with the underlying disorder until they break the addiction.

As an example:

> I fall in love easily because I want absolutely nothing more than to feel > that connection with another human being.

That's the emotional high I'm talking about.

You _can_ get away from the lows. But the cost is that the highs are also mitigated. _This is how most people live_. There are few extremes. Just every day fumbling through life. Life is this: just living.

> I genuinely hope you find it in yourself to develop empathy for people who > aren't as advantaged and in control of their lives as you.

That is another typical BPD comment. You know nothing about my pain, my experience, or my journey. But because _you 're_ in pain, then _my_ life must be wonderful.

Stop splitting. Decide to just _live_. Decide to not inflict pain or suffering on others. Work on the addiction to the highs.

If you want to talk more, email me. My email address is in my profile.

<comment><USER8> See? Got me figured out from a label.

I didn't miss your point. The part that made that comment horrible is "you're not allowed to come over until you stop peeing on my couch," like human beings with a regrettable, painful, mortifyingly embarrassing condition are untrained dogs to you. Like it's something they can just stop. That's what you said: figure it out, then I'll let you sit on my couch. I considered the possibility that I misinterpreted you here, then noticed that I wasn't the only one, if so.

Then you did the exact same thing here, too. "Stop splitting." "Decide to stop hurting people." "Just flick off this light switch that's taken years of therapy to even understand, buddy! Just live! Just be!" Okay, Julia. You're talking about serious, life changing journeys that require a lot of help and support along the way, and paying them the same respect as taking the car through the wash.

I'm not blind to my impact on other people. As is typical in armchair psychologists, you missed the entire part of my comment where I talk about how _intensely_ aware I am of my impact on others. That's this entire comment: _oh, he has this condition, let me ignore everything he said and talk to him with my years of psychological training. Maybe that will get through._

I'm not splitting with you and acknowledge that I know nothing about your pain or journey. I know only what you've chosen to share in commentary here, and brother, it's enough of a display of malempathy to make me conclude that your opinion matters very little to me. I didn't even need my disorder to make that determination. The follow up didn't do a lot to help.

<comment><USER9> Who is Julia? Just curious. Thanks for sharing your perspective and following up with the other poster in detail.

<comment><USER8> For some reason, "decide to just live" made me think of _Eat Pray Love_. Mental reference I don't fully understand either, don't worry.

<comment><USER10> As a BDP self-diagnosed here in the post, I fully understand why you did this. I also did it in the past without knowing why but today I got some reflection about it, mainly with this topic and your reluctancing in understand that the way your argument is severely biased because of this condition we share.

<comment><USER11> Please don't self diagnose. Not much good comes out of it, as you can't act upon it with treatment such as therapy or medication. Please see a professional instead.

</comment></comment></comment></comment></comment></comment></comment></comment></comment><comment><USER12> If people get one thing and only one from this thread, it should be this: the vast majority of popular work on BPD (e.g., _Stop Walking on Eggshells_ , mentioned below, and _" I hate you, don't leave me"_, etc.) is based on research that is _decades_ out of date and substantially obsolete. If you want to learn about BPD, start with the research on Dialectical Behavior Therapy [0] and grow from there.

Before you write off BPD people or assume you know how this disorder works or what the prognosis is, take the time to read up on more recent work in this field. BPD is one of the least-understood diagnoses in the DSM, and most people who write about it appear completely unaware of the last ~30 years of research on this disorder.

[0] [https://en.wikipedia.org/wiki/Dialectical_behavior_therapy](https://en.wikipedia.org/wiki/Dialectical_behavior_therapy)

<comment><USER13> >> BPD is one of the least-understood diagnoses in the DSM

That's funny because from what I've read, DBT is the only proven treatment for any of the personality disorders and it's used for BPD. My reading suggests that SPD is the least understood, and probably the most common among HN readers (that part is speculation on my part).

<comment><USER14> according to the wiki page on SPD[1], it is not currently recognized in the DSM

[1] [https://en.wikipedia.org/wiki/Sensory_processing_disorder](https://en.wikipedia.org/wiki/Sensory_processing_disorder)

<comment><USER15> I think he means this:

[https://en.wikipedia.org/wiki/Schizoid_personality_disorder](https://en.wikipedia.org/wiki/Schizoid_personality_disorder)

<comment><USER16> The first one has a correlation with ADHD and Autism Spectrum Disorders. Both of which I'd imagine are fairly common among HN readers.

</comment></comment></comment></comment></comment><comment><USER17> If you have someone in your life with BPD or NPD you should do whatever you can to distance yourself from them, or cut them out entirely. As much as I feel bad for them, there is nothing you'll be able to do to help them without sacrificing yourself in the process.

<comment><USER18> I think it depends entirely on whether they're willing to work on it, and how they act when they're in a bad state.

I have a partner with BPD, and she's put a lot of effort into getting better (and I've seen real progress), and at her worst she's never really acted maliciously or cruel. Still, way more extreme highs and lows than any other relationship I've been in, and I've stopped seeing them as much just because it's so exhausting.

<comment><USER19> I applaud your effort, and I don't want this to be hurtful, but borderlines are chameleons, and I want you to guard against false hope. Good luck, but I'm afraid it is a battle that cannot be won (at this time).

<comment><USER20> There's a wide spectrum of severity when it comes to personality disorders; just because one person with BPD is beyond help doesn't mean others are unable to lead reasonably normal lives with the disorder.

<comment><USER19> Perhaps, but uncertainty plagues all those in the borderline's sphere of influence, and more likely than not, it's a save yourself situation. If you are realistically willing to give your life for this BPD, then by all means stick it out and good luck to you. But don't presume it is any more hopeful than highly unlikely of even leading a troubled relationship. Most likely a relationship full of anguish - probability speaking.

</comment></comment></comment></comment></comment><comment><USER19> I'm a child of a borderline with narcissistic tendencies. I had PTSD until the age of 38, then underwent EMDR therapy that changed my life. I can now live a full life, and I accept there is absolutely no reason for my mother to ever be included in my life again.

I praise anyone's attempt to help a BPD, but I hold no hope for a solution.

Some referred to "Stop walking on eggshells" as outdated, but I found it a revelation that significantly helped in my understanding and recovery.

<comment><USER21> (wikipedia) Eye movement desensitization and reprocessing (EMDR) is a form of psychotherapy developed by Francine Shapiro which uses eye movements or other forms of bilateral stimulation to purportedly assist clients in processing distressing memories and beliefs.

boop beep

<comment><USER19> The closest thing to a magic wand I've ever seen seen or heard of. Living with trauma for 38 years only to have it wiped away in 5 50 minute sessions. Amazing! I then spent 3 years in psychotherapy learning to be a person (literally a child in an adult's body), but it was life saving. Profound.

</comment></comment></comment><comment><USER22> For those who didn't read it:

The headline may seem to be saying "BPD is now more treatable than before," but that is not what this is.

The tldr; is actually more like "framing BPD patients as resistant to treatment is wrong. The correct framing is that we don't have adequate treatments for the disorder."

</comment><comment><USER10> I've read all comments here and about BPD. Most of them just confirm that people with the disease (which I could be included) should feel untrusted because the "only" solution proposed is to avoid them. Therefore, they are right and have no mental disease. It is self defense to avoid people that don't give you the value you give yourself. So it is more a problem of self- expectation/delusion or the people around you. Both have fixes.

</comment><comment><USER9> Reading this thread is very disheartening. BPD symptoms are so common, and probably possible to see from afar, for instance the lone wolf who got picked on in school probably has better than average chance of eventually developing such symptoms.

</comment><comment><USER23> I have (or had) borderline personality disorder.

I didn't realize that there was anything really wrong with me until the end of 2014. I had destroyed yet another relationship in a spectacular, irrevocable fashion. The pain was unbearable. And familiar.

I isolated myself for the next two years.

My childhood was chaotic. My father was an alcoholic. My mother booted him out by age two, but he remained a volatile and destructive force in my life until he dropped contact with me after my fifteenth birthday.

I had step-parents and step-siblings on both sides. People came and went. I had siblings and then I didn't. I learned that relationships are unreliable.

I was verbally abused by one of my mother's men. He was a violent man. He broke down doors, shook his children, and screamed a lot. I still remember how his eyes bulged when he was angry, which seemed to be always.

I remember how he would go out of his way in the mornings to drop his kids off at school first, even though we passed by my school on the way, just so that he could scream at me in private. Everything was my fault. Always.

At age eleven, I accompanied my mother to the police station because she'd just shot my father's deranged girlfriend, who'd followed my father to our house in the middle of the night threatening to kill us. I remember how she cried. I remember writing my deposition.

The girlfriends survived but was later murdered by someone else. She had two kids. I never saw them again. I had originally thought she was a cool person.

I didn't realize any of this was abnormal or damaging. I was a child. By the time I entered adolescence and began discovering that I was gay -- in a small, rural, Christian-dominated Texas down -- I had a total breakdown. I developed symptoms of panic disorder, OCD, hypochondriasis, paranoid thinking, and depression.

My mom took me to a psychiatrist, and he didn't know what to do with me. Mostly because he didn't know any of this. I was a weird kid. I talked to him about the origins of the universe because I was entering my philosophical phase. They put me on Paxil. It turned me into a zombie.

I started drinking in my early twenties. At first it wasn't much, but it grew and grew. I got to the point where I was no longer in control. After the calamitous end of my five year relationship (one that because of me, had grown incredibly toxic) I downed half a bottle of vodka and chased it with some clonazepam. I texted my ex and he, alarmed, summoned the paramedics. I was involuntarily confined for three days.

I destroyed many relationships and hurt a lot of people.

It took a lot of pain to make me wake up.

I stopped drinking. That was extremely difficult. I'm six months sober now. I go to therapy weekly. My relationships are stable (if few in number) and I no longer experience dramatic swings in emotion. Well. I still have days where I think about shooting myself in the head, but it's so mild compared to what it used to be. I can handle that, easily.

I still feel like my identity is a construct. I'm staggeringly insightful about people; I can read them very thoroughly and very quickly. I am subtly manipulative by default. It's not something I can turn on or off.

But I decided to do no harm. I started thinking about it as a sort of superpower I have, one that must be used with great care and responsibility.

People with BPD are often extremely empathic. That is not the same thing as having empathy. Being able to assess another person's emotions and state of mind is the raw instrument; deciding what to do with that information is what defines empathy (or lack thereof).

Mindfulness and meditation have been helpful to me. So has regular exercise, therapy, and a very great deal of introspection.

I still have doubts about my ability to form meaningful relationships. I am very lonely. All the time. I worry that I will go through decades like this.

But at least I'm not causing a lot of pain and turmoil all around me.

People with BPD can change. But it takes work. And you have to acknowledge and face the pain you've caused, which can result in unbearable guilt.

And you have to learn how to be alone.

<comment><USER24> > I started thinking about it as a sort of superpower I have, one that must be > used with great care and responsibility.

Bingo. Well done you. I've struggled with mental/emotional problems all my life, thought that I was cursed even, and accepting that I'll never be cured [1] is the game-changer. For readers: it forces you to think how you can >>manage<< them better, and how it can actually be >>useful<<. This can be hard at first, and will continue to be a lifelong struggle, so patience, lots of them. Eventually you'll be able to pinpoint your 'problems' and their triggers, and build up the discipline to adapt via lifestyle change. You'll also begin to understand how these can be turned into, well, 'superpowers' when you're in a calmer state of mind. Like the ability to empathise is frequently overlooked when it's actually very powerful. (But please, don't start looking to _be_ powerful, for sure this will cause grief sooner or later!)

Solitude imo is not necessarily a bad thing, it encourages more introspection and independence once you train yourself to embrace it. As long as you balance it with the right amount of positive socialising of course.

[1] If you feel _severely_ affected, PLEASE sought out professional help. Or at the very least, people who you can trust to be kind

</comment></comment><comment><USER25> I know something's wrong with me, and I need to be treated, but what could be a better that killing myself. It looks like this is the only thing that will work. [https://m.youtube.com/watch?v=wp3yreeTUmU](https://m.youtube.com/watch?v=wp3yreeTUmU)

<comment><USER26> First take a psychological evaluation, that will tell you what the problem is.

</comment></comment><comment><USER27> I can't read beyond the first page, so I am curious what is the treatment for a personality disorder.

<comment><USER12> Different ones are treated differently. For BPD, at this point the pretty well-recognized standard is called Dialectical Behavior Therapy (DBT) [1].

[1] [https://en.wikipedia.org/wiki/Dialectical_behavior_therapy](https://en.wikipedia.org/wiki/Dialectical_behavior_therapy)

</comment></comment><comment><USER28> In my opinion BPD is a combination of [false beliefs / a false worldview,] usually created by toxic (or abusive) imprinting during formative years, along with higher-than-average emotionalism (which is probably genetic).

I'm not surprised that it's treatable in most cases, assuming it's not TBI related. False beliefs gradually go away; rough edges in character are gradually worn down with life experience and maturity.

Poor imprinting is difficult to overcome, I think certain tenancies always remain, but one can learn to direct emotional energy in better / more productive / less destructive ways.

<comment><USER29> Though your comment is downvoted, it is broad terms quite correct.

There is strong evidence of a genetic component to BPD. It is a personality disorder and therefore a result of (abusive) training in childhood. And it is possible to learn to improve one's emotional instability.

I do have the sense that you're simplifying the issue in away that disguises the more complex reality of BPD. I do not recall the genetic factors pertaining to emotion. A failure to regulation one's emotions is partly connected to a general impulsivity which arises in a traumatic environment where you are always on high-alert.

NB.

It's always interesting what gets down-voted on hacker news. The police will chastise commentators who are too emotive in their phrasing but not the downvotes who most actively prevent open discussion.

</comment></comment><comment><USER30> [Throwaway account, for obvious reasons.]

I'm pretty sure my wife has BPD. To me, it seems hopeless for her to get treated. I haven't brought it up with her, I expect that would go poorly. One of the main symptoms is that she feels attacked by people even when they are making innocent comments on things. It is not just me who as noticed that. I have discretely brought it up with some others who know her and they have confirmed it. She has cut ties to her family as they are "toxic people".

Based on my readings, I understood that most psychiatrists think treatment is unlikely to work. If there is hope, that would be amazing. It is a difficult condition to live with, both for her and people who know her.

<comment><USER4> As someone who had a close personal relationship with a borderline for years: _get out_. A divorce will be nasty, particularly with a borderline, but a lifetime spent with such a person will not be a happy one.

With any kind of mental health, the person "suffering" from it has to be the one who wants treatment, and with BPD, most of the suffering ends up outsourced to others, which eliminates that motivation.

I know this is hard to hear, but part of BPD is an inability to form healthy relationships. The flip side is that it takes two people to maintain an unhealthy relationship. You're not helping her by staying in this marriage; at best, you're enabling her and at worst, you're suffering from her mental illness at least as much as she is.

<comment><USER12> This advice is pernicious and self-serving bullshit.

You don't know the poster or his/her wife.

You don't know the wife.

You don't have anywhere near enough information (unless you think a BPD diagnosis or suspected diagnosis is in itself sufficient information, in which case you're contradicted by a very well established line of research going back a number of decades; see links I've posted elsewhere in this thread) to assess the poster's wife's mental state or likelihood of recovery.

Your comment completely misunderstands how BPD works and completely misrepresents the likelihood of recovery. I understand that you may need to prove to yourself that you made the right call by cutting off someone with this disorder in the past, and maybe you did -- but that isn't epistemic justification for the very conclusory advice you're offering the poster.

<comment><USER19> This sounds like splitting, exactly what a BPD would say. I am suspicious.

<comment><USER31> Splitting is also common among individuals who have upset personality disorder. Such a horrible disease; I can only hope we once live in a world where upset personality disorder is identifiable and treatable.

<comment><USER11> Upset personality disorder?

<comment><USER10> I guess it was a joke that splitting is a common human behavior and should not be qualified as a disease because someone overuses it.

</comment></comment></comment></comment></comment></comment></comment><comment><USER9> This thread helps confirm my long term desire to self terminate. I didn't have much insight into how a bpd looks from both sides but it's clear to me that having a psychiatric disorder can put someone in a whole different universe from others despite appearances.

If someone believes others are out to get them, if they're sensitive, or whatever behaviors they manifest, who is anyone to say what they feel is right or wrong? Their behaviors may not fit in with society at large, but nobody can speak to their perceptions.

The world is complicated now and people on average have a more intricate social universe than ever before. I'm sad to say that I couldn't find my place in human society. Seeing where I am at personally relative to what I've learned from this thread is very painful.

Wishing for the best for everyone here. Nobody should have to suffer and it's commendable that so many fight the good fight. Be well.

<comment><USER32> Please don't, it's absolutely possible to turn things around and live a wonderful and happy life. I can tell you this from personal experience.

I've spent the past few years searching for ways of overcoming emotional and personality disorders in myself. Looking back, it's pretty clear that there were significant symptoms of narcissistic/borderline/histrionic personality disorders, that had devastating effects on my relationships and my career.

I've worked on myself daily for the past few years to understand and overcome these traits. In the past 1-2 years I've come out of the tunnel and am now living a very different life, with a thriving career, a wonderful home, dramatically improving relationships with my friends and family, a great relationship with a wonderful, caring partner, and every reason to be optimistic about the future.

Just 3 years ago I was like you, thinking it was all futile and questioning whether it was worthwhile to carry on.

Please get in touch. It's hard to find good advice and support but I think my experiences and learnings could be valuable to you.

My email address in my profile.

Please, you are valued and loved, and there is hope.

</comment></comment><comment><USER33> Another Freudian shibboleth called into question.

</comment><comment><USER34> If someone wants to see what Borderline is like, read this [https://www.reddit.com/r/relationship_advice/comments/7gyl8d...](https://www.reddit.com/r/relationship_advice/comments/7gyl8d/cheating_gf_used_pregnancy_to_make_me_stay_prob/) Some poor soul posted this today.</comment>


Edward C++Hands - T-zex http://bartoszmilewski.com/2013/09/19/edward-chands/ <comment><AUTHOR> The H.264 encoder I use is written in a mixture of C and ASM. It is damn fast and maxes out all cores.

I dare you to write a full-featured, functional H.264 encoder in Haskell with equal or superior performance. Once such a thing exist I will start believing the hype.

Until then I reserve the right to consider the current Haskell/FP craze the biggest amount of bullshit since the Java/OOP craze.

Sorry people, I already know that magic language/paradigm which solves all problems of software engineering. Which allows me to write 4 times less code, said code being robust and maintainable practically by default, yet as fast as C/C++ if not faster, all that thanks to this great new model of software engineering! It is the (only) future!

Yes, the Java/OOP/design patterns/UML crowd made exactly the same bullshit claims back then. Nobody talks like that about Java/OOP anymore because the bullshit eventually hit the fan known as reality.

Oh and before Sun's viral marketing campaign there were the Lisp weenies. Again, same bullshit. We already have a "30x less code" language which comes bundled with an insufferable sense of intellectual superiority not backed by practical results.

Oh, and I almost forgot the Python/Ruby "dynamic" and "human" craze. "Programming for human beings" \- it's the (only) future! Back then the snake oil addicts paraded around dynamic typing and code which read like plain English as the salvation of the programmer. Nowadays they claim dynamic typing is the software engineering equivalent of the Holocaust and that good code must look like math!

I am so tired of it..

<comment><USER2> The main micro blogging site I use is a mixture of scala, java, with ruby/iOS for the front end.

I dare you to write a fully featured, async web stack that handles many-core on the scale of hundreds of millions of users in C and ASM within equal or lesser man hours. Once such a thing exists i'll start believing the hype.

<comment><USER3> BBC did this 15 years ago on tiny computers compared to now. They uploaded static HTML onto Sun boxes and served them.

If you did a submission somewhere, it'd do offline processing and upload new static pages.

Most of this was C and perl.

No Scala, no Java, no Ruby.

iOS does HTML too you know.

I agree with the OP - most of this new technology doesn't really solve any problems. All it does is create an ecosystem you can feel superior being a member of.

<comment><USER4> Even better, it's a new ecosystem that interviewers will use as a screen to keep out people who don't know the new ecosystem, and so will require people to learn it, and then in 4 years it will be thrown away because no one does that any more. See, they've moved onto the even newer ecosystem.

</comment></comment></comment></comment><comment><USER5> Every time I read a "scathing" attack on C/C++ for being the worst language the author ever heard of, I hear Jack Sparrow's reply in my head "Ahh... but you _have_ heard of me".

Somehow despite the litany of crippling deficiencies, C/C++ have managed to be the foundation of every piece of technology a consumer or a computer professional will ever touch in their daily life. But yeah, other than that, we should all be using.. oh, I don't know, scala or haskell or something like that.

<comment><USER6> C++ is a legacy language. It was indeed good, about 20 years ago, and we can't shake it because it was good, about 20 years ago.

<comment><USER7> We can't shake C++ because for a number of things, there's still nothing better.

</comment></comment></comment><comment><USER8> Not an easy read for C++ fans like me, especially since it is coming from Bartosz Milewski.

I did try out several other languages and I keep coming back to C++11 for anything that requires scalability and raw performance, like APIs. The same basic server that gets 400 req/sec when implemented in C# ASP.NET achieves 7900 req/sec using C++.

So far I could not find a programming language that does not have similar (or worse) scissors. It's more like "pick your poison" type of choice.

After I learned Scala, my C++ code started to look like functional programming. According to Bartosz that's a good thing, and I did not have to dive into Haskell (yet). :)

<comment><USER9> With C#, did you try using manual memory management? I wrote a rather high- performance (50K requests/sec, 550K ops/sec) daemon in F#. The big trick was to use my own mem management when it makes sense. I had a ~1GB managed heap, and 12+GB unmanaged.

For instance, you can stack-allocate many objects in C# (strings and arrays, for instance), if you're willing to give up the safety (and if C++ is an option, then you are willing). You can manually heap-alloc managed objects, too, although it gets tricky if they are nested objects. After all, the JIT is just taking pointers to objects and doing stuff with them - it doesn't care where the memory came from (just remember the GC won't scan your manually allocated stuff).

The CLR (unlike the JVM) has native capabilities built right into it. People should take more advantage of such things instead of only trying fully safe C# and then deciding to dump it all for no safety.

<comment><USER10> I'm in violent agreement.

To avoid the costs of serialization and deserialization on a per-request basis, I built a little object system that stored all its instance data in a byte array. All internal references were offsets from the start of the array, but what made it fast was that I could read and write in it using raw pointers.

I then recycled the byte arrays to avoid GC pressure, as many were just over the edge of the large object heap, only collectable with gen2 scans.

I had a version working with manually allocated buffers, but it wasn't any faster - GC overhead was only 2% or so.

<comment><USER8> Great! Can you prove it?

There's a benchmark: [http://www.techempower.com/benchmarks/#section=data-r6&hw=wi...](http://www.techempower.com/benchmarks/#section=data-r6&hw=winec2&test=db)

Go-lang is roughly 10 times faster than ASP.NET (implemented as recommended by Microsoft). Skipping the ORM doubles the speed, but then you lose most of the components, so I'm not sure that's a realistic optimization.

Can you do better?

<comment><USER11> In case anyone is curious what is going on with those ASP.NET TechEmpower benchmarks:

The TechEmpower benchmarks are all about how much overhead you can eliminate. I profiled the CPU-bound ASP.NET TechEmpower benchmarks and most of the time is spent in IIS<->ASP.NET overhead. After I removed IIS and ASP.NET by just using the .NET HttpListener class [0], the result (on my machine) gives Go a run for its money. Hopefully these results will show up in the next Round that TechEmpower runs.

I profiled the .NET TechEmpower tests that access PostgreSQL and MySQL and found that the database drivers had a lot of unnecessary overhead, for example the Oracle .NET MySQL provider does a synchronous ping to the MySQL Server for every connection, even if it's pooled. Plus, it sends an extra 'use database;' command. [1] The PostgreSQL provider also sends extra synchronous commands for every connection. [2]

[0] [https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/HttpListener) [1] [https://github.com/TechEmpower/FrameworkBenchmarks/issues/31...](https://github.com/TechEmpower/FrameworkBenchmarks/issues/315) [2] [https://github.com/TechEmpower/FrameworkBenchmarks/pull/325#...](https://github.com/TechEmpower/FrameworkBenchmarks/pull/325#commitcomment-3373154)

<comment><USER8> So C++ is bad because certain functions should be avoided and has no garbage collector. (With C++11 STL normally there's no need for manual memory management or naked pointers.)

C# is good, just you should avoid the garbage collector and 90% of the standard library. Roll your own web server, raw sql commands, have manual memory management, use undocumented calls, emit byte code and there you have: almost 40% of the C++ performance.

I'm the only one who thinks this does not make any sense?

<comment><USER11> No, I'm not implying any of that. I'm just saying that an important step to getting good performance is profiling to determine the cause of poor performance, then deciding whether it makes sense to try to improve performance in the found areas, then executing your decision.

Imagine the alternative if I didn't profile: I'd just declare that C++/whatever is way faster than ASP.NET, and I'd switch to C++ and open myself to a whole world of debugging memory corruption issues whatnot. Instead, because I profiled, I found the areas that could be improved, I wrote the HttpListener code and I can stay on the .NET platform for all of its other benefits. By following this process I have more options than just "C# blows, I gotta throw it out the window for C++".

In reality, I have probably written more useful, shipped, production C/C++ than C#, so I'm also a C++ advocate, but hey, when it makes sense, and for the right reasons, you know?

</comment></comment></comment></comment></comment></comment></comment><comment><USER12> "Ask any C++ guru and they will tell you: avoid mutation, avoid side effects, don't use loops, avoid class hierarchies and inheritance. But you will need strict discipline and total control over your collaborators to pull that off because C++ is so permissive.

"Haskell is not permissive, it won't let you — or your coworkers — write unsafe code. Yes, initially you'll be scratching your head trying to implement something in Haskell that you could hack in C++ in 10 minutes. If you're lucky, and you work for Sean Parent or other exceptional programmer, he will code review your hacks and show you how not to program in C++."

For those who aren't familiar with Parent, watch this talk:

[https://www.youtube.com/watch?v=4moyKUHApq4](https://www.youtube.com/watch?v=4moyKUHApq4)

which introduced me to Stepanov's "Elements of Programming" and the idea that I could be working with better/more reliable/provable abstractions in C++.

That said... after a few weeks of shallowly digesting the material, I started thinking pretty much like Milewski says above: it's great if I can learn to write better C++, but if what I really want is to escape from its specific dangers and general common programming pitfalls, something like Haskell seems like a better bet.

</comment><comment><USER13> Every time I look to use C++ for something, I come away with the knowledge that I will never know the _right_ way to do it in C++. At least with C I know where I stand.

<comment><USER14> I think this is why, for instance, the Linux kernel is written in C and not in C++. And this leads to discussions on the Internet which are definitely funny! :D

[http://stackoverflow.com/questions/520068/why-is-the- linux-k...](http://stackoverflow.com/questions/520068/why-is-the-linux-kernel- not-implemented-in-c)

<comment><USER15> That URL looks even funnier!

</comment></comment></comment><comment><USER16> John Carmack wrote a very interesting post about this same topic. [http://www.altdevblogaday.com/2012/04/26/functional- programm...](http://www.altdevblogaday.com/2012/04/26/functional-programming- in-c/) To sum it up, he's still writing code in C++, but it has become less and less like C++. His code has become less OOP and more functional.

</comment><comment><USER17> Big side note, but C++ for me is just... too much. I come to C++ from Python, and they are just so far from each other it hurts. One of the fundamental things about Python that I loved was:

        "There should be one-- and preferably only one --obvious way to do it."

Meanwhile, the sage wisdom I heard learning C++ is:

        "C++ is wonderful because there are so many ways to do anything."

These two methods of thought fly right in the face of each other, and it's very hard to reconcile. With Python, I felt like I truly was learning a language, a language of action where doing any one thing was consistently defined. With C++ I feel like I'm in an ocean of choice and ambiguity, having to carry around this huge load of tribal knowledge to get anything done.

Not saying it's a bad language, just sharing my feelings on it.

<comment><USER18> Reversing a string in Python is not obvious nor consistent:

        str[::-1]

While it is in C++:

        std::reverse(str.begin(), str.end());

And Ruby is even more obvious and consistent:

        str.reverse()

Most people who rag on C++ have never seriously used it. It's not that bad. Really, it isn't.

<comment><USER19> That's one point against python, and half a point for C++ [1]. By my accounting that leaves the score still hugely in python's favor when it comes to obviousness and consistency.

Python vs Ruby is another subject entirely. Largely I feel like it's mostly a narcissism of small differences situation, and have only been doing more Python than Ruby lately because more people around me are Pythonistas than Rubyists at the moment.

1] ideally you wouldn't have to tell the reverse function the starting and ending points for the string unless you only wanted the reverse of a substring

<comment><USER20> begin() and end() return iterators. Python has iterators too, so this concept shouldn't be alien to Python programmers. reverse() is a generic algorithm that operates on any pair of bidirectional iterators.

Actually, in C++, you ideally wouldn't reverse the string at all... you'd just call str.rbegin() and str.rend() to grab the _reverse_ iterators, and pass them straight to your next algorithm.

The two approaches are just as consistent as one another, Python just uses a terser syntax (which, in my opinion, isn't as obvious).

In C++14, if all things go according to plan with Concepts Lite, you'll be able to write a short 3-5 line, reusable, version of reverse() that takes your string (or container) as one argument, deduces at compile time, during overload resolution, that begin() and end() return bidirectional iterators, and then does the right thing. Failing that, C++14 may introduce Ranges. So C++ is only getting terser.

<comment><USER21> > Failing that, C++14 may introduce Ranges.

It would have been nice to have some sort of simple range syntax added to C or C++ long ago. In the true spirit of C, don't even make it safe, just make it bloody well work.

FirstArray[0..3] = SecondArray[4..7];

case 2..10:

for(int i : 0..ArrayLength)

for(int i : ArrayLength..0)

(hah that'd prove horrible if ArrayLength ended up being a negative number, obviously some proper syntax would need to be determined :) )

I am always annoyed that such simple things are ignored in the language. Sure they don't enable any "cool new abilities", but they make using the language a lot more friendly (especially in comparison to having a ton of case fall through statements!)

<comment><USER20> The problem is your proposed [] syntax implies random access. Many algorithms and data structures don't require or support random access.

</comment></comment></comment></comment></comment></comment><comment><USER22> > C++ "solved" the problem of redundant casting and error- > prone size > calculations by replacing malloc and free with > new and delete. The > corrected C++ version of the code > above would be: > > struct Pod { > int > count; > int * counters; > }; > > int n = 10; > Pod * pod = new Pod; > > pod->count = n; > pod->counters = new int [n]; > ... > delete [] > pod->counters; > delete pod;

The 'corrected C++ version of the code' is actually:

std:vector< int > pod( 10 ); ...

I didn't bother reading any further.

</comment><comment><USER23> Regarding his assertion about reference counting: Apple's implementation of ARC for Objective-C doesn't handle cycles (it requires the engineer to reason about weak and strong references in order to prevent memory leaks), but it is certainly a "serious" implementation. The fact that it doesn't have facilities for detecting and releasing cyclic references makes it definitely not the "other side" of the GC coin.

That being said, ARC-style reference counting is more limited in terms of what developers can do with their code, and it may not be a general enough solution for a language like C++ (which strives to be all things to all people). Weak pointers in Objective-C also require runtime support, which could probably not be appropriate for high-performance applications in many cases.

</comment><comment><USER24> > The power of multicore processors, vector units, and GPUs is being > squandered by the industry because of an obsolete programming paradigm.

It's worth addressing these in turn. In reverse order:

I dispute that the C paradigm squanders GPUs. OpenCL and CUDA are the two most prominent languages written with GPUs in mind, and both have a lot more in common with C than with Haskell. In particular they eschew functional mainstays like recursion, linked lists, and garbage collection. So for GPUs, it seems like the ideal paradigm is closer to C than Haskell.

For vector units, there's some recent excitement about auto-vectorization in Haskell. But I'm skeptical about the potential of auto-vectorization in general, since it only seems to apply to simple loops, and can't take advantage of all instructions. Most effectively vectorized code uses either compiler intrinsics or outright assembly, and I don't see that changing any time soon (I'd love to be proven wrong on this though).

Lastly, multicore processors. C++11 more or less standardized the creaky POSIX threading model, with some additions like thread locals - hardly state of the art. I wonder if the author is familiar with other approaches, like libdispatch, which provide a much improved model.

One last observation. Parallelism is not a goal! Improved performance is the goal, and parallelism is one mechanism to improved performance. If your Haskell program runs at half the speed of a C++ program, but scales to twice as many cores so as to make the overall time equal, that's not a wash: it's a significant win for C++, which did the same thing with half the resources (think battery drain, heat, other processes, etc.) Horse in front of cart.

<comment><USER25> >I dispute that the C paradigm squanders GPUs. OpenCL and CUDA are the two most prominent languages written with GPUs in mind, and both have a lot more in common with C than with Haskell. In particular they eschew functional mainstays like recursion, linked lists, and garbage collection. So for GPUs, it seems like the ideal paradigm is closer to C than Haskell.

I think the more obvious explanation is that it's much easier to write a compiler for C than for Haskell. Thus the first tooling available for any new system is almost always C. It doesn't mean C's the best tool.

>For vector units, there's some recent excitement about auto-vectorization in Haskell. But I'm skeptical about the potential of auto-vectorization in general, since it only seems to apply to simple loops, and can't take advantage of all instructions. Most effectively vectorized code uses either compiler intrinsics or outright assembly, and I don't see that changing any time soon (I'd love to be proven wrong on this though).

We'll have to wait and see on this.

>Lastly, multicore processors. C++11 more or less standardized the creaky POSIX threading model, with some additions like thread locals - hardly state of the art. I wonder if the author is familiar with other approaches, like libdispatch, which provide a much improved model.

My experience is that alternative approaches to something as fundamental as parallelism never take off, because they can't gather an ecosystem around them (I'm looking in particular at the chaos of approaches available in perl and especially python). I think a modern language _needs_ to have a single, obvious, preferred way of achieving parallelism/concurrency that libraries can build on top of (and that's why javascript has been so successful - while it's a terrible language in many ways, there is one and only one way you handle parallel-type problems, and it's (slightly) better than the standard way in other languages)

</comment></comment><comment><USER26> C++: an octopus made by nailing extra legs onto a dog. — Steve Taylor

[http://harmful.cat-v.org/software/c++/](http://harmful.cat-v.org/software/c++/)

</comment><comment><USER27> The author now works for a Haskell company; perhaps this helps explain his changing attitudes towards C++. Or it could be a result of them.

<comment><USER28> Do you mean Corensic? Their homepage is now "under construction", according to Network Solutions.

<comment><USER29> I did work for Corensic, which was bought by F5. It was a company that made a very ingenious data race detector. I learned a lot about data races and how they prevent companies from adopting concurrent programming.

I also used to work for a Haskell company, FP Complete, but I quit, so I'm no longer representing them. I learned a lot about building actual applications using Haskell at FP Complete.

</comment></comment></comment><comment><USER30> I looked at the banner and could think of nothing but "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."

I'm sorry and deserve to be downvoted.

<comment><USER31> Me too!

</comment></comment><comment><USER6> I think Linus sums up C++ pretty well:

[http://thread.gmane.org/gmane.comp.version- control.git/57643...](http://thread.gmane.org/gmane.comp.version- control.git/57643/focus=57918)

<comment><USER32> Do you think anything in that link is relevant to this article or did you just want to get in on the C++ bashing and had nothing to contribute of your own?

<comment><USER6> I think its relevant, honestly. C++ is a pile of hacks, layer upon layer, that only a small highly talented set of programmers can manage to master and the rest shoot themselves in the foot with. Linus says that in his own way, but that's the truth of the situation: C++ is a mess.

My takeaway from experience from all of that is to use C (as Linus argues).

</comment></comment></comment><comment><USER33> C++, the language programmers love to hate :) If you'd like to read some more C++ bashing: [http://yosefk.com/c++fqa/](http://yosefk.com/c++fqa/)

</comment><comment><USER34> > Yes, initially you'll be scratching your head trying to implement something > in Haskell that you could hack in C++ in 10 minutes. If you're lucky, and > you work for Sean Parent or other exceptional programmer, he will code > review your hacks and show you how not to program in C++.

Don't underestimate "instant gratification" even when it comes to programming languages. Yes you might code yourself into a mess further down the line, but most of us are in the business of shipping software not worrying about its correctness.

<comment><USER35> I'd argue that Haskell (which is what I use professionally, can't speak for Scala) lets you write your less well designed code for shipping, and then refactor it later into something clean. There's a very low cost to changing code, so you worry less about getting it right the first time.

<comment><USER34> But in some cases like mine you have legacy code. You still have to ship new features and bug fixes. If I get to green field something really new, then Haskell or Scala might be on the table but currently they are not options. Not even embedding them.

</comment></comment></comment><comment><USER36> Haskell is creating a new value for every parameter / function return value; That means that even for trivial tasks it is churning over non trivial amounts of RAM; the footprint of a Haskell program is therefore rather large; I guess that makes it rather impractical for real systems.

But of course, this one is an interesting observation: "If nature were as serious about backward compatibility as C++ is, humans would still have tails, gills, flippers, antennae, and external skeletons on top of internal ones — they all made sense at some point in the evolution."

I guess C++ is like Perl: for many things there is more than one way to do a thing; Don't like exceptions? Disable during compilation and code as in C with error codes; That's what makes the whole thing malleable; the right kind of flexibility is a winning feature.

</comment><comment><USER37> "It's a common but false belief that reference counting (using shared pointers in particular) is better than garbage collection. There is actual research showing that the two approaches are just two sides of the same coin."

Yeah. But RC is at least _deterministic and controllable_ side. Also, RC is just one of options of C++, while you can implement GC yourself in C++ without any overhead unlike any memory management method on GC.

<comment><USER38> Without compiler support for precise stack maps and barriers (and I don't know if it's actually possible to implement them, given how malleable pointers are in C++) the best you can do is conservative stop-the-world GC. That sacrifices a lot of performance over the incremental or concurrent GC algorithms you see in runtimes like the HotSpot JVM.

</comment></comment><comment><USER32> His entire rant about resource management is misplaced. It's not that new/delete/pointers are "bad" or retained only for backwards compatibility, they are primitives from which other abstractions are built. I don't think its too much to ask professionals understand simple concepts such as RAII, which renders his entire example trivial.

<comment><USER29> I wouldn't have mentioned resource management at all if it weren't for Bjarne's keynote: [http://channel9.msdn.com/Events/GoingNative/2013/Opening- Key...](http://channel9.msdn.com/Events/GoingNative/2013/Opening-Keynote- Bjarne-Stroustrup) . Apparently this is still not common knowledge.

<comment><USER8> Bartosz, Haskell was created 23 years ago, before Java. What is the reason it did not catch on yet? Will that change?

I'm not aware of any even mildly successful system that uses pure functional languages. Most of the implementations I know about is either C/C++/ObjC or JVM. Some Python (Youtube, Dropbox), one .NET (StackOverflow) and pretty much that's it. What do I miss?

[Edit] I'm looking for production code, not "in-house" or "internal tools". I did read trough [http://www.haskell.org/haskellwiki/Haskell_in_industry](http://www.haskell.org/haskellwiki/Haskell_in_industry)

<comment><USER39> FWIW Twitter and Coursera make heavy use of Scala (Twitter also uses Clojure, if you consider Storm etc.)

<comment><USER8> Scala is running on top of JVM (right now).

It is used in production by Twitter, Netflix, Foursquare, LinkedIn, Simple, HealthExpense, Klout, 47 Degrees, Box and a long list of other companies [1].

[1] [http://www.quora.com/Startups/What-startups-or-tech- companie...](http://www.quora.com/Startups/What-startups-or-tech-companies- are-using-Scala)

</comment></comment></comment></comment></comment><comment><USER40> C++ Novice Question: Why are for loops bad? (as mentioned in the article). What's the alternative?

<comment><USER29> You should use standard algorithms whenever possible. Sean Parent talked about it at Going Native. He was able to transform a horrible set of for loops he found in Google's code into a few lines of modern C++ using standard algorithms. But he _is_ Sean Parent!

</comment></comment><comment><USER41> "...avoid class hierarchies and inheritance..."

I love hearing this from OOP insiders. Virtual functions are particularly awful to track down, and are probably worse than GOTO ever was. At least GOTOs only went to one place.

</comment><comment><USER42> > But you will need strict discipline and total control over your > collaborators to pull that off because C++ is so permissive.

Except it's not. The key is proper encapsulation into classes and generous use of private instance variables.

The real problem is social: people want to get something done quickly, so instead of talking to the original author[1], they put a new method in the class (or declare a friend) and happily continue hacking, without thinking of far-reaching consequences of whether _unrestricted_ (that's what public is) use of the newly introduced method violates class invariants in some way.

[1] I'm aware that the original author might not be there anymore. Which makes a good case for documenting design and intent of the code. A QA matter.

How does Haskell solve the social problem (directly hacking something into a module you don't own or fully understand)?

> What you don't realize is that it will take you 10 years, if you're lucky, > to discover the "right way" of programming in C++

IMO, only novices and beginners look for "THE right way". Advanced people realize that the "right" way depends on the broad context and look for (the) best compromise solution among a spectrum of solutions.

I believe this holds for other computing-related things (designing a LAN, database tables, etc.), as well as real life (sports, martial arts, even everyday things like sitting and walking as any person who has had a lower back problem will tell you).

The problem is again social: novices and beginners who refuse to "grow up" and who know just enough to be dangerous: they can produce working but messy code, and refuse to learn other ways of doing the same thing in an appropriate context. (E.g. when to use while vs for, or why copy-pasting large chunks of code between different functions is generally "bad".)

Somehow I'm not convinced that Haskell is the magic bullet which solves the underlying social/human issues.

> Haskell is not permissive, it won't let you — or your coworkers — write > unsafe code.

He never defines what "unsafe" is. Mutation is not unsafe per se.

> Don't be fooled: accessing atomic variables is expensive.

I've seen recent slides where the measured cost of an uncontended locked cmpxchg on Haswell was ~20 cycles vs ~5 cycles unlocked. This is NOT expensive, unless unnecessarily you replace all memory accesses with their atomic equivalents.

> Most importantly though, threads are not a good abstraction for parallel > programming

No, but they are an essential building block.

> Haskell is way ahead of the curve with respect to parallelism

First, a computation can be abstraceted into a data dependency graph.

Now, the reason that most of today's applications don't benefit a lot from the vast number of processors available is not that the underlying programming is somehow unsuited for parallelism. It is because that there IS NO parallelism available in these applications: data dependency graph is mostly serial, and if parallelism is available, it is on such a small scale that superscalar CPUs already make use of the large part of it. Also, with overly fine-grained parallelism you WILL end up in a situation where the overhead of atomic operations becomes non-negligible, even if it is only ~20 cycles.

I believe that if people more often thought about their designs in message- passing terms, the dependency graph would also emerge, and they would see that there often is very little parallelism to extract through explicit parallelization. (Note that writing to a shared variable is just an extremely simple and efficient method of sending a message).

This was also remarked on by Knuth: During the past 50 years, I've written well over a thousand programs, many of which have substantial size. I can't think of even five of those programs that would have been enhanced noticeably by parallelism or multithreading. [[http://www.informit.com/articles/article.aspx?p=1193856](http://www.informit.com/articles/article.aspx?p=1193856)]

So, IMO, easier coding for shared-memory parallelism is one of the worst reasons to switch programming languages.

That's why I personally prefer Erlang-style concurrency (actors). Communication patterns and parallelism granularity is explicit, and communication _cannot_ be decoupled from synchronization. [With shared variables, these two are decoupled.]

</comment><comment><USER43> Brilliant, just brilliant. I found myself laughing and nodding all the way.

The sad situation is we have no worthy competitor. Go?

<comment><USER44> D [0], according to the author and me. Maybe Rust at some point.

Go is not flexible enough: Required garbage collection, no type-safe generic programming (yet), opinionated concurrency model.

[0] [http://dlang.org/](http://dlang.org/)

</comment></comment><comment><USER45> I'd consider myself a 'C++ programmer' \- I've used it for years, it works very well for me for what I do with it, etc. However, what I find most frustrating is that _nothing_ is intuitive. And there is always a reason for _why_ it is like that, I know. My favorite example is the erase/remove idiom.

Anyway, here is a question about C++. Last week I tried to implement a parser for a subset of CSV - one-byte-per-character, fields separated by comma, no quoting, fixed line ending. The only requirement was speed. So I started with a simple C++-style implementation, read one line at a time with std::getline, split with boost tokenizer, copy into vector of vector of string. But it was too slow, so I reimplemented it C-style - boom, first try, 30 times faster. Through some micro-optimisations I got it 30% faster still - copying less, adding some const left and right, caching a pointer. So if anyone is so inclined, how would I make the following more C++-ish and still get the same speed? Using fopen and raw char* to iterate over the memory buffer are what I'd consider the non-C++ aspects of it, but feel free to point out other idiom violations...

        bool CsvParser::OpenCStyle(boost::filesystem::path path)
        {
          FILE* fh = NULL;
          ::fopen_s(&fh, path.string().c_str(), "rb");
          if (fh == NULL) {
            return false;
          }

          const int BUFSIZE = 1024 * 256;
          char buf[BUFSIZE];

          m_Records.reserve(m_EstimatedRecordCount);
          bool at_end_of_file = false;
          std::string carryover_field_data;

          std::vector<std::string>* current_line = NULL;
          bool at_new_line = true;

          const char separator = m_Separator;

          while (!feof(fh)) {
            size_t size_read = ::fread(buf, sizeof(char), BUFSIZE, fh);
            char* start_of_field = buf;
            size_t i = 0;
            for (i = 0 ; i < BUFSIZE && i < size_read ; i++) {
              if (at_new_line) {
                m_Records.push_back(std::vector<std::string>());
                current_line = &m_Records.back();
                at_new_line = false;
              }
              if (buf[i] == separator || (at_new_line = (buf[i] == '\n'))) {
                current_line->push_back(std::string());
                if (carryover_field_data.size() != 0) {
                  std::string field(start_of_field, &buf[i] - start_of_field);
                  m_Records.back().push_back(carryover_field_data + field);
                  carryover_field_data = "";
                } else {
                  current_line->back().assign(start_of_field, &buf[i] - start_of_field);
                }
                start_of_field = &buf[i + 1];
              }
            }
            carryover_field_data = std::string(start_of_field, &buf[i] - start_of_field);
          }

          fclose(fh);

          return true;
        }

<comment><USER34> As for your getline being slow. It is a known problem.

[http://stackoverflow.com/questions/9025093/stdcin-really- slo...](http://stackoverflow.com/questions/9025093/stdcin-really-slow)

</comment></comment><comment><USER46> Whenever I see people comparing C to assembly I automatically assume they don't know anything about (a) C or (b) any kind of assembly.

<comment><USER47> I think your 'or' might be misleading, with the (a) incidental and (b) required. I deal with a number of smart C (and even C++) programmers who view it as assembly with macros. But I've yet to meet any assembly programmers who view C as just a more succinct way to write assembly. Maybe it can be phrased as "Anyone who conflates C and assembly has probably never compared the output of their compiler with the code they think they wrote".

</comment></comment><comment><USER48> If he replaced "int * _counters;" with "vector<int> _counters;" he would have lost nothing and gained a lot of control. As for the pointer to the Snd object itself, in many cases it is sufficient to create object, not pointer, and pass the reference of the object, then in case of exception memory is always freed no matter how many ints he has push_back'ed and where the exception occurred. And if he really needs to have pointer, then he should create that pointer not in naked function that could return at any time, but make it a member of a class and delete the pointer in destructor. Then make that class as object, which will always execute its destructor, therefore always freeing the memory.

</comment><comment><USER49> The problem is not that C++ is hard, it's that Haskell doesn't solve the same kind of problems.

We would all love programming to be easier, for the compiler or interpreter to just know what we really meant, rather than what we actually typed, but sometimes the tools are sharp, are a bit more manual, exactly because they offer more control.

The constant sell of Haskell or Go as the panacea for all programming problems is like someone else telling us all to adopt socks made of rubber - a few make like that, may even blog and evangelise about it, but the rest of us find it uncomfortable and annoying.

</comment><comment><USER50> I'd rather Edward than Samuel Boxingglovehands

<comment><USER26> You would, but the person shaking Edward's hand would not.

To stretch the analogy, scissors are dangerous, but they're also very useful.

I prefer a language that lets me put away the scissors when I don't need them, so I don't cut someone's hand off. For example, Python with C bindings. The problem with C++, IMO, is that it doesn't let you put the scissors away.

<comment><USER50> Yes, much better to punch your users into submission so they don't even think of using their hands.

</comment></comment></comment><comment><USER51> Fucking backwards compatibility, let shitty code keep using shitty compilers while the rest of us move forward.

There comes a time when no one uses a feature anymore so it might as well be dropped. How many of you still have floppies on your computer?

<comment><USER14> The fact is that there's a very huge amount of legacy code which provides irreplaceable functionality. What would you do if you had a complex data crunching library in C to be integrated into your program?

Rewriting stuff from scratch is sometimes good, but usually you prefer to have some well-tested routines, and be sure they will not fuck up.

Edit: you may also argue that projects like LLVM make it possible to compile stuff in IR, and still keep the old code... but there may be situations in which choosing a different compiler is not an option.

<comment><USER8> Both CLang and GCC have "C++11 compatibility" switch, so it's a matter of a compiler parameter if they accept or not the new standard.

I would introduce a "backward compatibility" switch that has to be turned ON per source file to accept old constructs. All the new code from now own would be nice and shiny. There's an (easy) way to still keep around old code.

Would that work?

<comment><USER52> Only if you like writing all your libraries yourself.

To answer a little less flippantly, you'd need to add some sort of "unsafe" construct to the language, because most of the nice, high level abstractions have nasty low-level stuff buried in them, and because of the way C++ templates are compiled, that's all code that will be included in any program you write. In short, all "new" code is built on top of an awful lot of "old" code, and if you were going to make a huge breaking change like this, you may as well write a new language and libraries ground up (like Go or Rust).

<comment><USER8> It's not that black and white.

Scala has the same debate - there are a couple constructs only library writers use (normally). So they compile the library with "enable all". Everybody else gets a warning and they refactor the code or turn on the switch to allow.

<comment><USER52> The difference is that you can separately compile your Scala libraries from the code that calls them - if you do that in C++, you give up templates. All those #includes at the top of your C++ code are basically just dumping code into your source files, and if you're using templated code, it macro-expands with parts you're putting in from your own code. There are some separately compiled C++ libraries, but most of the standard library and Boost code you use is recompiled every time you compile your program. You could probably define a new pragma that would tell the compiler that all the code from a given file, class, or function is unsafe, but it would take source-level modifications to every library you use to properly implement the flag you suggest.

<comment><USER8> Yes, the point was "from now on", as a clean break from the past without giving up legacy code.

<comment><USER52> And my point was that, due to the way C++ is designed (specifically, not having a proper module system and having this massively powerful macro- replacement templating engine), there is no way for the compiler to distinguish between "legacy" code and "new" code.

Consider the following case study: you have a library including a template class that uses raw pointers as an iterator type. You accidentally write `iter + 9` instead of `*iter + 9` when you've included it (this will likely compile, though there should be a warning). Now, even assuming there's some language extension added to mark that library as "legacy" (maybe #include-legacy <mylibrary>), can you tell me whether the "new" code you just wrote using raw pointers counts as "legacy" or not?

I think this is basically Bartosz' point as well - that C++'s legacy design features are too baked in to make positive changes easily, or even tractably (even small changes like your --no-legacy compiler flag).

<comment><USER8> Yes, there's a way. Precompiled headers already do a pretty powerful analysis.

Thinking a bit more I realized I just reinvented the wheel: this is how Microsoft phased out the sprintf, strcpy and so on.

So you can choose between 3 compiles modes: --new-cpp --advanced-library and --allow-legacy You can turn it on with pragma before including an .h file and turn it off after, if you have to.

By default "\--new-cpp" is on, throws error on naked pointers, new, delete, pointer arithmetic and so on. Basically C++ would become a safe language, almost like a CLR-type managed code. It could even have a "const by default" variable declaration, like Scala.

The "\--advanced-library" would allow a lot more (e.g. manual memory management), and "\--allow-legacy" would be for full backward compatibility.

Does it worth it? I think it does: currently with meta programming, lambdas, named(!) closures, deterministic constructors etc. C++11 is one of the best programming languages for anybody who cares about performance.</comment></comment></comment></comment></comment></comment></comment></comment></comment>


NASA's Curiosity will land on Mars, narrated by Shatner or Wheaton - <AUTHOR> http://www.extremetech.com/extreme/133722-how-nasas-curiosity-will-land-on-mars-narrated-by-your-choice-of-shatner-or-wheaton <comment><USER2> This was submitted earlier: <http://news.ycombinator.com/item?id=4315369>

The film itself, without the narration question, has been submitted repeatedly, and yet none them have significant votes, and none of them have comments.

Bizarre.

Anyway, for your entertainment, here are some of the previous submissions.

<http://news.ycombinator.com/item?id=4147907>

<http://news.ycombinator.com/item?id=4150596>

<http://news.ycombinator.com/item?id=4152659>

<http://news.ycombinator.com/item?id=4152965>

<http://news.ycombinator.com/item?id=4154270>

<http://news.ycombinator.com/item?id=4157927>

<http://news.ycombinator.com/item?id=4161845>

<http://news.ycombinator.com/item?id=4162900>

<http://news.ycombinator.com/item?id=4163991>

<http://news.ycombinator.com/item?id=4181890>

<http://news.ycombinator.com/item?id=4215426>

<http://news.ycombinator.com/item?id=4230576>

<http://news.ycombinator.com/item?id=4261268>

<http://news.ycombinator.com/item?id=4311325>

<http://news.ycombinator.com/item?id=4311649>

<http://news.ycombinator.com/item?id=4314737>

<http://news.ycombinator.com/item?id=4316943></comment>


Bot can beat humans in multiplayer hidden-role games - <AUTHOR> https://news.mit.edu/2019/deeprole-ai-beat-humans-role-games-1120 <comment><USER2> At first one would think that these games revolve around body language, but really, they're mainly about keeping track of a complex sequence of choices made by others and tracking (and paring down) a set of possible truths based on those choices.

This is hard for humans to do, and is made interesting by the ample opportunities for intuitive leaps, but I'm not at all surprised that a program would be better at it. It's very easy in these games to incriminate yourself in ways that might go unnoticed by human players but would be incredibly obvious to an agent that's keeping a perfect record of everything that's happened.

</comment><comment><USER3> I think if I had guessed, I'd have thought this particular hidden role game was easily beaten with AI since the meaningful choices are so limited. Still, it was worth actually proving. I suspect something like one-night werewolf is unbeatable by ai since it's so heavily based on communication, and there's only one a single vote in the game, though..

<comment><USER4> ONUW harder than Avalon? Yeah I don't think so. While Avalon has ~15 team selections (for something like an average of 60 picks) plus over 100 yes/no votes, and ~20 fail/success votes... ONUW has pretty much no choices at all.

>one-night werewolf is unbeatable

You're asking the wrong question for starters. The AI does need to "beat" the game. It is being measured on whether it's better at the game than humans. And my experience is that most One Night games devolve into a 50/50 guess. An AI would be better at calculating the odds of the two proposed game states that the players can't actually differentiate. So the AI would surely trivially win more than human players.

</comment></comment><comment><USER5> Please let me know if I'm mistaken but it seems that, disappointingly, there is no measure of the quality of players, especially considering that the game referenced is a fan-made clone of the physical game. There's no ladder, MMR, ELO, ec.

So, of course someone who's played the game 100,000 or even 10 times is likely to beat someone who's only just played maybe a handful of games. That's not a bold - or arguably fair-claim to have beaten a majority of players if those players are all brand new —or a minority of those are veterans— which I suspect is likely given the nature of web based games.

<comment><USER6> > there is no measure of the quality of players

This is interesting in itself. 10 years ago it would have been very hard to write a program beating a human at a game where we don't know what makes a player better than another.

<comment><USER7> We do know what makes a player better, it's win rate. What GP is saying is there seems to be no leaderboard or ELO/MMR to really understand how good the AI actually is at the game.

Is this achievement closer to AlphaGo beating Lee Sedol, or is it more like AlphaStar beating a bunch of Bronze league players?

</comment></comment></comment><comment><USER8> I would find the opposite an interesting research direction: can we build a game that bots cannot master but humans can.

<comment><USER9> Contests judged on aesthetic merit may be the last bastion of human advantage. Boxing and figure skating are judged like this. Chess and Go aren't, but most commentators seem to find the machine's moves ugly, so perhaps there'll someday be a category of chess judged for elegance and style.

<comment><USER10> What do you mean by advantage?

</comment></comment></comment><comment><USER11> There is a huge gap between playing werewolf-type games and poker. The article seems to imply that by beating one it should be able to beat the other.

Prove it.

<comment><USER12> As the other poster has listed: the superhuman Poker AI is already built. They extend the poker-AI to play another game here.

Actually, CFR is really interesting, because it calculates an estimation to the Nash Equalibrium and plays theoretically close to optimal in randomized strategies. Its a straightforward concept from a game-theory perspective, but the "estimation to Nash Equalibrium" part is the interesting part. Since a real Nash Equalibrium is too difficult to calculate, it seems like their estimated Nash-Equalibirum is good enough in practice.

Any "game" with a Nash Equalibrium with randomized strategies should benefit from CFR. Which is most games of "bluffing" and hidden information (Poker, Avalon, Pokemon, Magic the Gathering), and even real-world negotiations, diplomacy, business transactions, etc. etc.

\</comment></comment><comment>-----

Since CFR has already proven to be superhuman at Poker, the research problem is now in extending this Nash Equalibirum estimate over to other games. IMO, Avalon / Wearewolf games are too simple, AI Researchers should move to Magic: The Gathering or other more complex games like that instead.</comment>