How do people do this? How do their minds work?
How do people do this? How do their minds work?
I could never imagine myself writing 50,000 lines, I'm way too lazy for that. Fifty-thousand lines? You could write a universe in that, with a high-level language like Python (or in assembly, a smallish planet).
Semi-kidding aside, it's part laziness and part DRY-principle. I hate writing code twice, even if it's two chunks with similar functionality. If they are so similar (in an abstract way), there's probably a reason for that, and I try to capture that reason into my code by unraveling the similar parts from the specific parts. That usually makes it smaller.
Can you imagine what happens if those 50K lines (comments/white-space aside) all implement nearly unique functionality? Those 64k demos linked upthread are what happens. I'm going to guess those are 100K-250K lines C++ [1], maybe? But then, a prize-winning 64k probably does a little bit more than a basic partial Minecraft engine :-P
Since you're asking "how do their minds work?", maybe I can get a little bit obsessive over this optimizing (wouldn't call it OCD--that would trivialize the disorder), but I do really get a slight "mind itch" if I notice code with duplicate functionality.
[0] Sometimes it doesn't. But often there's other advantages, too. If that's not the case either (or I'm on a deadline), I grit my teeth and write the duplicate code, but I try to make it really obvious that it is duplicate. That way at least it'll compress well :P
[1] Not even the 4K demos use pure assembly any more, compiler tricks and exe packers have become amazing in the past decade since I stopped making them. Not counting the external procedural/generative design tools/Werkzeuge, btw.
For example the scala compiler + standard library:
find src -name "*.scala" | xargs cat | wc -l = 244,601 git log --format="%an" | sort | uniq | wc -l = 149
IMHO the game actually shows how powerful Python + Pyglet (OpenGL actually) are.
Wanna get your mind blown even harder? Check some 4kb demos[1]... and that's binary size! No JVM/Python runtime supporting it.
[1] http://www.youtube.com/results?search_query=4kb+demo&pag...
It's comparatively very big (179KB), but impressive how they were able to squeeze so much stuff there: video http://www.youtube.com/watch?v=wqu_IpkOYBg, official repository: http://j.mp/11ETcY0.
If you want to dig deeper, Farbrausch published most of their material and tools last year including the source code for fr-041. Search for farbrausch on GitHub. But I must say, it's pretty hardcore.
(DirectX + 4kb) vs. (OpenGL + Python + Pyglet + 500LOC)
=
4kb vs. (Python + Pyglet + 500LOC)
Long are gone the days when you could manage the framebuffer yourself :) Specially if you want to run the demo in modern OSes.[1] http://en.wikipedia.org/wiki/.kkrieger [2] http://www.youtube.com/watch?v=2NBG-sKFaB0
It's in Farbrausch's GitHub with many more demos/demotools https://github.com/farbrausch/fr_public
Edit: It would be intresting to see demos like this (4KB / 64KB) for WebGL. Does something like this exist already ?
This one really gets me as well:
Talk to me about "shouldn't" when we start breaking the Shannon-limit or other hard information-theoretical limits :-P
Code a lot. Write games a lot.
This produces slower results, better code. The other trade off is I'm not working from direct memory or skill, so co-workers have less respect for me, even if "my" solution is better than theirs.
This makes me functional years ahead of my experience, but belies a true understanding of the concepts. As I methodically catch up with myself over time, this is less true.
That is, I would write something in the first, most-obvious way that occurred to me. Then, recognizing patterns, I would refactor it down to something smaller. Usually this repeated a few times, until the 100ish lines of code I wrote turned into 10 or 20.
Python gives a programmer a lot of help in reducing redundant code. It makes C#/Java/etc. feel really tedious with all of the boilerplate code you end up writing.
tl;dr: DRY