Tail recursion in Python - <AUTHOR> http://chrispenner.ca/posts/python-tail-recursion <comment><USER2> Someone recently pointed out to me you can bypass the recursion limit with an inbuilt decorator, because it's basically a memoiser.

lru_cache, from the functools library.

The example given in the docs [0] is:

        import functools

        @functools.lru_cache(maxsize=None)
        def fib(n):
            if n < 2:
                return n
            return fib(n-1) + fib(n-2)

[0] [https://docs.python.org/3/library/functools.html#functools.l...](https://docs.python.org/3/library/functools.html#functools.lru_cache)

<comment><USER3> This only works in specific cases (namely those where dynamic programming algorithms suffice), and does not avoid the recursion limit in general.

<comment><USER4> Don't dismiss one of my favorite higher order functions so soon :)

"Recursion + memoization provides most of the benefits of dynamic programming, including usually the same running time." \-- Steven Skiena

lru_cache decorator is great for people who are happy to let the language handle the caching of results for them, and often leads to code which is much more concise than the dynamic programming approach. The limitation you are referring to is that the decorator uses a dictionary to cache results and that dictionary uses the arguments as keys so the arguments need to be hashable. That limitation can be avoided by using immutable data structures (Clojure also has a higher order function called memoize which does the same thing and has no limitations because the core data structures in Clojure are immutable) and although Python not having structural sharing can mean that this approach can hurt memory and GC efficiency a bit, but that trade-off is at least worth considering :)

Still have to keep the stack depth less than sys.getrecursionlimit() so no substitute for tail recursion but surely a substitute for dynamic programming in a lot of cases.

<comment><USER5> You can only avoid the recursion limit in cases where dynamic programming would also work, as you have to explicitly call the function in reverse stack order to avoid having the stack build up. If you want fib(10000) you need to call fib(1) through fib(9999) first, as if you were implementing a dynamic programming solution.

This isn't dismissive. lru_cache is one of my favorites too, but it has limitations.

<comment><USER4> But that isn't a limitation of lru_cache, for example the same higher order function when used in Clojure i.e. memoize with recur for tail recursion will not cause stack overflow. The stack build up is because python doesn't support tail call optimization, not a limitation of lru_cache, just wanted to make it clear because you can use similar higher order functions in other languages which support tail call optimization without any limitations. Deep recursion in Python without sys.setrecursionlimit() is probably not a good idea, memoization can't help you in that. My point was geared towards presenting this pattern of memoization using a higher order function + recursion as an alternative to dynamic programming and in languages with tco and immutable data structures it works beautifully :)

<comment><USER5> I agree that this isn't a limitation of the Platonic ideal of an lru_cache function. I thought we were talking about actual Python code.

</comment></comment></comment></comment></comment></comment><comment><USER6> The hackyness/speed issues aside:

When compiling/transpiling/whatever between languages, I have found that relying on regular procedure calls and TCO is generally a lot simpler than having to force the looping facility of one language into the semantics of another language.

The only one I can actually imagine porting other loops to is the common lisp loop macro, but that is probably the most flexible looping facility known to man.

Edit: and oh, cool thing: racket and guile has expanding stacks and doesn't have a recursion limit other than the whole memory of the computer. This is pretty handy when implementing something like map, since you can write a non- tail-recursive procedure so that you don't have to reverse the list at the end.

<comment><USER7> With regards to stacks that can use all of the memory: Gambit and AFAIK Chicken behave that way, too. This is one of the reasons I chose Scheme over OCaml (and Haskell) over a decade ago when looking for a new language to move to.

<comment><USER8> Even Python doesn't need to have stack limit - just make sure C stack is large enough (e.g. using ulimit or pthread_attr_setstacksize) and use `sys.setrecursionlimit(1000000000)`.

<comment><USER7> Making the C stack large enough is not solving it on 32 bit architectures with enough physical RAM that you can't/don't want to waste address space. And on 64 bit architectures address space isn't a problem, but the memory from a temporary large stack can't be re-used without swapping the old stack contents out which is slow.

</comment></comment></comment></comment><comment><USER9> This can also be done using trampolines without using try/catch method: [https://github.com/0x65/trampoline](https://github.com/0x65/trampoline)

</comment><comment><USER10> Code snippets you won't see if you have JS disabled:

[https://gist.github.com/ChrisPenner/c0b3f4feb054daa2f6370d2e...](https://gist.github.com/ChrisPenner/c0b3f4feb054daa2f6370d2e9961d6d3)

[https://gist.github.com/ChrisPenner/c958afbf6e7a763c188d8b83...](https://gist.github.com/ChrisPenner/c958afbf6e7a763c188d8b83275751bb)

<comment><USER11> JS fully disabled in this day and age?

<comment><USER12> I've noticed a shift over the last while how privacy-protective people are becoming "out-group" and a little weird.

I mean, I personally don't care; I've always been a little weird. But it is funny to see technical preferences as a signaling mechanism.

Funny, that is, until it hits a certain point... [http://www.wired.co.uk/article/chinese-government-social- cre...](http://www.wired.co.uk/article/chinese-government-social-credit-score- privacy-invasion)

<comment><USER13> battle is over, privacy lost

<comment><USER14> Where can I buy your browsing history?

</comment></comment></comment></comment></comment><comment><USER15> > def tail_factorial(n, accumulator=1):

> if n == 0: return 1

> else: return tail_factorial(n-1, accumulator * n)

The second line should be "if n == 0: return accumulator"

<comment><USER16> 0! == 1

EDIT: Oops. As pointed out below, the code is indeed incorrect, and my comment is irrelevant.

<comment><USER17> True, but irrelevant. For all values of n > 1, that function will return 1, which is clearly not what the author intended.

</comment></comment></comment><comment><USER18> Your code is still allocating a new stack frame anyway. So no optimization is happening. You are simply avoiding a stack overflow which is not the purpose of tail-call optimization.

I'm not sure if there is any advantage when language/compiler does not provide a proper tail recursive optimization.

<comment><USER19> It's a gross exaggeration to say there's no advantage. Who decided that stack frame re-use is "the purpose" of tail-call optimization, while not blowing the stack is not? It seems to me that being able to run the function at all is more important than whether it runs quickly.

</comment></comment><comment> a-nikolaev > It turns out that most recursive functions can be reworked into the tail- > call form.

This statement in the beginning is not entirely correct. A more accurate statement would be that all recursive programs that are _iterative_ (if they are loops in disguise), can be rewritten in a tail-call form. That is, there must be a single chain of function calls.

The inherently recursive procedures cannot be converted into a tail-call form.

</comment><comment><USER20> A patch that implements TCO in Python with explicit syntax like 'return from f(x)' could likely get accepted, ending these hacks

<comment><USER2> Would it? My impression is that Guido is fairly against any such thing occurring [0].

> So let me defend my position (which is that I don't want TRE in the > language). If you want a short answer, it's simply unpythonic.

[0] [http://neopythonic.blogspot.com.au/2009/04/tail-recursion- el...](http://neopythonic.blogspot.com.au/2009/04/tail-recursion- elimination.html)

<comment><USER20> His primary concern is with implicit tail recursion

I tried making such a patch in the past, got stuck in the much of trying to update the grammar file in a way that wouldn't complain about ambiguity

Main thing to get from tail calls vs loops is the case of mutually recursive functions

<comment><USER2> His primary concern seems more to be stack traces.

At the time, an explicit style, with patch, was proposed to python-ideas. [0] It was based around continuation-passing-style, and the conclusion reached then by the community was the same. TCO, explicit or not, isn't wanted in Python.

> And that's exactly the point -- the algorithms to which TCO _can_ be applied > are precisely the ones that are not typically expressed using recursion in > Python. - Greg Ewing [1]

> <sarcasm>Perhaps we should implement "come from" and "go to" while we're at > it. Oh, let's not leave out "alter" (for those of you old enough to have > used COBOL) as well! </sarcasm> \- Gerald Britton [2]

Feel free to try again, maybe things have changed.

To be clear, I wish Python did have a mechanism to express these sorts of problems, but I don't think the Python team themselves want them. This issue has come up more than a few times, and the dev team have never been satisfied that Python really needs it.

[0] [https://mail.python.org/pipermail/python- ideas/2009-May/0044...](https://mail.python.org/pipermail/python- ideas/2009-May/004430.html)

[1] [https://mail.python.org/pipermail/python- ideas/2009-May/0045...](https://mail.python.org/pipermail/python- ideas/2009-May/004522.html)

[2] [https://mail.python.org/pipermail/python- ideas/2009-May/0045...](https://mail.python.org/pipermail/python- ideas/2009-May/004536.html)

</comment></comment></comment></comment><comment><USER21> I experimented with something similar to this way back[1], but took a slightly different approach - you can replace the reference to the function itself inside the function with a new function[2], one that returns a 'Recurse' object. That way it looks like it's calling the original method but really it's doing your own thing.

1\. [https://tomforb.es/adding-tail-call-optimization-to- python/](https://tomforb.es/adding-tail-call-optimization-to-python/)

2\. [https://gist.github.com/orf/41746c53b8eda5b988c5#file- tail_c...](https://gist.github.com/orf/41746c53b8eda5b988c5#file-tail_call- py-L16)

</comment><comment><USER22> I'm not a pythonista, but this code seems to get rid of the recursion limitation of the interpreter. Does it actually "optimize" things and make the function take a constant space as it is calling itself?

<comment><USER23> It takes a constant space since it is not even recursive. The decorator makes it a non-recursive function with a loop.

It'll effectively side-steps the recursion limit in Python. For runs under the limit anyway, it'd be interesting to see whether it's any faster. It trades function call overhead for exception handling overhead.

By the way, the first example where it has `return 1` is wrong. It shoudl `return accumulator`. Clicking the GitHub link someone suggested this in December.

</comment></comment><comment><USER24> You can also do this by rewriting functions with a decorator.

[https://github.com/Bogdanp/tcopy](https://github.com/Bogdanp/tcopy)

</comment><comment><USER25>
      def tail_factorial(n, accumulator=1):
        if n == 0: return 1
        else: return tail_factorial(n-1, accumulator * n)

This just returns 1 every time.

<comment><USER26> It should be:

      def tail_factorial(n, accumulator=1):
        if n == 0: return accumulator
        else: return tail_factorial(n-1, accumulator * n)

</comment></comment><comment><USER19> This article and the other comments here are interesting, but some are trying to be a bit too clever. The original article isn't too bad, but one of the other comments suggests re-writing the contents of the function at run time, which I really don't think is a practical suggestion (think about debugging such a thing).

If I wanted to do this in practice, I'd just write the trampoline out explicitly, unless I wanted to do it a huge number of times. Doing it this way only takes a couple of extra lines of code but I think that's worth it for the improvement in explicitness, which is a big help for future maintainers (possibly me!).

        from functools import partial

        def _tail_factorial(n, accumulator):
            if n == 0:
                return accumulator
            else:
                return partial(_tail_factorial, n - 1, accumulator * n)

        def factorial(n):
            result = partial(_tail_factorial, n, 1)
            while isinstance(result, partial):
                result = result()
            return result

</comment><comment><USER27> Tail recursion is a programming idea left over from the LISP era. It's from when iteration constructs were "while" and "for", and there were no "do this to all that stuff" primitives. Python doesn't really need it.

<comment><USER28> Tail calls aren't always just used for some simple iteration. For example, you could have several mutually recursive functions calling each other in tail position. If you wanted to turn that into a loop, you'd have to roll all those functions into a single loop body, which would be made even less elegant due to the lack of goto statement. (TCO essentially turns a call into a goto whenever possible.)

<comment><USER29> Lots of languages can express it better though - even without gotos. For example in python you can do:

        while some_condition:
            x = one_generator(y)
            y = other_generator(x)

where the generators yield values. No need for goto, no TCO, no magic.

Even in languages like C, a nicer way to express it may be via two explicit state machines rather than going full Duff's device at this problem.

<comment><USER30> Python's generators are more magic. It's similar to some kind of COME FROM mechanism.

<comment><USER29> Weird comparison. Come from has no indication on the other side that it will happen. Generators are pretty explicit with yield. On the calling side they can be explicit with a next() call.

<comment><USER30> A generator may have multiple yields, if you call next(), then it comes from that call to the last yield call - based on the current execution context. The yield waits that the execution comes back to it.

The idea of function calls is much simpler - no yield magic necessary.

</comment></comment></comment></comment></comment></comment><comment><USER31> I used it to play with some functional programming in Python [https://github.com/lion137/Functional--- Python](https://github.com/lion137/Functional---Python)

</comment><comment><USER32> > def tail_factorial(n, accumulator=1):

> if n == 0: return 1

> else: return tail_factorial(n-1, accumulator * n)

Does this ever return the accumulator?

[ed: ah, no. I see the first comment on the article is about this bug; it should return accumulator, not 1]

</comment><comment><USER33> Tail recursion is a bad idea in multicore land. You end up with a one sided tree structure that can't be parallel processed.

</comment><comment><USER16> Interesting use of exceptions.

<comment><USER34> Indeed although generally it's usually a bad idea to misappropriate the exception throwing / handling mechanism for other purposes, as it's probably be less well optimised, performance-wise, than other parts of a VM.

<comment><USER35> not in python. exceptions for flow control are not looked down upon unless it's gratuitous usage. many frameworks do exactly this.

<comment><USER36> Even the language itself does this: if a generator that is being processed by a for loop returns (rather than yield), the language will raise a StopIteration exception, which the for loop with catch and use as a signal that it should exit.

</comment></comment></comment></comment><comment> cup-of-tea This is the same as recur in Clojure. It's not general TCO, though, which is much more powerful.

I do think it's a shame that Python doesn't have general TCO. It's said to be unpythonic because it means there will be two ways to do things. But some things are so easily expressed as a recursion but require considerable thought to be turned into a loop.

<comment><USER32> > But some things are so easily expressed as a recursion but require > considerable thought to be turned into a loop.

Do you have some examples of problem+solutions where tco works fine (in a language with tco) - but the manual translation is hard(ish)?

I wonder in part after reading the Julia thread on tco - and difficulties with providing guarantees in the general case with tco:

[https://github.com/JuliaLang/julia/issues/4964](https://github.com/JuliaLang/julia/issues/4964)

<comment><USER37> Usually, I implement state machines with mutually tail recursive functions. Each function represents one state.

<comment><USER32> Right. The general rewrite would be a loop with a switch and state functions that returned a state? (i was going to say state functions that called back to a step function, but I guess that'd still build a call stack).</comment></comment></comment></comment>


On Disability and on Facebook? Uncle Sam Wants to Watch What You Post - <AUTHOR> https://www.nytimes.com/2019/03/10/us/politics/social-security-disability-trump-facebook.html <comment><USER2> State and local agencies already do this. One egregious local case: [https://www.mercurynews.com/2019/02/01/sheriff-lieutenant- ar...](https://www.mercurynews.com/2019/02/01/sheriff-lieutenant-arraigned- for-allegedly-bodybuilding-while-claiming-disability/)</comment>


Zuck denies Facebook News Feed bubble impacted the election - <AUTHOR> https://techcrunch.com/2016/11/10/zuck-denies-facebook-news-feed-bubble-impacted-the-election/ <comment><USER2> _"People are smart and they understand what's important to them," noted Zuckerberg._

Huge amounts of money are sunk into political advertising and propaganda, and have been for ages. Facebook is a great platform to spread those views. To dismiss this by saying "people are smart" is either disingenuous or betrays a lack of understanding of how the world works.</comment>


Is It Sunday Already? Seems Like Only Yesterday It Was Saturday - <AUTHOR> http://borasky-research.net/2010/09/26/is-it-sunday-already-seems-like-only-yesterday-it-was-saturday-2010-09-26-edition/

<comment><USER2> I like that there are perspectives that question the Silicon Valley approach to start-ups. Although of course there's definitely good to come out of it, there's also an extraordinary amount of ego and hype. Some might argue more than there is good.

I'd prefer to see people focus on building entrepreneurship in other cities, as well as experimenting with alternative forms of business structures (non- profits, cooperatives, etc), for those who are really adventurous.

There doesn't have to be a one-size-fits-all track for creating a new technology, and a diversified tech economy is a healthy one.

<comment><AUTHOR> I could buy that argument _if_ people in the Valley weren't so harsh to founders from other parts of the world and so adamant that the people there were "better" in some significant way than, say, my home town of PDX. I've heard a number of stories of businesses that were _told_ to move their HQ to Silicon Valley. That's a big part of why I wrote what I wrote - Angelgate was just the crowning example of arrogance and viciousness that seems to inhabit Silicon Valley.

</comment></comment><comment><USER3> _We've been treated to a post by Sarah Lacy blaming teachers' unions for the "Why Our Schools Suck"_

Granted, Lacy might not be the best person to listen to about this, but I have yet to hear a better explanation for why public schools can't seem to get their act together.

<comment><USER4> Every time I point out that educational outcomes in right to work states aren't any better than outcomes in states where teachers unions have collectively bargained contracts, I get downvoted. People just really want to believe that it's about the unions instead of poor pay, the entrance of talented women into the rest of the workforce, and other harder-to-solve-in-a- vacuum socioeconomic factors. But again: educational outcomes in right to work states aren't any better than outcomes in states where teachers unions have collectively bargained contracts.

34 states and DC have laws mandating collective bargaining with teachers. Now, it is true that in the other 16 states, there are other laws that can serve to protect teachers. But these states certainly have the ability to engage in ruthless combat with the unions, and they don't. I blame the voters and the legislators - unions exist to protect their members.

The best freely available overview of this problem I've found is here: <http://www.hks.harvard.edu/pepg/PDF/Papers/BetterBargain.pdf>

<comment><USER5> 18 days ago, I pointed out that there are teachers unions in right to work states. I also pointed out that right to work laws simply allow employees to work without joining the union. They do not prohibit unionization or collective bargaining.

<comment><USER4> Yes, that's how unionization works in the U.S. However, you've said nothing about educational outcomes, which is what I'm concerned with.

In addition, you're a bit off on the facts. There actually are three states that expressly prohibit collective bargaining with teachers unions: North Carolina, Texas, and Virginia. In a lot of these right-to-work states, the unions have been able to get work rules and the like codified in state law as opposed to within collective bargaining. Again, the PDF I linked to has a lot off good data and cites, and yes, it does comes down pretty harshly on the unions.

Look, I've been actively engaged on this subject for the last six years of my life. It's clear that I'll never convince you that simply eliminating public sector unions won't magically solve our education woes. But I can show you the facts that the circumstances that would allow for that to happen haven't happened.

<comment><USER6> So you're saying that in the states where the public teachers' unions haven't messed things up through collective bargaining, the generic public teachers' lobby has messed things up through legislation instead?

That seems a rather fine and mostly moot point.

If it's still public school teachers' interests and campaigning that torpedoes necessary reforms, then it doesn't matter if that's effected through a mandatory-membership union or collective bargaining or legislation.

The same interests need to be confronted in any case, and I don't know anyone who's suggested that "simply eliminating public sector unions" would "magically solve our education woes". There's no magic bullet, just a bunch of necessary reforms. And teacher's unions in both right-to-work and mandatory- union states oppose most of the necessary steps.

<comment><USER4> I think that's a fair characterization of my point in your first three paragraphs. There's just not a history of being able to take on the unions and "win", regardless of the labor laws. So let's stop trying to fight the unions and characterize them as devil spawn since that _isn't going to work_.

I'd rather focus on the areas where there aren't necessarily entrenched interests so we can focus on experimentation and trying to change the anti- education sentiment[1]. Schools like the KIPP Academies have exceptional outcomes over and over again. We need to find a way to get their techniques wider distribution.

I believe that fighting a war of words with the teachers unions is both a waste of time and counterproductive from a policy/results perspective. Public sector unions just aren't going anywhere. Furthermore, we're going to have a shortage of teachers - estimated to be as high as a million teachers [2] - once the Boomer generation retires. Demeaning the remaining teachers (who are generally union-affiliated) strikes me as ridiculously counterproductive. The experiences in NYC and DC are proof that there are ways to make teachers more accountable, reward better teachers, remove crappier teachers, and generally change the culture in our schools without taking tactical nukes to the NEA and AFT.

[1] Read Bissinger's Friday Night Lights for the best-written example of what I'm talking about.

[2] <http://www.nytimes.com/2009/04/07/education/07teacher.html>

</comment></comment></comment></comment></comment></comment><comment><USER7> It's unfortunate that the ethos of TechCrunch's reporting is founded on Arrigonton's bizarre disregard for sober, non-sensationalist journalism. It leads to wildly variant levels of quality in the posts, both in terms of objectivity and insight.

</comment><comment><USER8> The Valley has already created a positive feedback loop for attracting high quality VCs and entrepreneurs. Therefore, like those who go to LA to seek Silver Screen fame, SV will be hard to replace as THE place to be for tech startups.

With that said, ironically technology is draining the moat around SV and offering great opportunities to other world-class startup cities (e.g., NYC, Boston, Austin, Raleigh-Durham, etc.). In 50-100 years I expect these cities and a few more to have equal resources ala capital, technology, experienced operators, and top tier entrepreneurs.

IMHO, this is one of the ways the US will get its swagger back ;)

</comment><comment><USER9> SV is one of the only places on Earth where dreamers, hackers, and backers all gather to make big things happen. My only thing is, why not apply more of our joint efforts to solve critical survival problems for all human beings and our only home planet? It's already happening at some degree but, as evolving beings, we must keep raising the bar.

Maybe more people need to trip on LSD before starting up...

</comment><comment><USER10> A lot of good points are made in this article including the main one of doesn't this all serve Arrington's #1 interest (himself) in the end?

</comment><comment><USER11> Uh, what?

At least the Hitler video was funny.

<comment><AUTHOR> Well - maybe it was, but it was created by Kakigarden, not Techcrunch.

</comment></comment><comment><USER12> I had never read Techcrunch before "anglegate" was posted here, and I wont ever read it again. Never liked the reporting style.

<comment><USER13> I've you've never read Techcrunch before, how did you form an opinion about their reporting style?

<comment><USER12> Sorry worded that funny, I didn't mean never like absolute never. I did read a few posts early on and wasnt enthralled enough to continue, and so it felt like never as of last week.

You know never like formatting without zeroing out data? ;p

</comment></comment></comment><comment><USER14> Well then, head on over to Boston. The startup scene is hot here and it's a fun city.

<comment><AUTHOR> Funny you should mention Boston. Paul Graham used to say there were _three_ places to start a company - Cambridge / MIT / Harvard, Berkeley / UC Berkeley, and Palo Alto / Stanford. And he commuted between Boston and Silicon Valley.

Then he decided Boston was not a good place to raise a child and moved full- time to Silicon Valley. It's written up somewhere on his blog - I don't have the link handy. I don't know much about Boston these days, but in the early 1980s when I used to call on DSP folk with Floating Point Systems, it seemed vibrant. And the food was a _lot_ better than anything I've ever had in Silicon Valley. ;-)

</comment></comment><comment><USER15> It's thin reasoning.

Does Silicon Valley have dilettantes like Sarah Lacey? Sure. But these people are everywhere. Does it have figures whose estimation of their own importance is over-inflated? Absolutely. Again, they're everywhere. Can you find some events here that cost more than the value they'll provide to the median attendee? ... You get the pattern.

The thrust could have more profitably culminated in "TechCrunch is the last place I'd go for information on the Valley." This conclusion could be reasonably supported by the argument. I still wouldn't altogether buy it, but it wouldn't be crazy.

I'm just not sure you can write off an entire region because of the behavior of one publication.

As a Valley transplant, the value I see for founding a business here is tremendous: A huge pool of extraordinarily talented technical professionals. Bigger, perhaps, than anywhere else. It's about people. And it doesn't stop with having fellow hackers. You'll discover investors, of course, plus a lot of senior people who can give you good advice from their hard-won experience.

There are people who annoy you in the Valley - big deal. Speaking from experience, I'd rather have bickering neighbors like Arrington, Dave McClure and Ron Conway instead of, for example, the kind of people who cherish a certain skin color, superstition, and pickup trucks.

For me, it's a culture thing. And it's priceless.

<comment><USER16> It's beyond thin.

Every VC environment has loud personalities and personal conflict between various groups. Whether it's the Valley or Chicago you're going to have these types of stories. So to condemn the valley based on those stories getting more press is silly. It shows the author lives in a bubble and has never experienced what it's like to really raise money in such an environment.

Worse though is how high this got. The fact that this made it to #1 on HN actually makes me a little queasy. I don't tend to pay attention to all the HN is degrading talk but this makes me wonder</comment></comment>


Not intending to come back to life - <AUTHOR> While i may still be alive,
i committed career suicide 100x over
and don't intend to come back to life <comment><USER2> Haiku or cry for help? Lots of people reinvent themselves and it's ok to pivot</comment>


Ask HN: Startup funding from Dubai? - <AUTHOR>

I'm wondering if anyone here has experience with startup funding - especially early stage - from Dubai? <comment><USER2> My startup just got unsolicited offer from Dubai. Seemed suspect.</comment>


Fear of Rejection when Applying to Y Combinator - <AUTHOR> https://www.hireart.com/blog/fear-of-rejection-when-applying-to-y-combinator/ <comment><USER3> I think there's something to be said for trying to develop a fear of not failing. It's a little counterintuitive, but simple enough - if you're not failing at all, you're usually not pushing far enough or risking enough. Hard to make a mark if that's the case. A little daily practice can help - <USER2> yourself: have I failed today? Did I give myself a chance to fail by taking a risk on something today? If too many days go by without a failure it may be time to re-evaluate your overall approach and the way you look at risk.

</comment><comment><USER4> The way you mentally frame rejection is important. I found Rejection Therapy [1] to be effective at rewiring the brain's perception of rejection and not be attached to the outcome.

[1][http://rejectiontherapy.com](http://rejectiontherapy.com)

</comment><comment><USER5> My thinking on this kind of thing is that it's the gatekeeper's job to filter you out, not yours. Don't do it for them.

<comment><USER6> I run into this attitude many times when helping people with negotiation. Where they are so psyched out they don't even want to attempt to ask for something. "They will never accept that". To that I say "don't do the negotiating for someone else that's there job.."

</comment></comment><comment><USER6> It totally amazes me how brainwashing things like this are to young founders and entrepreneurs on HN.

It sends a message that getting into YC is way to important to miss and if you don't get accepted you stand little chance of getting anywhere on the startup scene. Or in life.

I can't imagine this is the spirit that PG and now Sam Altman are interested in portraying.

YC came about in 2005. There were companies that were formed prior to that that have been hugely successful. And there have been companies formed after that that have been successful. Not to mention a whole lot of lifestyle businesses. There are also many other incubators, mentors, investors, angels etc.

I think it's really dangerous to get all worked up as if not getting into YC is pivotal in a non correctable way.

That said I understand the anxiety. But I don't think things like this really help because they reinforce the implied importance more than anything else.

<comment><USER7> Hi, Thanks for pointing this out. I should probably include something in here that clearly states: Getting into YC won't make you successful or vice versa.

No, it doesn't matter that much whether you get in, but people still care a lot and my point was simply to say: It's great to care, but don't let that fear paralyze you. Just apply and be a bit zen about the outcome either way.

<comment><USER6> Well in case I wasn't clear let me restate my point.

I think it's great and obviously a huge benefit to get into YC, Harvard, Wharton, or get funded by a top tier VC all of that. Or to marry a beautiful women, handsome man, someone with money, be an NBA or sports athlete you know all of that.

What to me is bad is reinforcement of something that makes people feel as if they are failures and "can't cut the mustard" if they don't get in (or achieve something).

I don't know if that is even avoidable but wanted to point it out. It kind of smacks of "penis" envy and/or keeping up with the joneses.

For the record though:

"Getting into YC won't make you successful "

Getting into YC or past any filter is for sure a big benefit. No doubt about that.

"it doesn't matter that much whether you get in"

It does matter if you get in. Of course it does.

I am acknowledging that in response to you. But I wouldn't write a blog post saying that because I feel it reinforces a stereotype of halo that I don't think is helpful. And perhaps becomes a self fulfilling prophecy as well.

</comment></comment></comment><comment><USER8> First step to mastery: make it safe to fail, in order to take risks over and over!

Being rejected by YC is completely safe!

</comment><comment><USER9> Didn't notice an author name on the blog post. I think you should and will get rejected many many times early on, and for us I believe it helped us get in to YC because rejection hardened the team and refined the pitch.

<comment><USER7> Hey, this is Elli from HireArt. I'm the author of the piece. Agreed that rejection actually helps you get closer to your team and figure out what you're really building

</comment></comment><comment><USER10> The wartime CEO lets the war define the culture. —Ben Horowitz

part of the war waged when running a startup is rejection: repeated, horrifying, relentless. there is no peace and the arrows fly. you can't always control your immediate response but you _can_ train yourself to be braced for it, inured to it when it comes. eventually, with a lot of hard mental conditioning, you can find and appreciate the benefits of being rejected (fortitude, resilience, grim determination).

getting into YC is one of many paths to winning that war when you're ready. just turns out to be the most effective i can think of.

</comment><comment><USER11> We just applied for the next YC batch. This post is perfectly on point with our feelings at times through the process. Going into it, the fear of being rejected was almost paralyzing but we pushed through and got it in. It was a good exercise for our team regardless of the outcome.

</comment><comment><USER12> Your offer of help for founders applying to YC is great - thanks very much. I'm going to drop you a mail to take you up on the offer :-)</comment>


The Big Lie About the 'Life of the Mind' - <AUTHOR> http://chronicle.com/article/The-Big-Lie-About-the-Life-of/63937/?sid=pm&utm_source=pm&utm_medium=en

<comment><USER2> These articles are awesome.

I'm always fascinated by why people seem to think that studying the humanities is living the 'life of the mind', as opposed to hard sciences or engineering; fields which provide more robust means of testing the conclusions one has arrived at through mental effort.

<comment><USER3> The author's objection to graduate school in the humanities has less to do with a lack of intellectual rigor than with the structure of the job market in that part of the academy.

So I think your comment is somewhat misleading in connecting this article (or "these articles") to your own criticism. (Which criticism may of course be valid on its own terms.)

<comment><USER4> I didn't read philk's comment as a criticism. I think it was a sidebar comment triggered by the OP's almost offhand reference to "life of mind"

I don't see where philk "connected" his own comment with any of the arguments made in the OP. It's just something he added.

</comment></comment></comment><comment><USER5> Compare Adam Smith's analysis in Wealth of Nations:

"The time and study, the genius, knowledge, and application requisite to qualify an eminent teacher of the sciences, are at least equal to what is necessary for the greatest practitioners in law and physic. But the usual reward of the eminent teacher bears no proportion to that of the lawyer or physician; because the trade of the one is crowded with indigent people who have been brought up to it at the public expence; whereas those of the other two are incumbered with very few who have not been educated at their own." - <http://www.econlib.org/library/Smith/smWN4.html#I.10.94>

<comment><USER6> It's somewhat the opposite here. In fields like Computer Science there's _more_ money available to pay for your education - it's typical to leave grad school without any debt, I think - than in the Humanities, where as the author pointed out it's typical to leave with huge student loan debt (which is undischargeable by bankruptcy, btw). I guess you could say that there are some fields like CS that can act as professional degrees even though they aren't officially so.

And maybe it wasn't like this is Adam Smith's time, but today a large majority of working law school grads aren't working as lawyers.

I think you're right - high tuition bills do make people think long and hard about going back to school. It's just that 22 year olds aren't so easily deterred from disastrous choices.

</comment></comment><comment><USER7> Have people not yet figured out that most degrees in the humanities are often not all that marketable? I thought the writing was on the wall 10 years ago. Even then far more people were entering these studies then there would ever be positions. It seems to have only gotten worse.

</comment><comment><USER8> If you want to know more about the problems with the structure of academia (as well as how it came to be), see Louis Menand's The Marketplace of Ideas: [http://jseliger.com/2010/01/21/problems-in-the-academy- louis...](http://jseliger.com/2010/01/21/problems-in-the-academy-louis- menands-the-marketplace-of-ideas-reform-and-resistance-in-the-american- university) , which I write about at the link.

</comment><comment><USER9> Here's some useful overview stats from Department of Education, but we need a breakdown of science and non-science. My gut wonders if these might not be borrowed data from the Bureau of Labor Statistics. Edit: here's the link: <http://nces.ed.gov/programs/digest/d08/tables_1.asp>

Oh, and here's some more granular data on the science enrollment side of things: <http://www.nsf.gov/statistics/nsf08306/>

anybody know how some open source datasets to start pulling the information apart?</comment>


Writing Performant Scala  - <AUTHOR> http://www.sumologic.com/blog/technology/3-tips-for-writing-performant-scala

<comment><USER2> Under what circumstances are you okay with giving up 3x performance? I find the while-loop code ("Version 2") as readable and idiomatic as the one using count(). If you can write fast Scala code (and you've already shown that you can), why not do it? Have you measured how much readability is impacted by slightly more verbose (or C-like) patterns?

Also, hi Russell!

<comment><USER3> In real production code, things like this are rarely bottlenecks. The count version, frankly, is less error prone. There are a few different ways that you can easily mess up the while loop version. In places where a loop like this really is the bottleneck we'll drop in the C-style version.

In general though, we find the code just kind of balloons if you use patterns like this everywhere.

<comment><USER4> I have to agree with mrdmnd here.

I know the old saying about premature optimization, but avoiding premature optimization doesn't mean actively choosing slower code. It just seems like sloppy programming, IMO.

<comment><USER5> Concise, readable code should trump performance concerns in cases where performance doesn't matter. The idiomatic version is much shorter and clearer.

</comment></comment></comment></comment><comment><USER6> Its does annoy me that lazy evaluation is not the default like it is in Haskell for much of the collections classes, but Once you figure out its there, man does it make things faster.

</comment><comment><USER7> The fact that it takes so much intimate knowledge of how the collections are implemented to get some decent performances in Scala is probably one of the many reasons why this language hasn't taken off.

<comment><USER8> I agree in principle that one shouldn't _have to_ understand the implementation of collections to use them effectively, but these limitations are by no means exclusive to Scala. Haskell's lists, difference lists and seqs work exactly the same way as Scala's list collections. Iteratively concatenating strings in Python will murder your performance. Most (all?) sufficiently complex systems involve tradeoffs.

<comment><USER9> > Iteratively concatenating strings in Python will murder your performance.

Understanding immutable strings aren't at the same level. People concatenate immutable strings all the time in Java/Python, but that is despite the documentation mentioning immutability and proper concatenation method(StringBuffer followed by toString, list.append() followed by " ".join(list))

<comment><USER8> > despite the documentation mentioning immutability and proper concatenation > method

What-do-you-know, Scala has documentation too[1]! And it mentions that appending to a List is O(n).

[1] [http://www.scala- lang.org/api/current/scala/collection/immut...](http://www.scala- lang.org/api/current/scala/collection/immutable/List.html)

</comment></comment></comment></comment><comment><USER10> Remember folks : "performant" is not a word.

<http://boulter.com/blog/2004/08/19/performant-is-not-a-word/>

<comment><USER11> "performant" may become legitimate soon, but it seems destined to be another tech buzz/weasel word.

</comment></comment><comment><USER12> So basically the recommendations boil down to "pretend youre using Haskell a work" :-)</comment>


Running Apache On A Memory-Constrained VPS - <AUTHOR> http://www.kalzumeus.com/2010/06/19/running-apache-on-a-memory-constrained-vps/

<comment><USER2> A lot of the math in this is a little... strange. For instance:

"20 * 60 * 5 = 60k satisfied clients a minute"

Hmm, that's a lot closer to 6k in my mind :-)

Also:

"The throughput of the server went from about 60k requests per second to about 380 requests per second"

The original (incorrect) calculation supposedly took place at 60k per minute, not per second.

Not trying to be a stickler for accuracy, but I feel like it matters when dealing with benchmarks.

</comment><comment><USER3> I swear we covered this recently. Oh here it is.

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

Different source but same concepts, I'll repeat what I said then.

Takes more than 5 minutes but worth the effort: replace Apache.

Nginx, Lighttpd, Cherokee, Zeus, LiteSpeed, etc. All use far fewer resources.

<comment><USER4> To give some factual support to the parent's argument: I run lighttpd+fcgi- lua+redis comfortably on a 128M VPS, which according to my benchmarks is capable of serving between 200 and 400 requests per second on the dynamic page. With about half of the RAM free, still.

</comment></comment><comment><USER5> You can also install nginx with apache running on reverse proxy.

<http://aruljohn.com/info/nginx/>

<comment><USER6> A couple of years ago, I would have said "That's wonderful advice because Nginx excels at serving static files and Apache is needed for the dynamic requests", but today only one of these is still true. The technique will certainly still work, though.

If I ever get a few hours to install Nginx and write config files for a few dozen PHP sites (blarg), I'm going to get rid of Apache altogether.

<comment><USER7> Why is it so hard to break nginx vs apache? What's the core difference?

<comment><USER8> Core difference: the request processing model. Nginx uses the "hot new" event- loop model. It's a good model, but I find that most people overstate the performance difference and resource usage.

The bigger problem is that Apache comes configured "out of the box" on most distros with a whole slew of options that you probably don't need. Even having said that, most people _think_ that Apache is using more resources than it is. They see all these processes floating around in `top` and they freak out. See my post in the other thread (linked in parent) for more info on that.

Most of the concern is driven by ignorance rather than deep understanding. I can feel the searing burn of Nginx fans' glare, so let me qualify that. YES, Nginx is a fantastic web server. YES, pound-for-pound, it is more resource efficient than Apache. The catch is, if you trim Apache down to do only what you need, the margin between it and Nginx becomes much smaller. If you really know Apache well, then you don't necessarily need to switch to Nginx, just because it's hot and new.

If you don't know Apache well enough to scale it, or if you're really, really tight on resources (you can't afford a 10% bump in VPS RAM), then you should probably learn Nginx straight away, because it's a fantastic web server. Hell, every Apache admin ought to learn Nginx, because you will no doubt learn something in the process.

<comment><USER9> > _The catch is, if you trim Apache down to do only what you need, the margin > between it and Nginx becomes much smaller. If you really know Apache well, > then you don't necessarily need to switch to Nginx, just because it's hot > and new._

Care to elaborate? I used to do that few years ago for static serving, from tuning Min/MaxSpareServers, measuring resource usage and speed of worker/prefork MPMs to strip out all modules to bare minimum and I still can't get the margin between Nginx and Apache to be any close.

<comment><USER10> How are you measuring resource consumption? Memory consumption often includes _a lot_ of shared virtual memory, where multiple Apache threads/processes simultaneously use the same physical memory.

<comment><USER9> Resident size. Normally ps -o rss,ucomm</comment></comment></comment></comment></comment></comment></comment>


What you should learn from the man who lost $600,000 on Facebook ads - <AUTHOR> http://adespresso.com/academy/blog/what-you-should-learn-from-the-man-who-lost-600000-on-facebook-ads/ <comment><USER2> It's a women's fashion publication. By the age of the models they use, their target market is girls age 15-25. (As opposed to tabloids or mags targeting an older range of women, see [http://www.zoomermag.com/](http://www.zoomermag.com/)). Given that target market I can see why facebook might have been appealing ... ten years ago.

The young are walking away from facebook, women in particular. Most walked the day their grandparents and highschool teachers joined. But young women are really walking away these days because they find any picture of them on facebook is quickly harvested for use by some shady dating website. As one student expressed it to me, facebook has a "serious creep factor". So nobody should be surprised that a fashion mag lost money on facebook ads.

I'd suggest which form of social media is better for this market, but as I am not a teenager whatever I say will just make me look old and out of touch.

<comment><USER3> You're talking like you have some special insight, yet all I'm finding are poorly reasoned anecdotes. For one, I have never met a single individual whose photo was actually harvested. Have you? For another, I cannot think of one sub-25 female friend who is not on Facebook. As for your comment how their activity is not conducive to advertising, show me some proof.

The actual problem here is spending $600k in four days. Full stop. You, or this article can try to intellectualize that as much as you want. But fundamentally, advertising does not work like that. If you spent $600k on four days of television commercials, billboards, mascots, etc., the odds are overwhelmingly in favour of your failure.

The only solution is to treat advertising as an engineering discipline.

<comment><USER2> "Shady promotion, sex trafficking, and data mining are just some of the tricks of the trade for Facebook's growing population of fakers"

[http://www.dailytech.com/Fakebook+Pt+I+From+The+Chive+to+Ask...](http://www.dailytech.com/Fakebook+Pt+I+From+The+Chive+to+AskMen+How+Facebooks+Phonies+are+Born+and+Used/article37488c.htm)

On dating websites' use of stolen images:

" He said: "We'd steal someone's identity through say My Space or something, we'd take someone from a totally different country, ie. Spain or wherever it may be. [...] We'd take the person's photos online and we'd start knocking out messages. It was all fake and under the pretence that it was real."

[http://www.telegraph.co.uk/news/uknews/law-and- order/1020771...](http://www.telegraph.co.uk/news/uknews/law-and- order/10207712/Online-dating-sites-use-stolen-data-to-create-fake-profiles-it- is-alleged.html)

And yes, I have met people who have had their profile pics used elsewhere. TinEye is a great tool for discovering such incidents. Then again I used to work in the entertainment industry (film) and now teach a forensics class to young people at a local college so I probably run into it more often than the average.

<comment><USER3> It's good that you could find me articles about fake Facebook accounts and how some dating websites contain fake profiles. But, I know both of those things already.

Instead, you made a claim that Facebook was a poor choice of medium because women aged 18-25 are walking away from the service in droves. You said they were walking away because:

 _But young women are really walking away these days because they find any picture of them on facebook is quickly harvested for use by some shady dating website. As one student expressed it to me, facebook has a "serious creep factor". So nobody should be surprised that a fashion mag lost money on facebook ads._

A statement like that needs some proof. If you have any, I would love to read it, but until then, I'll argue that Facebook has an immense amount of data and extremely fine-grained targeting options. Therefore, if you plan and monitor an intelligent campaign, it remains a decent advertising medium.

</comment></comment></comment></comment><comment><USER4> The real problem is that facebook fans are useless, because even if you have them, 95% of them still won't see your posts unless you pay to boost them. Fans are effectively an illusion.

</comment><comment><USER5> The original article this is based on, if you want more info: [http://www.businessinsider.com/mans-600000-facebook-ad- disas...](http://www.businessinsider.com/mans-600000-facebook-ad- disaster-2014-2)

</comment><comment><USER6> Is this an ad or an article? It's Both! Extremely well done job of blurring the line between the two while keeping things compelling. Kudos to you, Adespresso.

<comment><USER7> Lol ... it's Content Marketing :)

</comment></comment><comment><USER8> Hmm, so instead of Facebook Ad we should create click-bait articles as a form of free advertising. Thanks.</comment>


Share buybacks are what happen when you run out of ideas. Financial engineering  - <AUTHOR> https://twitter.com/garrytan/status/431709411560521728

<comment><USER2> Damn straight. Look here: "Apple's [Tim] Cook told [Carl] Icahn that he's still studying Icahn's proposal to buy back $150 billion worth of the company's stock." Source: [http://www.cnbc.com/id/101151952](http://www.cnbc.com/id/101151952) (Monday, 11 Nov 2013)

Apple makes about $60B/yr in profit. Ichan wants Cook to borrow $150B to buyback Apple shares. Icahn and Cook would be the main beneficiaries of this plan.

I've seen this many times in non-tech firms. Look at Borders book store. They did several rounds of this over decades to boost their stock price. Each round, enriching the officers and board members, and piling the company up with loads of debt. E.g., November 27, 1996. "Borders Group Inc., the retailer of books and music, said today that it would buy back up to $50 million of its common stock." [http://www.nytimes.com/1996/11/27/business/borders-in- stock-...](http://www.nytimes.com/1996/11/27/business/borders-in-stock- buyback.html)

Eventually, they couldn't service their debts and they went bankrupt. The officers and board members couldn't care less. They got rich. Their employees and customers got screwed. Their creditors took everything including the pension fund. Some commentary here: [http://www.datalounge.com/cgi- bin/iowa/ajax.html?t=11235835#...](http://www.datalounge.com/cgi- bin/iowa/ajax.html?t=11235835#page:showThread,11235835)

The moral of the story: Corporate raiders and vulture capitalists could care less about anybody but themselves. They'll gladly drive _successful_ businesses into bankruptcy to make a lousy buck. Along the way, they make the employees suffer. And they reduce competition in the market place and hurt consumers. And we make it easy for them as a society by pretending this is how capitalism is supposed to work. Shame on them; shame on us too.

<comment><USER3> How do they get rich off the buy backs? Explain like I'm five. Do all the Joe Schmoes who own the common stock as art of their 401k's benefit from it as well?

<comment><USER4> They are removing the number of shares on the open markets, so it's a 'less to go around' type sitation, or you can think of it as limiting supply.

In theory (I believe), the market cap for the company should stay the same, so each share increases in value. Cook and Icahn are major share holders, so they would be increasing their value.

However, it isn't a zero-sum game (hope I'm using that correctly) as in the short term, with rising stock price, all investors win.

On the flip side, the money used for a buy-back is money not invested into R&D, which for a tech company is obviously very important.

Though, I wonder if Apple may be a bit of an anomaly. They have such a huge profit margin, and strong following, and a group of customers who will buy pretty much anything they release at pretty much any (moderately unreasonable) price.

Apple doesn't spend (and loose) on R&D like Google and Microsoft do. There doesn't appear to be anything in the Apple quiver which came as a result of massive R&D effort. Massive design effort, absolutely. Massive engineering effort, sure. But straight R&D? I don't think so. Happy to be proven wrong though.</comment></comment></comment>