Melatonin: Much More Than You Wanted to Know - <AUTHOR> https://www.lesswrong.com/posts/E4cKD9iTWHaE7f3AJ/melatonin-much-more-than-you-wanted-to-know <comment><USER2> Couple anecdotal points:

\- Used to have to sleep problems - mainly just my mind racing with all the (stress of) things I had to do. The symptoms were trouble sleeping and/or waking in the middle of the night with instant thoughts of projects, task lists.

\- Melatonin didn't help me much. Maybe their effect was too subtle on me - maybe I was using the wrong dose as mentioned in the post.

\- Magnesium Glycinate pills before sleep were a massive help in falling asleep and staying asleep. The only way I can describe its effects is helping me "control my brain waves". Sounds a bit non-technical but the effect is quite subtle . The idea to take these supplements were from previous discussions on HN.

\- Recently got a newborn baby - first child. These things will do more to knock you sleep cycle out whack than anything else I've experienced. Coincidentally, falling asleep and staying asleep is easier than ever. You just end up getting woken up by a tiny crying human at seemingly random times.

<comment><USER3> I am sharing my experience because I know how awful sleep problems can be.

I'm in my 30s and eat what many consider a very healthful diet - virtually no sugar, just veggies, high quality fats and proteins, and minimal fruit. I spend 7-9 hours in bed; yet wake up feeling exhausted every. single. day. I'd love to exercise, but I'm too continuously tired to get started.

Melatonin, when taken via dissolving sublingual tablet (1-3 mg), makes me feel a bit sleepier, but doesn't often keep me asleep through the night. When swallowed via a capsule, it makes me feel like I've been hit by a bus for the entirety of the next day, even if I slept the night before.

My own research led me to magnesium glycinate, which helped to some degree (maybe I wasn't taking enough?), but didn't solve the problem. My biggest trouble is falling asleep - I can be dead tired, but as soon as I'm in bed, my mind goes nuts, and I lie awake for hours. Then, by the time my body is in nice deep sleep, it's time to get up, and the deep sleep is disrupted.

I recently had an appointment with my physician (who practices integrative medicine and is not your typical MD), and he told me to try a relatively new formulation of magnesium called Magnesium L-Threonate, commercially known as Magtein.

It is apparently the best type of magnesium for crossing the blood-brain barrier, and thus, likely the best at addressing sleep issues.

I've been on it for about a week now (taking 1000mg 2 hours before bed and 1000mg upon waking in the morning), and have slept better in the last two nights than I have for a long time. Here's to hoping it keeps working!

I also use a couple other hacks to help me sleep - at night, about an hour after the sun sets, I wear "blue blocking" glasses (the UVEX S0360X fit nicely over my prescription glasses). Sounds (and looks) goofy, but for me it creates a noticeably stronger "sleep pressure" than I'd experience without them. I also wear a mask over my eyes when sleeping, to block out any ambient light, and I just started making an effort to listen to music while waiting to fall asleep. I think all of these things help to some degree.

Also, check out the book "Why We Sleep" by Matthew Walker.

<comment><USER4> Not sure if minimal fruit counts as a healthy diet

<comment><USER5> It does, assuming you're getting enough vegetables; fruit is mostly sugar (high glycemic load which causes crashes, promotes diabetes, etc.), so not actually that good for you on the macronutrient level.

<comment><USER6> Uh not really. Most fruit is both low to medium GI and GL. Sugar in fruit is bound to fiber and bloodstream uptake is fairly slow.

There is a negative correlation between RDA fruit consumption and diabetes.

<comment><USER7> Correlation does not equal causation. People who generally eat less fruit are people who usually ignore health advice in general, and would replace fruit with stuff like sugar or carbs. Eating too much fruit gives an overload of fructose, which also triggers an insulin response.

If you eat the right meats, like liver, you get more vitamins and minerals then you would from fruit. So if you know what you are eating, it's fine to cut off fruit.

<comment><USER6> >Eating too much fruit gives an overload of fructose,

Note the operative modifier 'too much'

You can eat your recommended daily intake of fruit in one sitting with no other food and still remain below high GL levels.

Digestion is a complex process. Your model that anything containing fructose is bad is not supported by any data / analysis I am aware of, and contradicted by nearly all of it.

Mammals process most of thier fructose consumption in their small intestines. Only high doses that overload this capacity lead to harmful spillover to the liver etc.

</comment></comment></comment></comment></comment></comment></comment><comment><USER8> While melatonin helped me, the results were inconsistent.

However, 10,000IU of vitamin D3 before 10am (see e.g. [0] for discussion and analysis that do NOT support my regime) seem to consistently give me a good reliable sleep schedule.

I was definitely not as thorough as Gwern, nor comparing to placebo - but for decades I have tried tens of different sleep aids, most of them useless, some working for a couple of weeks and then not, melatonin being inconsistent - with vitamin D feeling like a jackpot.

If you care to experiment, do your own reading on dosing - it should be adjusted down if you spend any time in the sun - but it should 25-50IU/lb of body weight, which is way higher than the FDA RDA. This is not medical advice. I am not a medical professional, nor do I play one on TV. YMMV. Proceed at your own risk.

[0] [https://www.gwern.net/zeo/Vitamin-D](https://www.gwern.net/zeo/Vitamin-D)

<comment><USER9> I take 5,000 IU of Vitamin D daily and 3 mg of Melatonin about an hour or so before bed. It has all but cured a lifetime of serious sleep issues.

<comment><USER10> I take 5000 D3 at 9 in the morning. It causes me to naturally wake up at 6 a.m. or even earlier, without feeling groggy.

If I take it when traveling, jet lag is greatly diminished and overcome much more rapidly. I switch to taking it 9 a.m. of the destination's local time. If 9 a.m. occurs during the flight, I take it then.

It's like an external clock pulse!

The first time I took 5000 D3, I made the mistake of doing it in the evening. My sleep that very night was quite strange, disturbed with weird dreams. I immediately clued in to the fact that morning might be better. Basically, mimicking the onset of daylight.

D3 is beneficial for exercise; it relieves that muscle soreness and tiredness and improves mental alertness. It helps beat those winter blues and gets you out there.

</comment></comment></comment><comment><USER11> Melatonin has genuinely changed my life in regards to sleep. I'd tried everything and for exams went on Zopiclone, and then found the gold that is Melatonin. Thoroughly recommend anyone with suitable problems sleeping giving it a go.

(I was DSPD, though every so often did the whole "Non-24-Hour-Sleep Disorder" thing)

<comment><USER12> How much do you take? I was regularly taking 3mg and 1.5mg regularly for most of the past 4 years. I recently tried 0.3mg (as recommended in another recent HN discussion about melatonin, I think it was a week or 2 ago), and I had terrible results.

On 1.5mg and 3mg, I would have very unsettling and memorable dreams, as well as wake up very tired, but I would get at least 7 hours of sleep on most nights. With 0.3mg, I woke after only 3 hours of sleep, feeling very energized but then getting very, very tired by early afternoon. I would fall asleep between 10 PM and midnight, wake up three hours later, then be unable to fall back asleep before it's time to go to work.

This meant I had to use stimulants to be functional, and I entered a cycle of not being able to sleep through the night, having to use stims in the morning, having to use melatonin at night to fall asleep, waking up after 3-4 hours, repeat. I finally broke it this past week by taking a sick day and sleeping through most of it, but I still couldn't hit 7 consecutive hours.

I can't even remember the last time I got the recommended minimum of 8 hours, regardless of what I do. I am trying ashwagandha and ZMA together for the first time tonight, having just taken both about an hour ago. I also took D3 this morning which will hopefully help too.

I think I'm done with melatonin for now, since I saw recommendations to abstain for a week or 2 to reset, and then trying again at the smaller dosage. But if this works, I probably won't use it again.

<comment><USER13> D3 should be taken for small periods. Note that these supplements, do not make up for self-produced substances.

I would like to ask you if instead of using melatonin to enhance your sleep, did you try physical exercise. If your body is physically tired and you abstain from screens (iPads, iPhones, etc.) for 2h before sleeping, you should be able to get a decent amount of sleep.

Additionally, sleep quality doesn't translate in hours. You could have a 5-hours sleep, where you reach the REM phase vs a 7-hour sleep where you don't.

<comment><USER12> I don't exercise regularly, and I really should. My issue is I always feel too tired to exercise in the morning, and I feel like I have trouble falling asleep if I exercise in the evening. But I'm starting to think that exercising late isn't the problem now. I'll try what you recommend. It's really hard to abstain from screens, too. I'm definitely not doing that. I'll try doing nothing other than reading actual books ~2 hours before bed from now on.

<comment><USER14> If you don't like Cardio like me I can't recommend [https://stronglifts.com](https://stronglifts.com) enough. It's been really fun slowly building up strength and I'm squatting 105kg now. Improves my mood and sleep no end.

</comment></comment></comment></comment></comment><comment><USER15> Every single person here, if your serious about diving into the science of sleep, should read Matthew Walker's book: Why We Sleep: [https://www.amazon.com/Why-We-Sleep-Unlocking- Dreams/dp/1501...](https://www.amazon.com/Why-We-Sleep-Unlocking- Dreams/dp/1501144316)

His interview on Joe Rogan is a good summary: [https://www.youtube.com/watch?v=pwaWilO_Pig](https://www.youtube.com/watch?v=pwaWilO_Pig)

He covers everything from why we sleep (obv), naps, melatonin, etc. I've just finished it and really enjoyed it.

<comment><USER16> Joe Rogan is one of the biggest propagators of pseudoscience. It's not a good sign when a guest appears on his show. Joe usually tries to rope them into talking about his two favorite health topics: cholesterol and testosterone.

<comment><USER17> Eh, I've listened to hundreds of his episodes. Some are good for a laugh, some have interesting guests and I learn a thing or two, some I can't make it through. Not everything has to be a text book. What exactly is the problem? I find the unedited, uncensored, long form, 1 on 1, conversational style very appealing - Joe is just a chatter box to keep the guest talking.

<comment><USER16> I presented the problem clearly.

</comment></comment></comment></comment><comment><USER18> From the article:

>The consensus stresses that melatonin is a very weak hypnotic. The Buscemi meta-analysis cites this as their reason for declaring negative results despite a statistically significant effect – the supplement only made people get to sleep about ten minutes faster. "Ten minutes" sounds pretty pathetic, but we need to think of this in context. Even the strongest sleep medications, like Ambien, only show up in studies as getting you to sleep ten or twenty minutes faster; this New York Times article says that "viewed as a group, [newer sleeping pills like Ambien, Lunesta, and Sonata] reduced the average time to go to sleep 12.8 minutes compared with fake pills, and increased total sleep time 11.4 minutes." I don't know of any statistically-principled comparison between melatonin and Ambien, but the difference is hardly (pun not intended) day and night.

>Rather than say "melatonin is crap", I would argue that all sleeping pills have measurable effects that vastly underperform their subjective effects. The linked article speculates on one reason this might be: people have low awareness around the time they get to sleep, and a lot of people's perception of whether they're insomniac or not is more anxiety (or sometimes literally dream) than reality. This is possible, but I also think of this in terms of antidepressant studies, which find similarly weak objective effects despite patients (and doctors) who swear by them and say they changed their lives. If I had to guess, I would say that the studies include an awkward combination of sick and less-sick people and confuse responders and non-responders. Maybe this is special pleading. I don't know. But if you think any sleeping pill works well, melatonin doesn't necessarily work much worse than that.

The evidence says that it's a very weak hypnotic. The writer then makes a long, pseudoscientific argument against the evidence, while making a claim that their article is scientific, even though it wasn't peer reviewed. They make a cherry-picked comparison to Ambien, Lunesta and Sonata based on an article by non-scientific newspaper New York Times to bolster their claims; they ignore the ability of other, more potent hypnotics to improve time to sleep and sleep length in mental illness-caused insomnia -- on whom melatonin may be ineffective -- and in people with different causes for their sleep disorders.

I leave it as an exercise to the reader to find the other flaws in the article.

<comment><USER19> 2 other low hanging fruit that make me pause re credibility:

The article butchers the role of intracellular adenosine increases. It would be fairly easy to describe the full mechanism but instead says that Adenosine is made whilst awake and cleared while asleep which is a gross oversimplification and actually pretty scientifically inaccurate.

It further describes UpToDate as 'the gold standard research database' \- UpToDate is nothing of the sort - it is a authoritative clinical reference. Think Economist for medicine, except each article is about a condition, diagnosis or treatment and it is updated. But like all clinical references that are produced by humans, it has biases specific to the authors, their clinical practices etc

</comment></comment><comment><USER20> I regularly take long haul flights (12+ hours) and take Melatoin for Jet Lag.

I'll take twice. With the flights I take this usually works out to before sleeping on the plane (which ideally is the same/close to bed-time at the destination). And then the first night at the destination.

In combination with other tricks -- I've found it really effective.

<comment><USER14> What are the other tricks, I've always found jet lag horrendous.

<comment><USER21> I also use Melatonin for jetlag, but I usually prefer to do it just for the first and second night at the destination. On 12+ hrs flight I prefer a bland sleeping aid, as it is not directly working on the circadian rhythm (or at least that's my experience). Other useful tricks:

\- ban alcohol altogether the day of the flight an possibly one day before and one after

\- order a special vegan meal during the flight, even if you're not vegan. They'll serve you first and you'll have more time to organize your sleeping schedule on board, plus you'll stay more hydrated as the meal will usually include more veggies. \- stay hydrated constantly, I'd dare say even over hydrated

<comment><USER22> The vegan meal trick is airline specific.

On BA for instance, if you're in premium economy or higher as long as you order your meal via their portal a few days before the flight they'll serve you first before offering what's left to everyone else.

</comment></comment></comment></comment><comment><USER23> If you regularly buy Melatonin, I highly recommend Trader Joes Brand chewable Melatonin tablets.

In my area they cost $2.99 for a bottle, far below the cost of other brands, and the dosage per tablet is 0.5mg or 500mcg which for me is pretty optimal.

EDIT: corrected units.

<comment><USER24> >0.5g or 500mcg

I hope you mean 0.5 mg not 0.5g because that would be a very big dose!

<comment><USER25> I think he did mean .5mg since 500ug is .5mg. Still, I'm a bit confused. The bottles I get come in doses of 10mg, I can't imagine taking even just two or three of them in a single night! On the other hand, I'd think 1/20th of my pill (.5mg) would be way too little. After reading this relevant paraphrase from the article:

> There have been few studies on sighted young people. One finds that 1 mg > works but 0.3 mg doesn't; this study is an outlier. Another study on 25yo > found both to work equally. Another study on 22-24yo found that 0.3 mg > worked better than 1.0. UpToDate and Mayo Clinic suggests using at most > .5mg. John Hopkins' experts almost agree: they say "less is more" but > recommend 1-3 mg.

I wonder if I should actually start cutting my pills in 20ths now... The author goes on to say he personally thinks that .3mg is a good amount and anything beyond 1mg is too much.

Edit: Sorry for the edits, I read the article after I made my comment, then figured I'd share their answer since I asked the question myself.

<comment><USER26> > On the other hand, I'd think 1/20th of my pill (.5mg) would be way too > little.

That's one of the key points of the article:

> "But my local drugstore sells 10 mg pills! When I asked if they had anything > lower, they looked through their stockroom and were eventually able to find > 3 mg pills! And you're saying the correct dose is a third of a milligram?!"

> Yes. Most existing melatonin tablets are around ten to thirty times the > correct dose.

<comment><USER25> Yes, I ended up reading the article after commenting (shame on me) and edited my answer to contain their answer. Sorry!

</comment></comment></comment></comment></comment><comment><USER27> Re dosages - I recently found melatonin in liquid / dropper bottle form at one of my local drugstores, intended to be mixed into a glass of water or similar. The "dosage" is 1 mg, but that requires 4 droppers - so a single dropper is 250 µg, and it's very easy to do less than that (although not with much accuracy).

If you don't want to buy from some online nootropics store just to get a 300µg dose, check your local drugstore or vitamin store for liquid melatonin, and read the label and see how much each dropper is.

I just took a ~half-dropper with a glass of water because I'm still up. Good night!

<comment><USER28> Also if it's cheap enough, you can dump half the water after dilution!

<comment><USER27> Yes, that (or mixing a pitcher of 3mg melatonin and measuring a tenth of it each evening, or something) would also work. Anything with liquid seems way less fiddly than trying to split pills into >2 parts, I'm surprised I don't see more liquid melatonin at stores _or_ more people who know that they want a <1mg dose suggesting liquid melatonin.

<comment><USER29> > less fiddly

If the melatonin is in pressed-pill form, rather than splitting it, you can just crush it in a mortar, then mix it with more filler (look at which one they're already using on the bottle and use some of that; they're usually using the cheapest thing that works.) Then you can simply measure out powder for a dose (rather than measuring out liquid).

If you want to go the extra mile, you can add enough filler to the mixture to fill a grid of gelatin half-capsules, such that you don't have to worry about measuring doses.

</comment></comment></comment></comment><comment><USER30> Magnesium is very important. Magnesium deficient rats were shown to have decreased melatonin.

[https://www.ncbi.nlm.nih.gov/m/pubmed/17172005/](https://www.ncbi.nlm.nih.gov/m/pubmed/17172005/)

It's also protective against hypercalcemia, so if you're taking vitamin D, make sure you're getting enough magnesium.

I've even read that magnesium alone can mitigate the symptoms of vitamin D deficiency.

<comment><USER31> Magnesium is important, many people are deficient, supplementation is cheap and supplementation is very unlikely to cause harm (as long as you keep it to max 300 mg of elemental Mg (e.g. 2g of magnesium citrate) a day). Like with vitamin D, you should have very good reasons not to chose to take a magnesium supplement.

<comment><USER32> Is magnesium dissolved in water bioavailable? There are some sparkling mineral waters with Mg ions and it would be nice to be able to just sip on those

<comment><USER31> I'm not sure. I know the bioavailability of magnesium citrate is much better than that of magnesium oxide, due to the bad solubility in water of the latter (and supplements with magnesium oxide are thus next to useless). That suggests Mg ions already present should be readily absorbed.

</comment></comment></comment></comment><comment><USER33> > Yes. Most existing melatonin tablets are around ten to thirty times the > correct dose.

I couldn't find an explanation why they'd be sold at this dose from this article, which makes me suspicious of this. Am I missing something? What would be the motive for this?

<comment><USER34> Because they're sold as supplements and not as medications. Many supplement dosages are arbitrary, with few exceptions.

</comment></comment><comment><USER35> Wow! I've started with 2.5 mg and now 20 mg does nothing to me. I've been doing it sooo wrong. I hope the tolerance is going to fall now as I've stopped taking it and I will be able to use it the right way going with 0.3mg. That's such a pity you can't just get any better kind of a sleeping pill without a prescription if you don't want to mess with circadian rhythms and just want to fall asleep whenever you have time but can't. So many people actually have irregular schedules: day and night shifts mixed chaotically etc. I actually don't think I know anybody who would go to bed at the same time every night. I wish I had Ambien for occasions like that (I don't drive) but it seems impossible to get without a doctor.

In fact I've tried to do some research but failed to find any information about undesirable effects and DON'Ts of melatonin at the time when I've started taking it (some years ago). It seemed a wonder drug everybody should be taking all the time - it just makes you sleep well whenever you choose to, protects from oxidative stress, boosts your immunity etc. But now I know: tolerance (including tolerance to endogenic melatonin which means screwing your natural circadian system) is what you pay (I could find not a single mention of melatonin tolerance until today).

</comment><comment><USER36> I used to suffer terrible sleep until recently. Always exhausted in the morning. Sore all over. Missed meetings, or called in sick some days. Would wake up around 11 if I could

Now I can wake up around 630 am, lift weights, do HIIT, and be early to work

Melatonin wakes me up in the middle of the night. I take Unisom (Doxylamine) as well. Works pretty well in combination

I have blackout curtains but I need some light to wake me up in the am, so I leave them open about six inches on one side

I eat a small organic meal for dinner, early as I can, usually by 630

<comment><USER37> Just an anecdotal warning. Unisom is not recommended for long term use. I didn't know this and used it for a year straight to combat stress induced insomnia during my first startup. It took me a few years before I returned to feeling "normal". YMMV.

<comment><USER38> Another data point: I've been using it on and off for a year now and it's been a life saver. I can reliably get to sleep when I need to for the first time in my life

As best I can tell it's not recommended for long term use because it hasn't been studied for that purpose and because there are prescription sleep aids that don't cause as much drowsiness

I'm terrified of taking a prescription sleep aid because of all the sleepwalking horror stories.

I take only 5 mg so the drowsiness isn't that big of a problem for me especially if I exercise in the morning. I'll take drowsy and rested over alert and unrested any day.

<comment><USER39> The first generation antihistamines are strongly anticholinergic, so long term use might have cognative effects and may increase the chance of dementia later in life. They can also interact with a lot of other medication since they are much less specific than most drugs. I agree that they are still quite a bit better than GABA-A agonists. IMO, any sleep medication is best taken with breaks as frequently as possible, which can both increase effectiveness when you take it and reduce side effects of long term use.

<comment><USER38> Wow, that is good to know. Thank you.

</comment></comment></comment></comment></comment><comment><USER40> Are there statistics somewhere on how many folks use an alarm clock? Every time I think I have a sleeping problem, I'm always harshly reminded of how different my sleeping habits are by virtue of the fact that I have never used an alarm clock. Something that it seems near universal among everyone else. (Though, I suspect it is just something everyone talks about. Hypothesis being that I'm in the majority, but there is just nothing to say about not using one.)

<comment><USER41> If I didn't use an alarm clock I would be unemployed.

<comment><USER42> I've trained myself (and reworked my daily schedule) to stop using alarm clocks. Incidentally, next week will be 4 years since the last time I used one. And melatonin has been one of my main tools.

Getting up by yourself instead of being jolted out of sleep is invaluable, especially if you do rest all the time you need.

<comment><USER40> Similarly, I haven't used one for more than a few months at a time for my entire life. Pushing forty at this point. I'll confess the winter months up here in Seattle can be tough. Sun isn't up til about 8ish, so it can be hard to realize what time it is.

In the summer, though, sun is up at 4:30. I don't know how folks sleep too late. Even when exhausted, sleeping past 7 is near impossible.

</comment></comment></comment></comment><comment><USER43> I never took it because I read a long time ago that it causes your body to decrease melatonin production long term. I guess that's just a myth because people in this thread seem very positive about using it long term.

<comment><USER44> People in this thread didn't RTFA (top posts are addressing the title/subject of 'melatonin'), and generally the responses are anecdotal. Don't assume folks here know what they are talking about.

</comment></comment><comment><USER45> Melatonin is usually not (freely) sold in Europe while it can be easily bought in the US like vitamin pills or cod liver oil.

Is there a recommendable online option with international delivery?

(I don't consider the usual 'online pharmacies' recommendable. Even when buying Melatonin in a store in the US, there's still the issue that Melatonin manufacturers and sellers mostly control themselves …)

<comment><USER46> Huh. Melatonin is readily available in pharmacies and shops here in Finland.

<comment><USER47> I don't know why the parent said "Europe", unless they did a survey of all the laws. Drugs are mostly regulated at the country level.

<comment><USER45> You are right, my use of "Europe" was too broad.

</comment></comment></comment></comment><comment><USER48> Melatonin has been a lifesaver for me after having kids and for a few other new parents I know that I've recommended it to. Somehow it allows you to get much more rest out of interrupted sleep.

</comment><comment><USER49> Melatonin has also shown to help with certain cancers especially breast. Ref: [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5412427/](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5412427/)

<comment><USER50> No mention of the antioxidant properties of melatonin or its metabolites. [https://www.ingentaconnect.com/content/ben/ctmc/2002/0000000...](https://www.ingentaconnect.com/content/ben/ctmc/2002/00000002/00000002/art00006) [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3614697/](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3614697/) [https://www.fasebj.org/doi/abs/10.1096/fj.01-0309fje](https://www.fasebj.org/doi/abs/10.1096/fj.01-0309fje)

Or the fact it also appears to have an effect on mesenchymal stem cells. [https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1600-079X....](https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1600-079X.2006.00318.x) [https://stemcellsjournals.onlinelibrary.wiley.com/doi/abs/10...](https://stemcellsjournals.onlinelibrary.wiley.com/doi/abs/10.1634/stemcells.2007-1000) [https://stemcellsjournals.onlinelibrary.wiley.com/doi/abs/10...](https://stemcellsjournals.onlinelibrary.wiley.com/doi/abs/10.1634/stemcells.2007-0197)

Perhaps this is why its called Beauty Sleep?

I also wonder what effect on the sleep pattern these above affects have in the big picture of sleep?

Best sleep I have had in adulthood was water only fasting for 18days recently. The body seems to know what to do to repair itself, perhaps because ever cell has a copy of our DNA in it. There seems to be some knowledge in this DNA that makes cells know what to be and how to perform its individual cellular role for the bigger picture of being part of a body, a bit like individual humans playing their part in a society.

</comment></comment><comment><USER51> Just a quick warning for those considering Melatonin before a flight or for adjusting to jet lag:

About a week before a long flight I decided to test Melatonin and took a single 3mg tablet (smallest dosage I could find at my local pharmacy) before I went to bed. My sleep quality seemed unchanged but right after breakfast the next day I had gastro issues.

I tried a 3 mg tablet again a few days later and had the same symptoms.

I gave up on Melatonin deciding it was better to be wide awake over the Pacific than stuck in a tiny airplane bathroom :)

YMMV but other folks online have had similar side effects. It seems a small % of people have gastro issues but if you're considering Melatonin I suggest a small dosage first (maybe 0.3mg as recommended by the article) and a test _before_ travelling!

</comment><comment><USER52> I see lots of posts bashing melatonin.

I take 0.5mg/night one hour before bed and it helps calm my mind and get right to sleep. It also helps me with my reflux!

</comment><comment><USER53> Melatonin is also an antioxidant. Does anyone know its effects on physical health?

<comment><USER18> [https://examine.com/supplements/melatonin/](https://examine.com/supplements/melatonin/)

See section 9.

</comment></comment><comment><USER54> I'm reading HN because I have insomnia after upping my Melatonin dose from 2.5mg to 5mg at the recommendation of my psychiatrist. I've never had the early morning jolt of energy until the last couple of days. Maybe I'll drop my dosage down to 1.75mg tomorrow. That's about the lowest I can get with these 10mg pills.

<comment><USER55> 1.75 mg is still almost an order of magnitude higher than the recommended dose of 300 _micrograms_. Throw your pills away and get these instead: [https://www.amazon.com/Sundown-Naturals- Melatonin-300-Tablet...](https://www.amazon.com/Sundown-Naturals- Melatonin-300-Tablets/dp/B000GG2I9O/ref=sr_1_2_sspa?ie=UTF8&qid=1532837902&sr=8-2-spons&keywords=melatonin+300+mcg&psc=1)

<comment><USER56> If I take 300 micrograms I feel groggy the next day. I do half and that's just right. It's crazy people are doing 3-10mg.

<comment><USER50> Ideally a bedroom needs to be so dark that if you hold you hand up inches away from in front of your nose, you cant see your hand in any way. You may also want to consider good ventilation in the room, if CO2 levels get up to around 700ppm which can happen in a few hours of going to bed, you will also wake up feeling less refreshed and groggy. Its why they have CO2 scrubbers in submarines and why people feel more refreshed when camping under canvas. Sleeping at the back of a large cave doesnt seem so bad now.

<comment><USER57> > if CO2 levels get up to around 700ppm which can happen in a few hours of > going to bed, you will also wake up feeling less refreshed and groggy

source?

</comment></comment></comment></comment></comment><comment><USER58> As someone who works from home 90% of the time and sleeps/works in a room with a huge skylight, I've never had better sleep, energy, and overall "consistency" with my body. The most notable issues being that I actually feel sleepy when it's time to sleep, and I can fall asleep within minutes. I've never really experienced that before.

I used to work nightshifts with mostly light-blocking shades, and the only natural sunlight was the light that came in from the small gap above the room partition (I lived in a flex room/living room). That set-up was the worst.

I've had various life variables and combinations of them, but aside from the night-shift one, and obvious ones like constant sleep deprivation, it does seem like sunlight is playing the next-most significant role in helping to regulate my body and sleep.

<comment><USER7> That's ok if you're living close to the equator with a regular day/night schedule. But if living more towards the poles then you get extremes in winter and summer of how much light/darkness there is.

</comment></comment><comment><USER59> I always dream much when taking Melatonin, which makes the sleep less refreshing.

<comment><USER60> I thought that indicated REM sleep which is supposed to be the best type. (I heard that alcohol and pot do the opposite,so you have less refreshing sleep).

</comment></comment><comment><USER61> I have a very different sleep aid. A sleep headphone (a headband with speakers woven into that also serves as an eye-mask) combined with white noise (quality rain sound) served by an iPod. The white noise blocks outside sounds much better than earplugs, and the rain soothes me into sleep (always loved it when it rains outside and I'm in bed).

It has become a crutch for me, sometimes I do worry if I have become too dependent on that arrangement, but it works well. In summer the headband can get hot though.

<comment><USER62> Link to the headband product ?

<comment><USER61> There are a lot of crappy ones or overpriced, it takes some trying out to find a good fit. The ones I currently use are those: [https://www.amazon.co.uk/Sleep-Headphones-Adjustable- Comfort...](https://www.amazon.co.uk/Sleep-Headphones-Adjustable-Comfortable- Relaxation/dp/B00XZCYQQ4/). Had also good experience with the provider, they eagerly replace broken headphones.

</comment></comment></comment><comment><USER63> I will always sing the praises of Trazodone for dealing with sleep issues. It worked extremely well for me and my parents. It's normally used at very large doses as a last line for clinical depression. However at smaller doses it's an extremely effective sleep aid for some people. It also doesn't make you to sleepy like other drugs. It just makes getting to sleep easy.

</comment><comment><USER64> The but about th optimal dose being 0.3mg is interesting. I've been nibbling the corners of 3mg pills for years now, since the full strength always left me with a weird sleep hangover, or I would end up bolt awake but still sleepy at 4am..

</comment><comment><USER65> I've been practicing mindfulness meditation for a few weeks. I'm in week four now, and I'm getting good results. [https://palousemindfulness.com](https://palousemindfulness.com)

</comment><comment><USER66> What a great article. Explains why melatonin works for my wife for a short time but then stops working (dosage in store-bought pills is too high and stays in the system too long).

</comment><comment><USER67> I occasionally use Melatonin to help me sleep on planes or adjust to new timezone, but I don't think it's a good idea to take it regularly.

<comment><USER68> I'm curious since this is currently apparently the highest-upvoted comment -- does OP (or any upvoters) have any (preferably reference-backed) reasoning for this?

Otherwise it's just an unsubstantiated knee-jerk reaction at the top of the discussion.

I take melatonin once a week or so but haven't noticed any detrimental effects, so I do have a stick in the game and would like to know about potential issues if anything is out there.

<comment><USER67> I don't have any studies to back it up, but I know someone who used to take it every day and she said it's harder for her to fall asleep without it than it used to before she started taking it. Naturally our body adjusts to anything that we ingest.

</comment></comment></comment><comment><USER69> Anyone knows why Melatonin is available so easily in the US, but you need a prescription for it in Europe? (I haven't asked my GP though)

<comment><USER70> No need for a prescription in France.

<comment><USER42> Nor in Spain. I've been taking melatonin for quite some time, and so has my mother. You just go to a pharmacy and buy it over the counter.

<comment><USER71> A friend of mine was on rotation in Sweden from the US and went into the pharmacy to ask for some melatonin to help with her jet-lag. She was very sternly told that she needs a prescription for that here.

</comment></comment></comment></comment><comment><USER72> anyone here tried breathing exercises to help with better sleep? i am noticing that at times when i am taking deep and slow breaths before sleeping, i have a dramatically higher quality sleep.

<comment><USER73> I don't know why but whenever I did the technique where I tense and relax my muscles I got nightmares.

</comment></comment><comment><USER74> Some related posts by the same author, some about drugs (SSRIs and Adderall), some about other topics: [https://slatestarcodex.com/tag/much-more-than-you- wanted-to-...](https://slatestarcodex.com/tag/much-more-than-you-wanted-to- know/)

</comment><comment><USER75> It's always unclear whether you're reading crackpot or not especially around the nootropics crowd.

In this case the author seems to be a psychiatrist so he should be trustworthy: [http://slatestarcodex.com/about/](http://slatestarcodex.com/about/)

</comment><comment><USER76> A good multivitamin stack (for example, AOR Ortho-Core + Life Extension D & K in the morning and 4 Doctor's Best High Absorption Magnesium pills at night 5 days/week) is probably better than raw melatonin.

</comment><comment><USER77> I have cut out sugar and caffeine for dietary reasons and my sleep schedule did not improve at all. I tried those red shift apps and they did not change my sleep schedule. The last few weeks I was not working on my computer late at night and got tired at a reasonable time. Now that I am back working on my side project, having interesting problems to solve (one more feature before bed!) and the bright screen, I am starting to stay up late again.

I notice when I do everything right I don't have a problem waking up before 8 hours. Normally I shoot for 8:30 and have trouble going to sleep and getting up. Also when I am in a good sleep schedule I sometimes wake up in the middle of the night, use the restroom, meditate if I'm awake enough, then go back to sleep.

I am sad to say that with most of the other factors controlled, bright screens are the likely cause of my sleep issues. This is hard for me because screen is life.

<comment><USER78> I'm not sure I understand, but I want to: Do you become engaged in a project and fall asleep later because it's hard to drop the project, or do you become engaged in a project and use a bright screen and the screen causes you (through some screen-body interface mechanism) to fall asleep later?

<comment><USER77> It is unknown to me, honestly. Most of the time I am simply not tired, which I blame the screen for. When I do get tired I usually push it even later if I'm working on something good.

</comment></comment></comment><comment><USER79> What time should you take melatonin if you don't have any major sleep problems but want to improve sleep quality?

<comment><USER80> Roughly 30 minutes before I hit the pillow works for me. I use the normal melatonin (non-chews), but I suck on them till they dissolve in my mouth, because I hate when they get stuck in my epiglottis; you get used to the bitter flavor after a bit. I'm going to assume this is safe because chewables exist.

<comment><USER81> Why not just take it with a small amount of water?

<comment><USER80> Water isn't a magic lubricant. Pills still get stuck in my epiglottis with water. Usually when I take pills, I do it followed by a piece of bread and then water, but prior to bed I don't want to eat anything after brushing my teeth and the pill dissolves nicely, and like I said, I assume it's safe, because chewables exist (obviously other drugs don't work in a similar manner).

<comment><USER81> Ah. Have you tried butter, which _would_ be a lubricant? And it would probably be relatively safe after brushing because of the lack of sugars.

<comment><USER80> Butter is delicious, but sadly it too lacks any fel or fey essence necessary for magicks.

</comment></comment></comment></comment></comment></comment><comment><USER82> When I was working long hours at an startup. My sleep cycle got disturbed.

Here is what works for me:

1\. Reduce room temperature to 25*C. Go to bed at 10:30pm

2\. Automatically shutdown the airconditioner at 4:30am.

3\. Jump out of bed at 5am without any alarm clock.

This habit continues in the month when no airconditioner is needed.

<comment><USER81> _Reduce_ the temperature to 25C? What do you normally keep it at?

</comment></comment><comment><USER83> Dupe from three weeks ago:

[https://news.ycombinator.com/item?id=17505380](https://news.ycombinator.com/item?id=17505380)

<comment><USER24> Looks like the author posted it on his personal blog, but also on the group blog LessWrong, so the link avoided the filter.

<comment><USER84> The filter doesn't work several weeks later (or even days later AFAIK).

Also, the earlier submission didn't get a lot of comments (7) or votes, so a second run is probably OK by the guidelines.

</comment></comment></comment><comment><USER85> Melatonin doses of the standard distribution seem great for crazy fucking dreams, but little else.

Drinking two Rolling Rocks or PBR distilleries is more effective;

<comment><USER86> I did this for a decade. If you drink or smoke pot to sleep you will slowly go mad. They suppress deep sleep.

<comment><USER87> This is true for alcohol but I'm not sure about cannabis.

In California, a heavy indica is a recommended by doctors for sleep. My understanding is that it only affects R.E.M. sleeep.

Anecdotally, I track my sleep and when I smoked a heavy indica before bed I would consistently get at high 80 to 90% sleep quality. I'm on a couple of month tolerance break and have a hard time breaking 80% sleep quality.

<comment><USER39> I think you mean sleep efficiency here not sleep quality? Sleep quality isn't possible to measure precisely without EEG and usually both deep sleep and REM sleep are tracked (and both together are usually less than half of sleep).

I recently came accross Babson et al. 2017 Cannabis, Cannabinoids, and Sleep: a Review of the Literature:

[http://www.med.upenn.edu/cbti/assets/user- content/documents/...](http://www.med.upenn.edu/cbti/assets/user- content/documents/s11920-017-0775-9.pdf)

There hasn't been that much research (and most is on synthetic cb1 and cb2 agonists, not cannabis, and is short term). cb1 and cb2 receptors have different effects, and the dose (especially CBD) and length of use may both make a large difference. IIRC (and maybe not from this particular review) there is evidence that the same receptors may have opposite effects in different parts of the brain. cb1 receptors have a major role in circadian rhythm.

Some studies have shown increased slow wave sleep at least at first, but long term use and withdrawal may have the same issues as GABA-A agonists. Your current issues may be withdrawal effects or due to it helping or both.

Interestingly, the common anesthetic propofol inhibits an enzyme (FAAH) that breaks down the endocannabinoid anandamide. It might work well to combine endocannabinoid enhancers with other sleep aids (maybe melatonin), however research on those seems aimed at pain relief and hasn't worked out so there don't seem to be any good ones generally available. Pfizer did a Stage 1 sleep trial of the FAAH1 inhibitor PF-04457845 (by itself), but only to make sure it was passing the blood brain barrier. They didn't publish the results but it sounds like they found at least slightly reduced REM sleep (I'm not sure if there was increased deep sleep).

Some people have tried oleamide for sleep and it is a cb1 receptor agonist (among many other things including some kind of GABA effect). It sounds like it naturally accumulates during sleep deprevation. Looking online I have mostly found people reporting no effect, although I did see one person with primary insomnia who found it very helpful when cannabis wasn't. One person reported feeling tired and dizy all the time after a few weeks of use (resolving when they stopped) and the person who found it helpful said it felt like it wasn't a good thing to take every day. It is worth noting that it may have a fairly significant and direct dopamine system effect (vs indirect effect of cannabis) and that is one of the most fragile parts of the brain.</comment></comment></comment></comment>


Show HN: My first Rails app Bar Roulette, bar hopping with help from Uber and Yelp - <AUTHOR> https://bar-roulette.herokuapp.com

<comment><AUTHOR> Hey HN - This is the first app I've built, it was coded with Ruby on Rails. I built it as a way to explore Uber's new ride request API. I haven't seen anything using their API where you don't know where you are going until after the Uber ride finishes. It got a little bit of press last week, but I really value the HN community and I would love to get your honest feedback. Is this something you'd use? Concerns you have that would keep you from using it? Do you have suggestions on how to improve the homepage?

</comment><comment><USER2> Great app! Have had a lot of fun trying it out. Especially like the spontaneous nature of it, certainly spices up the evening trying new places. Hook in with Tinder or Grindr to also grab a date?

</comment><comment><USER3> Thats an awesome idea. Available in every city where Uber operates? If so, I might use it myself soon.

<comment><AUTHOR> Thanks, yes it's available any city that has uber and yelp. The car hierarchy that it looks for availability is uberX > uberPOP > uberBLACK.</comment></comment>


Ask HN: Anyone have OCD? - <AUTHOR>

I thought I would throw this out there for the community after watching an episode of "Obsessed".
If so, care to share your habit? Or care to share any habits you find yourself continuously doing?
I don't consider myself to have OCD, but one habit I always find myself doing is when changing the radio volume in the car I usually always have to set it to an even number (10, 14, 18, etc..). <comment><USER2> I have Tourette's, which is often comorbid with OCD. I guess the closest thing I have to an obsession is an irrational sense of dread when I leave the house wondering if I locked the front door. Really deep all-consuming dread. I've been told this is a classic bit of OCD. Also, if I'm in the right mindset and I brush my hand against something I'll need to go back and brush against it the other way to "even things up".

</comment><comment><USER3> I have to set the number on the tv, thermostat, radio etc to an even number. It started as a joke, but has taken on a life of its own.

<comment><USER4> So if you have Dish Network, and the HD version is right above the SD version on the channel guide, you'll watch the SD version if the number is even?

<comment><USER3> Doesnt extend to channels because that wasn't part of the original joke which resulted in the issue. Basically in the course of the joke ( which was only good if you really followed it ), it became something that actually bothered me - ie volume on 63 instead of 62 or 64 etc.</comment></comment></comment>


Why you should, actually, rewrite some of it in Rust - <AUTHOR> https://unhandledexpression.com/2017/07/10/why-you-should-actually-rewrite-it-in-rust/ <comment><USER2> The author focuses on rewriting low-level media decoders in Rust. I have bit of experience in this area. I've been slowly working on an MPEG2 binary subtitle decoder in Rust: [https://github.com/emk/subtitles- rs](https://github.com/emk/subtitles-rs)

A while back, I ran my subtitle decoder through "cargo fuzz", and I was pleasantly surprised at the results: Close to half a billion fuzz runs found 5 runtime panics, all of which were detected by Rust before they could compromise security. If I'd written this code in C, several of those errors would have been exploitable. I like to think I'm a lot more paranoid than the average programmer. But the MPEG2 format is gnarly and, sooner or later, I'll miss a potential overflow when bit shifting, or get confused following internal "pointers" in a subtitle packet.

Rust has a few advantages for this work:

1\. Rust does not require a garbage collector or other specialized runtime. This makes it _far_ easier to pretend to be boring C code. This is a significant advantage over some other excellent languages like Haskell, etc., which require non-trivial runtimes.

2\. Rust is very fast by default. For low-level programming, this matters.

3\. The Rust infrastructure for testing and fuzzing is surprisingly good and easy to use, which makes it easier to produce bullet-proof libraries.

The downside is that even if you're already familiar with C++, it's probably going to take a couple of weeks to become comfortable with Rust. And if you don't really understand stacks, heaps, memory layout and references, it may take even longer.

I do agree with the underlying thesis: In 15 years, I'll be heartbroken if we're still facing an endless stream of security updates and remote root compromises. But it's going to require literally billions of dollars of programmer time to put a dent in this problem.

<comment> yjftsjthsd-h > Close to half a billion fuzz runs found 5 runtime panics, all of which were > detected by Rust before they could compromise security. If I'd written this > code in C, several of those errors would have been exploitable.

Wouldn't the apples-apples comparison be fuzzing a C program? If AFL would catch the same bugs, Rust isn't better than C in this case.

<comment><USER2> > If AFL would catch the same bugs, Rust isn't better than C in this case.

You can find a list of my vobsub bugs in the Rust Fuzz Trophy Case: [https://github.com/rust-fuzz/trophy-case](https://github.com/rust- fuzz/trophy-case) They are:

1\. The shift overflow: This was harmless in both C and Rust, I believe.

2\. The arithmetic overflow: This was a runtime panic in Rust, resulting in a clean crash. In C, this might have been exploitable with a complex enough attack.

3\. The three "invalid slice" errors. All of these were clean runtime panics in Rust, and I'm pretty sure that at least two of them would have been exploitable in C with enough work.

So Rust has a couple of advantages here. Out of 5 errors found by the fuzzer, the worst thing that could happen in Rust would have been crashing the program in a controlled fashion. In C, we would have been looking at memory corruption and quite possibly escalation.

Secondly, Rust's runtime checks actually make fuzzers work better. Even simple checks like "is the end index of this slice great >= to the beginning index?" tend to catch problems almost as soon as they occur.

<comment><USER3> You would get 2. and 3. as runtime panic in C if you used sanitizers.

<comment><USER4> You would also get additional attack surface if you used sanitizers, because they were designed as debugging tools, not for production deployment.

[http://seclists.org/oss-sec/2016/q1/363](http://seclists.org/oss- sec/2016/q1/363)

</comment></comment></comment></comment></comment><comment><USER5> Sigh. This again.

Not all security vulnerabilities are due to pointer arithmetic or out of bounds execution or pick-your-rust-is-better-idiom.

Heartbleed is a great example. It wasn't caused by an error with how C handles memory or strings or anything else. It was caused by failing to validate untrusted input. Rust isn't going to help you with that.

Could the affected parts be re-written in a way where the boundary checks would have worked? Yes. As they could have in C, C++, D, Fortran, or any number of other languages.

If memory safety and correctness was so truly valued above everything else, we'd be seeing a lot more Ada than we do today.

And this doesn't even cover the fact that not everything _can_ be re-written in Rust, mainly due to compilation target restrictions.

Exasperated Edit: No, I'm not saying code should never be re-written. I'm not even saying that Rust is a bad tool if the decision to re-write is made. What I am saying is that Rust is not a silver bullet. Rust is not going to solve every problem ever. Rust is one of many choices for writing memory safe, C ABI compatible code.

The reasons provided by this article are insufficient to solely justify a re- write in Rust; the exact same arguments could be used as justification for rewriting everything in Ada. Or Haskell. Perhaps some thought will be put in the next "re-write everything in Rust" article that takes that into account.

Then again, none of the past articles have.

<comment><USER6> Sigh. This again.

The Rust language is more than just memory safety. Memory safety is certainly the most prominent and unique feature of Rust, but the language also includes a lot of features that make writing good, bug-free code easier.

For example:

`Result`, when returned, forces all callees to check for errors. It's all too easy to throw away error codes in C/C++. This is probably one of the most important features in Rust, besides memory safety.

To easily consume an `Enum`, you have to use `match`, which forces you to handle all members of the enum. In C/C++ it's easy to build a switch for an enum, and then later when a new member is added to the enum and you forget to update all your switches.

Support for multiple return values (through tuples) means being able to avoid the nightmare of output pointer arguments to functions.

No NULL pointers.

Unit testing built into the canonical tooling.

Documentation testing built into the canonical tooling.

The `Option` type, which lets you return "nothing". In C/C++ you'd have to return a bool, and again use a nightmarish output pointer argument.

`OsRng` in the rand crate (go ahead, try to write a function that safely reads urandom in C).

No undefined behavior.

The list goes on. The flavor of it, is that Rust makes it easier to write defensive code. Defensive code is code that is hard to use wrong. For example, for a backup solution I built using Rust, I made all the cryptographic types their own unique, opaque types. EncryptionKey, HmacKey, Salt, etc. For someone new to the codebase, these types make it obvious what each function is asking for, and make it really difficult to use the functions or the types the wrong way. And they are super easy to build and use in Rust, see my code: [https://github.com/fpgaminer/preserve/blob/master/src/keysto...](https://github.com/fpgaminer/preserve/blob/master/src/keystore.rs#L20)

C++ would require a whole set of classes, and require instantiating a new class every time I want to add a new cryptographic type. Rust only requires 3 lines per type.

TL;DR: The real magic is that it's easier to do the right thing in Rust.

<comment><USER7> I mainly agree that Rust is more than about safety. I just wish these other features had a tenth of the vocal support as Safety.

It's even worse here on HN, where the a certain group seem to thrive on blasting not-Rust, especially if that not-Rust is C or C++. I've seen comments to the effect that anyone writing in C or C++ today is literally acting with reckless indifference to life and safety. It's terrible.

<comment><USER6> Criticism is just so much easier than constructive arguments. That's why it's rampant in communities, even HN. And controversial subjects (Bitcoin, health, food, Javascript) will magnify the problem.

It's easy to find fault in C/C++. It's easy to parrot the Rust marketing. It's not so easy to actually have spent the time to learn and use Rust, let alone articulate the subtle ways that its design, taken as a whole, is better than alternatives.

Building those constructive arguments is _hard_. I remember reading an article about error handling. It had to have been at least 10 pages worth of content, covering the history of error handling throughout all the old and modern languages, and using examples for where each fails or succeeds. It culminates, more or less, in explaining exactly why the error handling of languages like Rust outperforms in the field of systems programming.

(NOTE: The author of that article was actually arguing for the error system used in the language they developed for their OS, IIRC. But Rust was pretty darn close to the ideal the author was going for, and they pointed out as much.)

My point is that it took 10+ pages to make a solid argument for _just_ error handling. Not many people have the experience, wisdom, time, and willingness to write even a fraction of such insightful content in a comment on HN.

That said, well written, balanced comments still generally float to the top in even controversial HN threads.

EDIT: I would also like to point out something specifically in response to "I've seen comments to the effect that anyone writing in C or C++ today is literally acting with reckless indifference to life and safety."

There is a tremendous amount of pent up anger in the programming community against C/C++. The language should have been put our to pasture a _long_ time ago. Rust is the first language which has a real chance to displace it. So it's no wonder that a lot of us are willing to just burn C/C++ to the ground and jump ship.

Not to mention that as programmers we may be quickly approaching a time when security bugs become a governmental issue, and the _last_ thing we want is the government mandating how we write code. So it is in everyone's interest if we self regulate. Again, that would explain why everyone is kinda jumpy about C and security bugs.

<comment><USER8> The interesting bit is that it was already happening on the PC world, with C only being used for OS APIs on Windows and OS/2, but most people were actually using C++ (OWL, VCL, MFC), Turbo Pascal for Windows followed by Delphi, VB, Eiffel, Ada, Oberon, Component Pascal...

Then the UNIX FOSS, written mostly in C took over, and set us almost 20 years back in security and safety.

</comment></comment></comment></comment></comment><comment><USER9> +1 to everything said here.

It really is very straightforward to start inserting Rust into a C/C++ codebase. I did the Rust port of netcode.io[1] which started out by just calling C code for the portions that I didn't have working in Rust. Eventually the port was 100% Rust but I was really impressed with how seamless mixing C/Rust was.

Even now our unit tests run against the C code at a functional level so we know when the protocol diverges which lets us easily catch breaking changes from the reference C implementation.

Much like everything, don't apply an adage blindly and do a proper evaluation but I think if you're in the a space where memory or performance matters Rust is a very strong contender that plays well with existing ecosystems.

[1] - [https://github.com/networkprotocol/netcode.io](https://github.com/networkprotocol/netcode.io)

</comment><comment><USER10> As someone who really likes C and C++ I feel like the biggest reason for me not even thinking of Rust as a viable language right now is the community attitude. It seems so damn hostile to C and C++. Anyone who thinks C and C++ is viable is a misguided idiot, bad programmer, writing unsafe software, etc. to these people.

Some badass below even just said that "writing C++ code longer than a few lines without UB is humanly impossible". Apparently all these FUBAR C/C++ systems (Linux and Windows kernels, all? web browsers, LLVM that the dear rust uses, device drivers, web servers, router software, VMs of Lua, Python, C#, Java, ..., etc.) work well enough to transfer that kind of garbage to me.

It's a bit like the decades old vim vs. emacs, C vs. C++, C++ vs. C# vs. Java, etc. feuds.

<comment><USER11> Show me the programming language community that's a fan of the language it's intending to supplant and we'll talk. :)

<comment><USER12> I've never seen Python or Lua community do that so far. But Python is its own animal (which IMO is only highlighting how good it is), it's not supplanting anything. Rust meanwhile both hates C and piggybacks on it (using LLVM, similar syntax, cited compatibility and coexistence with C). Lua is similar, no hate, its own animal, custom syntax, good in its niche (Python's niche seems to be literally everything not super performance critical BTW). Same for Erlang and Elixir, custom, different languages that are masters of their niche (and go see people gushing over these two on HN, they don't shit on other languages but say how good these are, no "Pfsshh, it's 2017, only idiot would write a reliable service in C, you can't program C ever, it's broken").

<comment><USER13> _I 've never seen Python or Lua community do that so far._

Back then, wasn't it readable Python versus unreadable Perl?

<comment><USER11> You have a point. Python was definitely pitched as a perl replacement. We forget because it pretty much won.

Lua has it's own problems, of course, but I don't see it as a language developed as a consequence of frustrations with another.

<comment><USER14> Lua was developed for legal reasons: huge tariffs on foreign software meant that Brazilian companies often found it cheaper to develop custom toolchains, which is what gave us Lua.

</comment></comment></comment></comment></comment></comment><comment><USER15> I've been programming in C for 17 years. Now I'm writing (and rewriting) image processing and encoders in Rust and I love it.

It's not just memory safety. Rust has sweet error handling — the syntax is almost as noise-free as exceptions, but code flow is as predictable as error codes. In Rust I handle rare error cases that I wouldn't have bothered with in C (and thus my Rust programs fail in orderly fashion instead of running with garbage values).

Runtime arithmetic overflow checks have saved me many times. Knowing I have this safety net I can be cavalier about using smaller integer types.

I don't have to free memory explicitly, and yet peak mem usage is as minimal as it can be, and I did not have a leak yet.

And the whole ecosystem is fantastic compared to C. There's a culture of having unit tests. Ease of using dependencies via Cargo, and the zero-cost abstractions, help having dependencies broken down into small and focused libraries.

<comment><USER16> > the syntax is almost as noise-free as exceptions

No.

 _const USAGE: &'static str = "usage string";_

I _did_ rewrite it in Rust. I rewrote a small low level command line app in Rust. I really wanted to like Rust going in but I freaking hated it going out. They had a few good ideas but they never knew how to say no. The part I hated the most was the Rust macro language. And for real low level to the metal systems programming, everything is unsafe; so you may as well be writing in C.

Go is pretty minimal. They knew how to say no. I like modern C (C99 and C11). It has most of the good ideas from C++.

<comment><USER17> As of the most recent release, that's now

        const USAGE: &str = "usage string";

and there's talk of maybe making it

        const USAGE = "usage string";

> The part I hated the most was the Rust macro language.

We don't like it either; there's a replacement coming. We reserved the "macro" keyword before 1.0 and made the current one use the less-good "macro_rules" to help ease the eventual transition.

<comment><USER18> > We don't like it either

But.. but.. Scheme macros are so nice!

<comment><USER17> Totally! It's not about the fundamentals, it's about things like "macros are global" and "almost entirely hygienic but sometimes not", stuff like that. Stuff that would be backwards incompatible to just fix.

</comment></comment></comment></comment></comment><comment><USER19> I am a fan of rust, but this article overstates the simplicity of C/rust integration.

A few examples:

* You may need to use PhantomData in your struct definitions to properly track lifetimes. Not sure I fully understand.

* C functions don't always return. Sometimes they longjmp (c.f. PostgreSQL). Calls into C code need to prepare for this and it's not trivial nor does it generalize to all projects.

* Integrating with the memory management scheme is probably possible but not trivial. For instance, Postgres memory contexts (regions/arenas) can hold any kind of object, and code can switch between them and create/destroy them at will. You could rely on rust to manage it's own memory, with circular references an Rc that might leak.

* Postgres has its own calling convention for SQL-callable functions and conventions for loadable modules. Integrating with this is a pain because macros are hygenic and can't make up new symbols. Maybe procedural macros will help when they arrive.

* Rich APIs that rust supports don't always translate well to C. When integrating with a large application that pushes you toward the lowest-common-denominator APIs.

* A lot of C macros don't translate well to rust and just including a C header in rust is a lot of work. Hoping procedural macros will help here too.

<comment><USER20> Btw, are you planning to work on a thin integration layer between rust and postgresql? Sufficient to be able to write UDFs in rust? That's imo the most realistic start to get some experience w/ rust in the postgres community, and it provides value on its own.

<comment><USER19> I've made some progress. Not quite as thin as I had hoped ;-)

I really need procedural macros to stabilize, otherwise it just puts too much pain on the UDF author.

<comment><USER20> > I really need procedural macros to stabilize, otherwise it just puts too > much pain on the UDF author.

Why exactly is that? I'd have expected a C wrapper to take care of most of that? Are you concerned about the Datum<->native type C macros?

Are you planning/hoping for this to be all safe, or is there going to be unsafety in the wrapper?

<comment><USER19> Creating a new module or UDF requires exporting new special symbols for V1 calling convention.

Rust's hygenic macros don't let you do that. So defining a UDF has a bunch of boilerplate, unless I am missing something.

Procedural macros should alleviate this, but it will be a while. I might just release and document the boilerplate needed.

EDIT: Yes, I am trying to be mostly safe. I will see how close I can get for at least the basic stuff.

<comment><USER20> > Creating a new module or UDF requires exporting new special symbols for V1 > calling convention.

Right - but I don't think you need to do so. That'd only be required if you'd use language 'C' \- why not instead use language 'rust'. That'll force a simple wrapper function which looks up and calls the real function, but that's fairly harmless, no? Might actually be good, because you can do some extra checks and conversions there.

<comment><USER19> There are some extension APIs that demand C. But perhaps I dismissed the idea of plrust too quickly and there is room for both?

<comment><USER20> I'd say it'd be better to let PL handlers decide whether they can be used in those cases. IIRC those cases largely exist because you need to be able to deal with pointers which existing pls weren't able to...

</comment></comment></comment></comment></comment></comment></comment></comment><comment><USER21> Is it really the time, yet, to start advocating for rewrites in Rust? Worth considering for new projects, definitely. Using to write new components of existing projects, maybe. But rewriting existing work?

I'm concerned if we start pushing that too much too early, the initial friction will burn people. You only get one first impression.

For anyone who thinks "yes, now is the time" I have questions for you:

Have you released and distributed software written in Rust? What's the install story like for end-users? Is it in a repository for a major OS (e.g. can I yum install it, or apt-get it) and if so which?

As far as I can tell there's no major package manager accepting or even ready to accept programs written in Rust yet. Am I misinformed?

<comment><USER17> > As far as I can tell there's no major package manager accepting or even > ready to accept programs written in Rust yet. Am I misinformed?

At least Debian, Fedora, Arch, and Gentoo have rustc and cargo in their repositories. Oh and Alpine, recently. FreeBSD (IIRC) has it in ports.

In the not-too-distant future, there's a pretty important package that will require Rust: Firefox. HEAD already does today.

<comment><USER22> But you do realise that pressuring distributions in that way (when there are still issues with integrating cargo and crates into our existing build systems) won't result in Rust being properly supported right? There will be some hack to get Rust to work "well enough" to build Firefox, and if someone wants to start packaging more Rust stuff then all of the work would either need to be redone or started from scratch.

I'm saying this as someone who has started writing their projects in Rust and has plans to ship said projects as part of openSUSE and eventually SLES. If you cannot satisfactorily maintain a Rust package inside OBS then it's a non- starter. I imagine that many other distributions feel this way. We were burned with Ruby (and continue to be burned by it) and I doubt that anyone is going to jump on the "just auto-generate an RPM for every version of every crate we need" solution.

It's great that Firefox will have Rust code, but I'm not convinced that will make the situation better for distributions. It'll just make the packagers more stressed out.

<comment><USER17> All I can really say is, we're interested, willing, and actively working with distro maintainers on fixing their issues. It's something we care about.

It is just one of many things on our plate, though.

</comment></comment></comment></comment><comment><USER23> The trouble with mixing Rust and C/C++ is that you tend to get Rust with C/C++ unsafe pointers. Most of the examples of this pass C raw pointers into rust, Rather than passing a Rust Vec into C. Or even passing STL strings and vectors into Rust. So, instead of passing Rust's array size information into C, they propagate C's lack of size information into Rust. Typical example: [1]

        pub extern "C" fn count_substrings(value: *const c_char, substr: *const c_char) -> i32

If you incrementally convert from C/C++ to Rust, you end up with those constructs in the final Rust program. Not good.

[1] [http://siciarz.net/24-days-of-rust-calling-rust-from- other-l...](http://siciarz.net/24-days-of-rust-calling-rust-from-other- languages/)

<comment><USER24> You only end up with them in the final program with a naive translation that makes life hard for yourself. Using the native types is much nicer (even ignoring any safety benefits), and so people are naturally encouraged to do so. For instance,

\- the C interface can easily be thin wrappers around pure "nice" Rust functions, that just do the necessary unsafe conversions

\- and, whether or not that is used, when a function is no longer being called from C (that is, everything that calls it has been converted to Rust) the arguments can be switched to something more natural and strong static typing will point out all the places that need to be updated.

I cannot believe that a pure Rust codebase would want to be passing raw pointers around. And the alternatives don't seem at all better: only ground-up complete-rewrite migrations (hard to justify so often won't even start) or not migrating at all (meaning one has a C codebase that is still full of unsafe pointers).

</comment></comment><comment><USER25> The title ought to have been, "Why you should rewrite _some_ of it in Rust." That's what the article is actually about. Then we could have a productive discussion about which parts, rather than yes or no.

<comment><USER26> Good idea. We've added that bit above.

</comment></comment><comment><USER27> Am waiting for Coq developers to start showing up and asking for Rust projects to be rewritten using Coq / Compcert.

<comment><USER28> Compcert is guaranteed to compile _correct_ C code to correct assembly (given its TCB assumptions). It doesn't say anything about incorrect C code. So in order to benefit from CompCert, first you have to prove that you have valid C in the first place, which is no easy feat. You'd probably be better off using a language that's designed with verification in mind, like Cogent or ADA/Spark, or waiting for lambda-Rust to become production ready, since in those cases you won't have to prove tedious bureaucratic memory safety invariants for the vast majority of your code, and can focus on functional correctness (or, if you just care about memory safety, you can stop there).

</comment></comment><comment><USER29> "Rewrite it in Rust" is the new "Stallman was right" thread.

Its an echo chamber of fandom. Over time I've come to despise "evangelism" or any kind. I'm sure Rust is great. I just don't think it's news every time a Rust fan says that its great.

YouTube lectures of people actually using it? That would be interesting. Interviews of people actively porting a large C project to Rust. That would be interesting.

Rehashing its feature sheet? Not so much.

<comment><USER30> The author is actually using it, to actually rewrite portions of C projects in it, and writing about their experience doing this in practice. For example, the linked paper is about using Rust at the I/O boundary in an existing, complex system.

<comment><USER29> Except that the article is actually just the feature sheet of Rust. I would rather the article had been a link to that paper.

<comment><USER30> uhhhhhh, multiple links in this block on the post:

"That's because I have been working on this subject for a long time now:

* I did multiple talks on it * I even co-wrote a paper * I did it both as client and personal work"

<comment><USER29> Yes, I saw those links. The article that op linked to though was another Rust feature sheet blog post, though.

This was days ago, why do you care?

</comment></comment></comment></comment></comment><comment><USER31> While I am avid supporter of Rust, I can't help but feel this post is not right. If Rust is so much better, why not prove it by writing software in Rust, instead of words. After all, if Rust is so much better, the result will speak for itself.

<comment><USER30> In this case it seems the author is writing about the concrete results they've already obtained, not about something abstract.

</comment></comment><comment> Const-me Writing manually-vectorized SIMD code is the only way to approach advertised performance on any modern CPU.

While there's _some_ SIMD support in Rust nightly builds (but not in Rust stable), it's just not good enough. For one thing, Intel only supports their intrinsics for C (C++ also gets that 'coz compatibility) and Fortran. Another thing, Rust strong type-safety concept complicates SIMD code, especially when the code does integer math. These __m128i / __m256i / __m512i registers are often treated as different data types by even consecutive instructions.

While Rust might be good enough for some areas, performance critical CPU bound code is not one of them.

<comment><USER17> Yeah, SIMD is being very actively worked on; until then, you can link in an external assembly file, but that's not exactly the best UX.

<comment> Const-me Yep, assembly's not the best UX.

When you're coding assembly, you have to code everything in it, including code running on the scalar parts of CPU cores. With intrinsics you can code these parts the usual way, e.g. for( size_t i=0; … )

With intrinsics you can even compose your vectorized code the usual way, VC and Clang have __vectorcall calling convention for that, Intel has very similar __attribute__((regcall)).

<comment><USER17> Yup, absolutely. My understanding is that an RFC is currently being written, so it's gonna be a little while to get into stable, but not forever. We'd have liked to have had it sooner, but some stuff happened, that's just how it goes sometimes.

</comment></comment></comment></comment><comment><USER32> We need Rust to have great support for ARM microcontrollers before the IoT industry really takes off.

<comment><USER33> The relatively low portability of rust programs is definitely one of its largest shortcomings.

<comment><USER34> Can you elaborate? Although haven't tried it myself, I was under the impression that it's quite possible to write low level code for at least for x86 and ARM (and AVR?).

<comment><USER33> You can write low level code. Tier 1 platform list is very short however.

[https://forge.rust-lang.org/platform-support.html](https://forge.rust- lang.org/platform-support.html)

<comment><USER35> It's probably unreasonable to expect a wide variety of IoT platforms to meet the "automated testing" requirement for Tier 1 status.

</comment></comment></comment></comment></comment><comment><USER36> If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.

<comment><USER37> Oh no, no, no! Some people _may_ reasonably, with some extreme care and diligence, maybe try to claim they can write safe and UB-free C code. If stars align properly. (See maybe SQLite. Seen as one of the pinnacles of crazy pedantism in C. Also, see the article about errors found recently in SQLite with fuzzing!) But with C++, it's just impossible for a human. It's too big, too quirky, too big, too wide, too deep, too tricky, too big, too complicated, and also too huge. And purposefully (sic! for performance) sprinkled with UB, which means barbed fences, trip-wire mines (to _boost_ your in-flight performance), and hidden pit traps. Writing C++ code longer than a few lines without UB is _humanly impossible_. Sorry. And that's just about UB, because it's the most unpredictable thing; but there's still exception safety, for example, which you also should be doing, which can "only" spoil your code's logic (and then, obviously, go on writing over random memory, but that's nothing uncommon for us C++ers). Is every line of your C++ codebase exception safe? Yeah, sure. Good luck. And "modern C++" only means more C++. Because backwards compatibility. Unless at some point some quest for a "safe subset of C++" finally gains traction, which may maybe bring back some sanity. I do really hope for that.

A personal opinion from a person who loved C++ for quite some time, before diving deep enough to realize how dark is the abyss.

<comment><USER38> Basically exception safety is a solved problem in Modern C++. If you use RAIIike it was meant to be used, exception safety is not that big a deal.

<comment><USER39> True, I guess, for "business logic"-y classes. Not true at all for data structures, particularly those that are templates.

<comment><USER40> How is it not true for data structures? Even templated ones?

</comment></comment></comment></comment></comment><comment><USER41> I would love to learn Rust, but the learning curve seems a bit too steep for me. The whole struggle with lifetimes is what has kept me from diving in. It seems impossible to me to figure out how to use them correctly. Plus the redundant syntax, I guess. If those things weren't an issue for me, I would gladly try to learn Rust.

<comment><USER17> Lowering the learning curve is a huge objective of this year!

> The whole struggle with lifetimes

How did you try to learn them? I'm interested in trying to make this easier!

> the redundant syntax

Which bits are redundant?

</comment></comment><comment><USER42> Has anyone done any in depth explorations of the safety and security of rust code vs well written C or C++?

<comment><USER43> Well written the hard part there. I am riding on on the idiomatic C++11/14/17 train right now.

Life over here is great, but I can the warts of the language looking backwards. The promised land in the future doesn't look quite as bright as the promises Rust offers. The only thing keeping me from trying it is the giant codebases in my current projects.

<comment><USER8> > I am riding on on the idiomatic C++11/14/17 train right now.

How do you see it?

Nowadays I only use C++ on hobby projects or when Java/.NET need some kind of integration work.

To me it seems that as code bases grow organically, it will become very hard to get which code is in which ANSI version, specially problematic given some of the changes that took place between standard revisions.

<comment><USER43> At both of my jobs, I am working way too much, I am working in pre-C++11 codebases which now allow C++11. Both are working to for -Werror everywhere and that helps a huge amount, and we can try to get more warning listed and make broad but subtle changes to the codebases.

At one place we are in a race before a tight deadline and at the other we are breaking a large monolith into smaller packages. At one place we implement a new practice for all our code, and at the other we implement all our best practices as we chop code out of the monolith. Both places are seeing a reduction in bugs. The place with the packages is probably reaping a larger benefit because they are aggressively re-working old code and have better test coverage and can do so with confidence.

Code bases do grow organically, but like places they can be tended and pruned to make impressive orchards or topiaries or left to the wild to become impassible jungles. Tools like RAII, exceptions, classes, etc... are just tools for managing this.

I think the tools in C++11/14 are at least as powerful as in any language except perhaps Rust. Every time I hear a C developer say "C can be just as safe..." I am imagine a person with nothing but a pocket-knife trying to manage a whole forest.

<comment><USER8> Thanks for the overview.

</comment></comment></comment></comment></comment><comment><USER44> Well Rust seems like a nice enough language if blog posts are anything to go by. But I really cannot unless we something like RustPython and Rython to replace CPython and Cython. (If anybody does write a new Python distribution on rust I named if first)

<comment><USER45> Someone has already done the honors:

        https://github.com/shinglyu/RustPython

<comment><USER44> Should have seen it coming. Though it seems to be a one man show for now.

</comment></comment></comment><comment><USER46> You can also rewrite to C++, OCaml, Go... Each language has benefits and drawbacks, and there is good reason for each them to exist.

Would your project benefit a lot from algebric datatypes -> OCaml is a great fit!

You want to port as soon as you can: C++ is your friend.

You plan to write HTTPS service nodes: Go has the best standard library out there.

<comment><USER47> If you read the article you'll notice that he proposes that Rust is a better language because it allows incremental rewriting, rather than a complete one; Rust doesn't have a runtime, doesn't have GC, and can fairly seamlessly/painlessly integrate with C (you can both call and be called from C easily).

That changes the equation considerably, compared to something like Go where none of these benefits exists. For example, exporting code from Go not only requires the runtime and GC, there's also significant function call overhead because of the way Go maps goroutines to threads.

There are many other good languages, but few of them have these benefits. C++ is probably the option with the least amount of friction against C, but then you're also inheriting most of the unsafety of C.

<comment><USER48> Incremental rewriting introduces the potential for new issues, as foreign function interfaces are inherently unsafe.

Rust also has its own costs. Its biggest limitation when it comes to mixing in code with that written in another language is probably its poor support for shared ownership (i.e. multiple references of the same object), while in most languages, shared ownership is the norm.

Multi-language setups (which you invariably get with an incremental rewrite) also generally create other interfacing issues when they share objects. How are you going to represent `std::shared_ptr<T>` or `std::vector<T>` in Rust, for example? They are opaque types, after all. Can you guarantee that Rust properly observes C++ semantics with regard to assignment, move assignments, and destructors when dealing with instances declared entirely in C++ code once you start mixing and matching C++ and Rust?

</comment></comment></comment><comment><USER49> Or even better, Haskell!

<comment><USER50> If you rewrote only part of a large C++ project in Haskell, is there a way to link it back in again?

<comment><USER51> Call Haskell from C (not C++) seems pretty easy:

\- [Calling Haskell from C - HaskellWiki]([https://wiki.haskell.org/Calling_Haskell_from_C](https://wiki.haskell.org/Calling_Haskell_from_C))

And the FAQ on the Haskell wiki directly addresses this too:

\- [https://wiki.haskell.org/Introduction#I_already_have_a_large...](https://wiki.haskell.org/Introduction#I_already_have_a_large_application_in_C_or_C.2B.2B).

So apparently it _is_ doable!

<comment><USER52> It pulls in a huge runtime system, though (including stuff like garbage collection). This makes it much heavier than calling some Rust code.

<comment><USER53> True, where "huge" means something around 10MB.

For many projects that is a showstopper.

</comment></comment></comment></comment></comment><comment><USER54> Why Rust? Why not Idris? Why not Haskell?

Or you know, why rewrite it at all? You could instead try and use a safe C implementation (such as gcc/clang with the sanitisers or something like [https://staff.aist.go.jp/y.oiwa/FailSafeC/index- en.html](https://staff.aist.go.jp/y.oiwa/FailSafeC/index-en.html)), but to be frank if I was to rewrite my programs I would use a truly modern language like the ones that I mentioned above.

<comment><USER55> All of your questions are addressed in the article.

> Why Rust? Why not Idris? Why not Haskell?

        it can easily call C code
        it can easily be called by C code (it can export C compatible functions and structures)
        it does not need a garbage collector
        if you want, it does not even need to handle allocations
        the Rust compiler can produce static and dynamic libraries, and even object files
        the Rust compiler avoids most of the memory vulnerabilities you get in C (yes, I had to mention it)

<comment><USER54> All of these except GC also hold true for the languages that I mentioned.

As for GC, I think that Mercury avoids its use [https://lirias.kuleuven.be/bitstream/123456789/131304/1/Mazu...](https://lirias.kuleuven.be/bitstream/123456789/131304/1/Mazur.pdf)

<comment><USER56> Nope- C interop is higher on the list for a reason. Idris and Haskell do not produce straightforward, runtime-less binaries that can be easily loaded by e.g. CPython or Node, without any interference with _their_ runtimes.

</comment></comment></comment></comment><comment><USER57> Is this article "Use Rust" or "Stop using C"?

I mean both are reasonable arguments that get made often on here, but the one doesn't necessarily follow from the other.

<comment><USER58> I think its a little bit of both. Primarily it is aimed at legacy software. IMO not a lot of new code is written in legacy C, so we have a problem with having a ton of dependencies written in a way that may not be the safest or most reliable (from recent experiences). The authors suggestion is to rewrite parts of those applications that tend to be buggy (mostly I/O parts) in Rust.

I really hate to see the naysayers comment on this article without even having read it. I think the author made a very good point.

</comment></comment><comment><USER59> In my opinion, there are more reasons to rewrite Rust code in C.

<comment><USER60> such as?

<comment><USER59> E.g. ABI compatibility, multi-platform support, tools, open source code base, community, etc.

<comment><USER61> ABI compatibility: Not really solved in C++ - see MSVC versus Mingw. If you're coming from the standpoint of using a Linux distro or BSD you enjoy a sanitized environment from the start.

Multi-platform support: Pray that your project's build system makes it straightforward to get all the dependencies going on every platform. Pray that your dependencies are easy to access and of the correct version. Pray that the manufacturer's fork of an ancient gcc isn't too buggy to use. C made it possible, not easy.

Tools: Both languages are too impoverished to have tooling as comprehensive as the stuff available in, for example, Java, although VS pushes very hard on this front. rustc already gives better error messages than any C++ compiler.

Code base: See the build system problem. Maintaining open source projects in C and C++ is an exercise in endurance. Single header file libraries have come into vogue as a result - and they're a hack. There is a lot of decent code in both languages not being used because it's hard to get running.

Community: Rust is in a better position here in part because it's smaller. If I encounter a C++ hacker in an online space it's just as likely to be an aggro kid as a seasoned pro.

<comment><USER59> My point was explicitly about C, not C++. All these points are solved in C, _decades_ ago.

</comment></comment></comment></comment></comment><comment><USER62> Or write in Haskell in the first place.

Good Haskell code is rather fast, but that's beside the point. For many projects, the only measure of goodness should be how nimbly one can then use and experiment with one's code. In Haskell, like Lisp before it, one ends up with a language to use one's code. Like writing a Mathematica package and getting all of Mathematica for free, only better.

</comment><comment><USER63> C can be safe if you use Turing incomplete libraries that have been verified. It's the YOLO ad hock parsers that get you in trouble.

<comment><USER43> I am not sure if you are serious or not.

How does verification prevent buffer overflows? It can reduce their frequency, but you can never know you got them all. They find issues in libCURL and openSSL that have existed for years. Very few people are better than the people working on those libraries.

It is better to be safe by default then add risk only when you need it. I say this as a C++ developer, I think const should be the default state of all variables and one should have to opt out of that, and Rust did that right and C is so far from that I see no reasonable way to use plain old C safely. At least with C++ I can hide my stuff in classes and verify one thing at a time.

<comment><USER54> Formal verification is not the same as a security audit. With formal verification you can prove that something is bug-free.

> They find issues in libCURL and openSSL that have existed for years

Neither of them are formally verified. [https://github.com/seL4/seL4](https://github.com/seL4/seL4) however is formally verified.

<comment><USER43> Please, step away from "formal verification" and come back to world the rest of us devs work in. I have never seen a formally verified piece of software even once.

I don't know if its too hard to do to real software or if C doesn't allow for it, or if it is just too expensive. The simple matter is that is not an option for the vast majority of projects. Unless you can make it practical, I assert it has no place in a practical discussion about preventing software issues.

<comment><USER40> Worse: "It's amazing how many bugs there can be in a formally verified piece of software." I forget who said it, but it's been a long time. (Maybe in connection with formal verification of an OS? Does anyone remember?)

Formal verification only works if the formal verification was mistake-free. (And how are you going to prove that? With a formal verification? It's turtles all the way down...) Also, it only works for the aspects that were formally verified. Heartbleed, for example, could be regarded as a flaw in the specification; formally verifying that the code matches the spec won't save you from that.</comment></comment></comment></comment></comment>


Ask HN: What's the best donation/tip "jar" for a blog? - <AUTHOR> I want to add a way to get donations on my blog, and I was wondering which donation/tip "jar"/button gets the best results? <comment><USER2> There are many ways to do this, but I pose the question: are you trying to build a community, or just make money?

If you think about your audience and work backwards from there, you might be able to answer that for yourself.

Off the top of my head I would say [https://www.patreon.com/](https://www.patreon.com/) would be the first step...

Side Note: I would warn against going for the "best results" and instead built the community... once you are getting funds to be able to worry about colors, affiliations, etc... that will be a good problem to have :)

</comment><comment><USER3> Consider using multiple options, for example Paypal Donate and Patreon.

</comment><comment><USER4> Ko-fi

Patreon

Just a PayPal send me link</comment>


Invite HN: Tagxt.com Open Beta Weekend (HackerNews Only) - <AUTHOR>

hi HN! it's probly way early to make this public but i'm going a little untraditional on this one.<p>check this out: http://www.tagxt.com/post/1 <comment><AUTHOR> really? no feedback on this? what gives</comment>


Tell HN: I'm worried that certain posts are made and deleted to hide news - <AUTHOR> This post might be a paranoid reaction on my behalf, but I've run into this issue twice in three weeks. In both cases, the news portrayed was negative for someone (https://news.ycombinator.com/item?id=19165839 , https://news.ycombinator.com/item?id=19004568). I totally understand flagging a post because you believe it doesn't have a place on HN, or deleting your own post for the same reason. However, the latter approach makes it markedly more difficult for someone else who thinks differently about the post to make it on their own, and can therefore be used to willfully prevent discussion.<p>Again, my reaction could just be interpreting malice where there is none. However, please do not take away the privilege to agree to disagree with each other from topics of conversation where we are still able to act with civility with one another. <comment><USER2> It's a bad idea to delete your own post. If you do too much times the mods may ban your account. Delete the post only when you made a (big) mistake.

\-- About [https://news.ycombinator.com/item?id=19004568](https://news.ycombinator.com/item?id=19004568) " _Undercover agents target cybersecurity watchdog Citizen Lab_ "

See [https://hn.algolia.com/?query=undercover%20apnews&sort=byPop...](https://hn.algolia.com/?query=undercover%20apnews&sort=byPopularity&prefix&page=0&dateRange=all&type=story)

It was submitted three times before your submission. That's probably the reason the dupe detector blocked it. Anyway, it was resubmitted again two times after you submission and one got 463 points and 172 comments [https://news.ycombinator.com/item?id=19131729](https://news.ycombinator.com/item?id=19131729)

I don't see nothing shady there

\-- About [https://news.ycombinator.com/item?id=19165839](https://news.ycombinator.com/item?id=19165839) " _Facebook 's security team tracks posts, location for 'BOLO' threat list_"

I don't understand what problem you had when you tried to submit it. It looks like a normal post that didn't get traction.

<comment><AUTHOR> > \-- About > [https://news.ycombinator.com/item?id=19004568](https://news.ycombinator.com/item?id=19004568) > "Undercover agents target cybersecurity watchdog Citizen Lab"

My experience with the duplicate detector is that it takes you to the duplicate. It didn't that time, and I got an error message. When I tried looking up the URL on hn.algolia.com at the time, I didn't find it (I just copy and paste the full URL).

> \-- About > [https://news.ycombinator.com/item?id=19165839](https://news.ycombinator.com/item?id=19165839) > "Facebook's security team tracks posts, location for 'BOLO' threat list"

[https://www.cnbc.com/2019/02/14/facebooks-security-team- trac...](https://www.cnbc.com/2019/02/14/facebooks-security-team-tracks-posts- location-for-bolo-threat-list.html) is the original URL that didn't work for (note the 'www' subdomain).

It's possible that hn.algolia.com can be slow at times and I'm interpreting that delay combined with the error message as something fishy. Thank you for the reply `gus_massa .

<comment><USER2> About the first one: I had to tweak the search for a while until I got a meaningful set of results. Sometimes it's no easy.

</comment></comment></comment><comment><USER3> HN _loves_ bashing Facebook and the Citizen Lab story did get some discussion on the front page. I think HN has so many problems with discoverability in general and this particular subproblem (if it exists) is not even the biggest one. BTW, you can add something like ?please_give_me_a_second_chance to URLs to bypass dupe detection, but if you abuse it then other factors may kick in.

</comment><comment><USER4> You can go into your settings and enable "showdead" to at least see if something was indeed marked for review.

<comment><AUTHOR> Thanks. I have that on already. Usually, trying to submit a story that's already been submitted takes you to the already submitted one, but when the story is deleted by submitter, you just get a message.</comment></comment>