
John Carmack on Functional Programming (2013) [video] - tosh
https://www.youtube.com/watch?v=1PhArSujR_A
======
JohnCarmack
I am aware that my presentations aren't optimal for communicating targeted
information, and it does weigh on me more and more as the years go by.

So far, I haven't been able to justify to myself the time required to do a
really professional job, so I just show up and talk for a few hours. I like to
think there is some value in the spontaneity and unscripted nature, but I
don't kid myself about it being the most effective way to communicate
important information.

I'm taking some baby steps -- I at least made a rough outline to guide my
talking at last year's Oculus Connect instead of being in full ramble mode.

~~~
dgritsko
While this may be true, please don't let it cause you to shy away from "full
ramble mode" when the opportunity presents itself! I know I speak for many
when I say that I have learned much from hearing these sorts of talks of yours
over the years. Your willingness to share your wealth of experience is
inspirational, regardless of the format.

~~~
bluejellybean
Agreed, full ramble isn't something many people do well and it's fun too
watch. Random but useful information will fall out of peoples brain and it's
great!

------
cthulhujr
I really like John's perspective on things, he can take a listener or reader
from the most abstract concepts to the nitty-gritty without losing focus. He's
a tremendous asset to the programming world.

~~~
ksk
I agree with the second part of your sentence. I have watched every single one
of his talks, and while I find them entertaining, I don't think his brain-dump
style of communication is appropriate for teaching/instruction (to clarify: I
use his talks as a springboard for my own discovery, not as a terminal point
to aggregate knowledge).

~~~
waivek
[https://youtu.be/lHLpKzUxjGk](https://youtu.be/lHLpKzUxjGk)

I disagree. See the above link for a lecture where he describes the
difficulties in VR in a manner that anybody with minimal programming
experience can understand.

------
pmarreck
He wrote a very good piece here:
[http://www.gamasutra.com/view/news/169296/Indepth_Functional...](http://www.gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php)
on the same topic (is it in fact the same?)

~~~
seanalltogether
I come back to this quote over and over when talking about desktop and mobile
apps/games, especially since they tend to be highly state driven view
collections and devs are always trying to come up with DRY patterns to bury
important features in subclasses or helper utils.

> A large fraction of the flaws in software development are due to programmers
> not fully understanding all the possible states their code may execute in.

~~~
pmarreck
This is also simultaneously a strong argument for unit tests (which encode
knowledge of that state into a proof of sorts).

The limit of a programmer is his/her brain's ability to contain all these
possible states. Bugs always come from missing some mental modeling of state
or having a flawed conception of it, either at the point of design, the
version 1, or the rewrite.

OO just buries that state "elsewhere", so things _seem_ easier superficially
to contain mentally (but the state is still there, ready to get corrupted and
pounce on you). FP makes the state explicit, so you're forced to deal with it
at all times (this perhaps not uncoincidentally also makes FP easier to unit-
test AND reason about). If managing that state upfront becomes unwieldy, then
that becomes a good code smell/indicator that your design is suboptimal.

The upshot of all this is that _I think_ that using FP in conjunction with
unit-testing reduces bug production by some statistically-significant amount,
especially as a codebase grows. We definitely need more empirical data about
this, though. But that's what my intuition says.

~~~
grogenaut
one of the hard things about game dev and testing is that there are all sorts
of bits of code that don't really have strong "success criteria". A lot of it
comes down to "did that feel good" or "does that look better" which is very
hard to quantify in unit tests.

However I think there's also a huge swath of code in games that can be unit
tested. Scorekeeping systems, ai evaluation trees, etc. The industry as a
whole has much more of an integration or manual testing bent focus than a unit
testing one.

I will say that coming from a no tester all dev unit / integration test world
to no automated test, 30-120 high skill manual tester world (30 gameplay
testers, every other employee using new builds 2x daily), there is definitely
something to having lots of really good manual testers with very short
feedback loops. People noticed bugs that were hard to test for within 10-15
minutes of checkin on a regular basis.

Really if I did a studio I'd have both but then I'd likely be spending too
much money and go out of business.

~~~
lallysingh
Why would unit testing cost extra? It saves money.

~~~
lgas
Like most technical work, it saves money when done well and costs money when
done poorly. Most people find themselves somewhere in the middle most of the
time so it turns out the discussion is a little more nuanced than that.

~~~
grogenaut
Exactly! But it's so much easier to be an unyielding zealot than to think and
understand why and if something is working.

As I said above I'm a big advocate of tdd... Do it all the time. So when I say
I wouldn't do it for parts of games maybe I have a reason (to gp not you)

------
jandrese
Interesting that he ran into friction exactly where you would expect him to.

He was talking about having the AI scripts running in different purely
functional threads. Later (around 21 minutes in) he mentions what happens when
two AIs decide to move to the same place at the same time, and has not figured
out the solution.

Of course parallel programming is easy if you ignore the data dependencies,
but eventually you run into unavoidable dependencies and your clean elegant
system has to pick up some smell.

~~~
ece
He talked about a whole FP-powered architecture to solve this.

~~~
sololipsist
Motivated reasoning. He prefers imperative programming (or something other
than functional programming), so he hears the "criticism" without hearing the
solution. I mean, of course he physically hears both, but one is prominent in
his consciousness. It doesn't matter that there is a solution, he heard what
he needed to hear to get the evidence he needs to maintain his bias, and shuts
off his frontal lobe.

To be clear: Everyone does this. I just think it's interesting.

~~~
scott_s
I think you misunderstand Carmack's position. As of this talk, he had not yet
solved this problem, but he is optimistic that it can be solved, and ece
mentioned the solutions he outlines. He goes on to say such a system would be
beneficial to all game developers.

~~~
sololipsist
He says it's a problem that can be tackled, it just hasn't been yet. Like you
look at a square block, and you need to get it in a square hole, you just
haven't gotten to it.

It's not the language of someone that isn't confident that there isn't a
perfectly fine solution. I mean, it's likely that other people have already
figured this out, just not him.

------
babuskov
It actually starts here:
[https://youtu.be/1PhArSujR_A?t=2m7s](https://youtu.be/1PhArSujR_A?t=2m7s)

------
ballpark
Should add (2013) and [video] to the title

------
zerr
I guess we all had that FP click at some point in our lives, but then we got
back to our regular (imperative) flow, hopefully as better engineers :)

~~~
yogthos
I got that FP click, switch to Clojure, and pretty happy with that move 7
years later. :)

------
ece
I wonder about the present state of the functional projects he talks about and
is currently working on. A bit old, but good video talking about FP and static
typing from a veteran perspective.

Would like to see a conversation between Sid Meier and Carmack, the modern Civ
engines seem to have made some strides in stability methinks.

------
vog
While he says a lot of interesting things, it is too bad he is really just
sitting and talking. No slides, gestures or any other facilities. Those would
have brought more structure into the talk, making it easier to follow -
especially for non-native speakers.

~~~
epigramx
Or more distracting and annoying.

------
zengid
The thing that's interesting about Haskell is that lazyness had a payoff of
leading to the discovery of monad-based IO [1].

[1]
[https://youtu.be/re96UgMk6GQ?t=31m22s](https://youtu.be/re96UgMk6GQ?t=31m22s)

------
bmc7505
Has there been any progress on garbage collection since then? He discusses GC
in games starting here:
[https://youtu.be/1PhArSujR_A?t=1443](https://youtu.be/1PhArSujR_A?t=1443)

------
keymone
this is a best video to explain to your C++ friend why functional programming
is worth it even in gamedev world.

~~~
pjmlp
C++ has been getting functional programming goodies since C++11.

Nowadays with C++17, functional programming in C++ is a common talk subject at
C++ conferences.

~~~
keymone
that's nice, but generally speaking the mindset is still very much imperative.

~~~
pjmlp
Well, it is still a huge fight to get many devs to stop writing "C with C++
compiler" style anyway.

The C++ community that cares about C++Now, CppCon, ACCU kind of material, does
care about applying functional programming ideas to their daily coding.

~~~
f00_
is it bad that I prefer C to all the shit in C++?

Now I don't even write C/C++ regularly, so my opinion is probably shit. But I
really like the simplicity of C over all the features of C++.

~~~
pjmlp
What is so simple about more than 200 documented cases of UB and all the ways
one can write unsafe code without even knowing about it?

C++ has stronger type safety, offers the libraries and language features to
only go down to C like unsafe coding as last resort.

------
vog
EDIT: Why all those downvotes? Are famous developers not supposed to
criticized on HN?

While John has a lot of interesting things to say, the presentation is awful,
almost an imposition to the audience.

There's not a single slide, or any repetition to clarify structure, or any
notable gestures to make up for that. A simple overview, just a damn simple
list of keywords, would already go a long way. That would add a lot of
structure and would make the talk so much easier to follow, especially for
non-native speakers.

Just because one is so much respected by the audience that they will tolerate
everything, one should not act like the audience will tolerate everything.

~~~
Kiro
I downvoted you because:

1\. You state your criticism like it's an objective fact. I think it was a
brilliant talk.

2\. Your edit. It violates the HN guidelines and you insinuate people only
downvote you because they are Carmack fans.

~~~
optimusclimb
> You state your criticism like it's an objective fact, when in reality I'm
> sure most would disagree with you.

He stated his opinion, it's how people discuss things. Ironically, by saying
"in reality, I'm sure most would disagree with you", you do the same thing
(express your opinion as if it is fact), AND use the weasel words of "in
reality" to add gravitas to your opinion. I didn't like the talk either FWIW.

