Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |=----------------------------------------------------------------------------=|
- |=----------------------=[ Programming Guide ]=-------------------------------=|
- |=----------------------------------------------------------------------------=|
- |=-----------=[ learn programming for (more)fun and profit ]=-----------------=|
- |=----------------------------------------------------------------------------=|
- --[ Motivation
- Since people sometimes want to learn to code seriously instead of "just barely
- enough to like make game", and they ask where to start, I decided to try and
- whip up this little guide so I don't have to keep writing the same replies.
- Learning programming has benefits for making games. If your code is ineffective,
- your game will run slow. If your code is unreadable, not only are you unhireable
- as most commercial games are written in teams, you won't be able to maintain
- your game yourself as when looking at code you wrote a month ago is the same as
- looking at a code written by someone else.
- I repeat, this guide is for people who want to become skillful at programming,
- make it a marketable skill and maybe get a job programming(games or anything
- else they may want), not just slap together a game as quickly as possible
- regardless of the extensibility, effectivness, performance, readability
- and maintainability of code.
- This guide is suitable for complete newcomers as well as people with some
- experience who want to get serious with programming.
- --[ Introduction
- First of all, programming is a craft rather than science. You absolutely can not
- learn it just by reading books and thinking abouy it. Programming books
- are supposed to be a supplement to the learning not the core of it. Write code
- as you go through books, when you read about a new thing, write a program
- using it.
- It's also better to write a bunch of smaller programs (couple hundred lines
- at most) rather than immediately trying to write an open world RPG, if you tried
- to do that, it would take ages you'd be stuck rewriting your bad code over
- and over and in the end never getting any results.
- My recommendation is in the beginning jst try to use the newest thing you learn
- in a simple way(i.e. you just learned how to use an array and a cycle so try
- to find the highest number in a sequence of numbers in array), the books I
- recommend provide these kinds of excercises at the end of a section. After you
- have basic understanding of the language try solving algorhithmic problems from
- high school algorhithmic competitions, their solutions are usually short(within
- 1K lines depending on dificulty) and they will teach you algorithmic thinking.
- --[ Getting Started
- As a first language to learn, go with C (even people who already code should
- learn C if they are looking to be more serious with their programming).
- I know you might think C is an incredibly low level language that's unusable in
- real projects but this is a meme and it's patently untrue, C is a high level
- language and it's perfectly usable for making games(I'll provide examples
- later).
- C is in my opinion the perfect language for beginners for a couple of reasons:
- a) C is simple and easy to learn.
- It only has 32 keywords. It provides the most essential tools which
- you'll find in pretty much any other language and the vast majority
- of languages have syntax inspired by C. You'll find learning new
- languages really easy after learning C (with some exceptions like
- functional languages).
- b) C is procedural.
- It's focused on procedures and algorithms rather than some esoteric
- design of object hierarchies. When coding in C you will be focused on
- trying to solve problems with procedures(functions) which are simply
- implementations of algorhithms. You will learn how a big problem can
- often be broken down into smaller ones, each solved with a procedure
- of it's own.
- c) C is still relatively close to the hardware.
- It makes you understand how memory is handled by the OS on a more
- fundamental level which in turn gives you an understanding of how
- the higher level languages work "under the hood" and about their
- limitations and inefficiencies which you wouldn't know otherwise.
- Experience in C will make you better in most other languages.
- d) C is bare bones and has no helper wheels.
- If you want to shoot yourself in the foot, C will let you do it. This
- gives you a lot of power but as you know, with great power comes great
- responsibility. If you aren't careful you will fall, but every fall is
- going to be a learning opportunity because it will be your fault
- not because of some weird behavior of obscure features of the language.
- --{ Recommended Reading
- C is best learned using the book The C Programming Language by K&R (it's the
- only book you need, C is very simple).
- Supplement it by a great book Algorhithms + Data structures = Programs by
- Niclaus Wirth which will give you a very solid foundation to build on for
- the rest of your programming adventures.
- Remember to always do the excercises from the books and don't forget to keep
- solving those competition problems as you learn. You can solve many with just
- the tools presented in the first chapter of K&R.
- Here is an archive of programming contest problems from just one school and you
- can use google to find more:
- http://www.cs.umd.edu/Outreach/hsContest.shtml
- (at a glance I can tell at least the first three from 2016 are solvable with
- just the knowledge from the first chapter of K&R)
- Treat them like puzzles and have fun, try to challenge yourself to make them
- as optimal(fast) as possible).
- For formatting guidelines (where to put brackets, how to indent code etc),
- use this:
- https://www.kernel.org/doc/Documentation/CodingStyle
- --{ Linux
- I have to recommend you start programming in Linux. Linux is a very programmer
- friendly environment, many great programmers swear by it, and even most good
- universities recommend it for their students.
- I switched to Linux as a highschool kid getting into programming competitions
- because it was much easier to work in. Contrary to popular opinion, it's not
- some ugly, convoluted or purely terminal based OS anymore. These days,
- it's a full fledged user friendly OS on par with Windows and Mac. You can get
- many flavors of linux, many of them as pretty and user friendly as mac or
- windows. In fact you can get some that specifically try to imitate the look
- of Windows(PCLinuxOS) or Mac(ElementaryOS) or go their own way in designing
- a user friendly UI.
- For newcomers I recommend one of these: Ubuntu (or it's various flavors like
- Xubuntu), Fedora(Xfce version is my personal OS of choice), Linux Mint
- or the two mentioned in the paragraph above.
- You don't even have to give up windows, you can install Linux under 30 minutes
- and you can either install alongside windows(dualbooting, you get a choice when
- starting pc for which os to boot) or run it in virtual machine with something
- like VirtualBox. At least give it a try.
- --[ Linux development tools
- For writing code I recommend starting with simple editors like Gedit(similar to
- notepad on windows but with various enhancements useful for programming) or
- Geany(more features but still very light-weight) or Vim(ard to learn but once
- learned, your speed will blow through the roof) for the adventurous.
- For compiling your programs you only need to use the terminal.
- Compiling in linux: http://www.linfo.org/create_c1.html
- The terminal is the most useful tool in Linux and if you're not using it you're
- missing out. Here is a good bunch of tutorials to get into it:
- http://linuxcommand.org/
- When beginning I used to have a printed cheat-sheet with terminal commands which
- I put somewhere I could always glance at it if I forgot something:
- https://files.fosswire.com/2007/08/fwunixrefshot.png
- That's really all you need to get started and after 5 years of coding, that's
- still what I use for 90% of my work.
- --[ Making games in C
- Making games in C is entirely possible even for beginners and single-man/small
- teams. I recommend starting out with simple terminal games, either text based
- or using the ncurses library, but you can safely skip straight to graphics.
- Once you want to make some games with real graphics, then I suggest SDL2 for
- creating windows and simple 2D graphics for 2D games and OpenAL for sound.
- OpenGL is great for 3D or 2D(more complex than SDL but provides more features).
- I'm sure you can find engines for C but I would suggest first writing some games
- without them at least for learning purposes, the same idea of learning how it
- works "under the hood" applies here.
- Here are some tutorials:
- ncurses tutorial: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
- SDL2 tutorials : http://lazyfoo.net/tutorials/SDL/index.php
- OpenGL tutorials: http://learnopengl.com/
- http://lazyfoo.net/tutorials/OpenGL/index.php
- (remember to heavily use official library docs as well
- ==WARNING==
- While math above arithmetic is generally not a requirement for being a good
- programmer, I believe writing good 3d games(yes even with engines and no amount
- of screaming from unitydevs will change my mind) requires understanding
- of linear algebra and mathematical analysis up to partial differential
- equations. For 2D games you should at least have good understanding of
- highschool math, that is, basic algebra, geometry, vectors in 2d space and trig.
- Mathematical analysis and linear algebra can be useful in 2D as well.
- --[ Examples
- Here are some real games written in C with source codes you can scrounge
- through:
- Handmade Hero - a project of one programmer to make a full game in C
- from scratch (without even using graphics libraries
- like OpenGL).
- It's made by a great professional programmer who worked
- on The Witness and he records and streams all the coding
- sessions with commentary.
- https://handmadehero.org/
- Space Nerds in Space - 3D Star Trek bridge simulator made by one dude
- with a couple of friends without any prebaked engine.
- https://github.com/smcameron/space-nerds-in-space
- Craft - Minecraft clone.
- https://github.com/fogleman/Craft
- Wizznic - Puzzle game in C.
- https://github.com/DusteDdk/Wizznic
- ID Soft Games - Many old games by ID Software are in C and now open
- source.
- https://github.com/id-Software
- There are many other you can find online. I hope you see that writing games in C
- is more than possible, not some herculean task. In fact there is no proof that
- OOP itself speeds up the process compared to procedural programming, you can
- write games procedurally in high level languages and make games as quickly
- as in OOP languages.
- --[ Where to move on from C
- From C you can go pretty much anywhere, here are some tips:
- a) OOP Languages
- C++, Java, C#, D and tons more. They are popular in the industry
- and thus marketable so it's a good idea to learn some even it OOP isn't
- all that great.
- It's really hard to recommend a book here cause most books you find on
- OOP are literal garbage (I try to be moderate, but here I just can't).
- While they teach you to code and you may be able to write working
- software, your code will suck. It's sad that it is like this but alas.
- One of the best ways to code in these languages would be using some
- functional principles. So I think that, ironically, to really write good
- code in C++ you should dabble a bit in Haskell. (Never touch a book
- that's about general OOP theory, it's useless and the ideas are bad.)
- Here are some articles by really good programmers on using functional
- principles in C++, one is from Carmack and one is from the post mortem
- of The Witness:
- http://www.gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php
- https://mollyrocket.com/casey/stream_0019.html
- I recommend reading the whole post mortem, this is the same guy who
- makes Handmade Hero:
- https://mollyrocket.com/casey/index.html
- From regular books, Eckel and Stroustrup will get you started
- sufficiently in C++.
- Decent Java books would be Java in a Nutshell or The Java Programming
- Language (spare yourself though, when dante wrote divine comedy he
- ommited one circle of hell and that would be Java).
- I have no idea about C# or D books since I don't use them.
- Why OOP is bad: https://www.youtube.com/watch?v=QM1iUe6IofM
- Another good rant on modern programming conventions:
- https://www.youtube.com/watch?v=Y0V7nwaPe2E
- b) Scripting languages.
- I recommend learning at least one or two scripting language like Bash
- (extremely useful if you work in Linux), Python, Lua, Ruby, JS or other.
- These languages have an advantage that they are interpreted and very
- high level which means you can write code in them extremely quickly,
- the tradeoff is much slower performance than compiled languages.
- This makes them useful at quickly writing short programs for small
- specific tasks(scripts) and prototyping. Most of these have some type
- of game library(often more than one) you can use to make games quickly
- (LOVE for lua, PyGame for Python etc).
- Fun book on Ruby: http://poignant.guide/book/
- Interactive Python tutorial: http://www.learnpython.org/
- Another Python book: https://learnpythonthehardway.org/book/
- (i haven't read this one just heard it's ok)
- Short and concise book on Python:
- http://www.greenteapress.com/thinkpython/thinkpython.pdf
- This one serves great as reference: http://www.diveintopython3.net/
- A quick overview of Lua: http://tylerneylon.com/a/learn-lua/
- Crashcourse in Lua, this one teaches you by analyzing a piece of code:
- http://tylerneylon.com/a/learn-lua/
- Great book on Lua: Programming in Lua
- 1st edition is available online but i'd recommend
- using the newest
- Advanced concepts in Lua: http://www.lua.org/gems/
- Remember to use official reference manuals (this applies to all
- languages): http://www.lua.org/manual/5.1/
- c) Functional languages.
- Languages like Haskell and Lisp are for the more adventurous people but
- they are worth learning just for what an eye opening experience they
- are. Programming functionally is completely different experience that
- will challenge everything you know about programming. Game programming
- in lazy languages is especially weird due to the real time nature of
- games.
- I also believe functional programming will become way more popular in
- the coming years because of the trend of increasing the amount of cores
- in processors instead of making the cores faster. This means that
- programs that can work on multiple cores at once(multithreading) will be
- more and more desireable. It is very hard to write such code in object
- oriented languages like C++ but functional languages make it easier by
- an order of magnitude.
- Learn you a Haskell is popular, fun to read tutorial but not that great
- from the educational standpoint, use at your own discretion:
- http://learnyouahaskell.com/
- Good compilation of resources for learning haskell:
- https://github.com/bitemyapp/learnhaskell
- Interactive Haskell tutorial: https://tryhaskell.org/
- Lisp: http://www.gigamonkeys.com/book/
- There are tons of other procedural languages and many languages that don't fit
- into the previous specific boxes, mix and match between features or do something
- weird. You can explore and find whatever you like.
- Everything is up to you now.
- Best of luck with your programming and gamedev adventure!
- --[ Random thoughts/tips/whatever
- --[ Why OOP sucks
- Another reason to start without OOP is that OOP gets into your head. It's an
- intuitive concept but it usually doesn't work as nicely as those tiny examples
- in books, in fact the bigger you get the worse it becomes.
- Once you have it in your head however, and you don't know anything else, you
- start trying to fit every problem into some classes and objects even if it's
- not a good idea. It's not your fault, you're not dumb, it's just that that's
- the only tool you've been taught. OOP becomes the hammer and every problem
- suddenly looks like a nail.
- I know OOP seems like all the rage now, just don't think it's going to be
- a godsend or silver bullet that solves all your programming problems. OOP is
- in fact really not that great and doesn't actually provide any advantage it
- originally promised over procedural imperative programming (you'd be hard
- pressed to find any actual evidence of this).
- OOP is just popular because it's easy to superficially teach in a corporate
- enviroment to create armies of code monkeys that write really bad code.
- Popularity has an advantage of tons of libraries but even that is a bit of a
- hidden disatvantage as most libraries are shoddily written and not as universal
- as you'd think. If you want to make an argument about "reinventing the wheel",
- then please realize that libraries are not wheels but complex pieces of code
- and you probably have little idea how they're written, and they might not be
- implemented effectively or the way that fits your problem domain.
- So just be careful and don't overly rely on external libraries and if you do,
- make sure they are good and fit your problem(SDL2 for example is one of the best
- libs out there with virtually 0 overhead and provides extreme simplification
- and crossplatform support).
- --[ Functional Programming
- If you want a different paradigm that actually does some very interesting things
- then get into functional programming. It's weird, it's completely different but
- it provides some amazing things like referential transparency, laziness and
- immutable state which actually solve a lot of problems procedural programming
- has and OOP promised to solve but made worse(let's solve problems with mutable
- state by making an entire paradigm dependent on mutable state, wew lad).
- The problems with FP are that it's often not as efficient as C since it's high
- level, however, Haskell compiler for example offers some great optimization
- options and with a little understanding of compilation you can rewrite the
- heavy parts of code a C-like performance.
- There's an extra benefit to learning these since functional principles can be
- applied in any language.
- --[ For the l33t h4x0rZ
- Hacking: The Art of Exploitation by Jon Erickson - with all the shitty meme
- books on "hacking" it can be hard to identify any serious ones so I decided to
- throw one in here if anyone is interested. This one is good. Really fucking
- good. However it's also pretty terse and you should already know how to code
- and know C pretty well. It's worth reading even if you're not planning to make
- a career in security because it will teach you a lot about the inner workings
- of operating systems.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement