Live data from Hacker News

John Carmack on Functional Programming (2013) [video]

youtube.com

71–80 of 90 posts

Re: John Carmack on Functional Programming (2013) [video]

#71
post #43

Earlier quoted context omitted.

But one actor can always read the state of the other actor, and modify their actions accordingly. The state of each actor is immutable, so each action taken based on the state is sure to be conflict free. As opposed to imperative programming, were each actors position might not get updated correctly or in time until too late. Deadlock and starvation don't happen when you have pure functions with no side effects and i…

If two actors moved to one spot at the same time which actor occupies that spot? How can an actor act accordingly if they moved at the same time? In functional programming this can happen... in imperative programming it NEVER happens, because the actors move imperatively, aka step by step or one at a time. This is the problem he is talking about.

FP is not gonna wall you off from doing stuff like this. For example, and this is just off the top of my head, you could:

* provide an explicit sequencing of when actors take their turns, passing updated resources to each in turn. This is your "step by step" imperative approach, and you're basically writing a main game loop. * don't sequence the actors, but implement a lock on the resource using a TVar. This is the simplest async approach. * many more approaches I haven't thought of

The point of FP is to be provide as much information about the logic of the program as possible. If two actors can move to the same point at the same time, then you need to write down logic to handle that case, whether actors move in sequence or independently.

Not writing down that logic because "I have an imperative language" is how you get bugs, especially race conditions.

Re: John Carmack on Functional Programming (2013) [video]

#72
post #68

Earlier quoted context omitted.

If two actors moved to one spot at the same time which actor occupies that spot? How can an actor act accordingly if they moved at the same time? In functional programming this can happen... in imperative programming it NEVER happens, because the actors move imperatively, aka step by step or one at a time. This is the problem he is talking about.

It can only never happen if you use a lock correctly. In separate threads, this can absolutely happen in imperative programming. As a reader-writer or dining philosopher problem will show, two actors can try to do the same thing at the same time unless you EXPLICITLY stop them by using locks. In FP, you will have an immutable variable for state instead of a mutable variable wrapped in a lock. You will be passing a wh…

I don't think the latter point is true. FP requires a lot of thinking up front, which is not how most engineers like to work.

That's not to say that FP is at odds with iterative programming, but it means that you have to work out a "specification" of your code pretty completely from the beginning.

Although, even then it's not so bad because the excellent type systems and compilers mean you can develop the specification interactively (see Idris' typed holes).

Re: John Carmack on Functional Programming (2013) [video]

#73
post #17

Earlier quoted context omitted.

You can train yourself to recognize this pattern in your own behavior.

Mhm. I try to. Why? Are you implying I prefer functional programming? I don't. I don't have a horse in this race.

No, I was commenting on statement, "everyone does this". What I was trying to say is that with effort, you can begin to identify times when you are biased toward a certain thing (in this case, different programming styles), and consciously choose to leave your emotions out of the equation.

Re: John Carmack on Functional Programming (2013) [video]

#74

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 effec…

Really interested in hearing if the ideas on how to transform game programming into a more productive form panned out. Did you end up using the ideas in a later product?

Re: John Carmack on Functional Programming (2013) [video]

#75
post #72
post #68

Earlier quoted context omitted.

It can only never happen if you use a lock correctly. In separate threads, this can absolutely happen in imperative programming. As a reader-writer or dining philosopher problem will show, two actors can try to do the same thing at the same time unless you EXPLICITLY stop them by using locks. In FP, you will have an immutable variable for state instead of a mutable variable wrapped in a lock. You will be passing a wh…

I don't think the latter point is true. FP requires a lot of thinking up front, which is not how most engineers like to work. That's not to say that FP is at odds with iterative programming, but it means that you have to work out a "specification" of your code pretty completely from the beginning. Although, even then it's not so bad because the excellent type systems and compilers mean you can develop the specificati…

Which part? I think even John Carmack in the video talked about the upfront thinking required for FP. If every CS student learned category and type theory like they learn complexity theory; and FP compilers could optimize type classes and all the object creation, FP would definitely be more widely used. But, yes, there is definitely a cost to picking up FP today in almost any domain, but it's getting lower.

Re: John Carmack on Functional Programming (2013) [video]

#76

Earlier quoted context omitted.

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 exec…

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 thing…

[deleted]

Re: John Carmack on Functional Programming (2013) [video]

#77

Earlier quoted context omitted.

It's not about either. He is illustrating a problem that only occurs in functional programming: There is no concept of time in pure functions. In imperative programming when two actors approach the same spot, whether the application is parallel or not, one actor ALWAYS arrives first and the other will arrive subsequently. Therefore the Second actor can read the state of the first and act accordingly... This is not th…

> There is no concept of time in pure functions. Very true, but there is a fundamental concept of time, almost by definition, in game-worlds. Whereas in imperative programming it's true that one actor always arrives first in computation, he might not have arrived first "in the game": conflict resolution is still a necessity. As such I don't think this is a problem that only occurs in functional programming. It's my i…

Correct. But when things arrive at the same time and the same place "in game" the imperative programming style resolves this automatically by giving precedence to the object that was computed first, thus this problem is handled automagically in the imperative world. In fact you probably don't even have to really think about this issue when using the imperative style, unlike the functional style where this issue must be explicitly dealt with.

FYI I'm not saying either paradigm is worse or better, it is what it is.

Re: John Carmack on Functional Programming (2013) [video]

#78
post #71

Earlier quoted context omitted.

If two actors moved to one spot at the same time which actor occupies that spot? How can an actor act accordingly if they moved at the same time? In functional programming this can happen... in imperative programming it NEVER happens, because the actors move imperatively, aka step by step or one at a time. This is the problem he is talking about.

FP is not gonna wall you off from doing stuff like this. For example, and this is just off the top of my head, you could: * provide an explicit sequencing of when actors take their turns, passing updated resources to each in turn. This is your "step by step" imperative approach, and you're basically writing a main game loop. * don't sequence the actors, but implement a lock on the resource using a TVar. This is the s…

I'm not arguing about which paradigm is better. I'm not saying theres no way around it. I'm just describing a single pitfall in the functional paradigm. That's all.

Re: John Carmack on Functional Programming (2013) [video]

#79
post #71

Earlier quoted context omitted.

FP is not gonna wall you off from doing stuff like this. For example, and this is just off the top of my head, you could: * provide an explicit sequencing of when actors take their turns, passing updated resources to each in turn. This is your "step by step" imperative approach, and you're basically writing a main game loop. * don't sequence the actors, but implement a lock on the resource using a TVar. This is the s…

I'm not arguing about which paradigm is better. I'm not saying theres no way around it. I'm just describing a single pitfall in the functional paradigm. That's all.

Being able to write asynchronous (multi-threaded or not) code so easily using FP is most definitely not a pitfall.

Even in the most simple multi-threaded imperative programs, no compiler or hardware will give you almost any sort ordering guarantees by default. You have to use atomics or volatile or something else to get specific ordering guarantees. It's the same in FP compilers too.

Re: John Carmack on Functional Programming (2013) [video]

#80

Earlier quoted context omitted.

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…

Why would unit testing cost extra? It saves money.

Engineers have to do work.. I would unit test core libs... I would also hire manual tester because they were very useful. I'd likely not chase down 100% automated coverage. The goal is to ship a game not have 100% coverage. And I work 100% pure tdd in my day job and side projects so take that for what it's worth.
Post reply on HN