Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4

Author Topic: I want to learn how to program roguelikes.  (Read 6129 times)

catpaw

  • Bay Watcher
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #30 on: April 03, 2014, 02:31:46 pm »

I just want to add two experiences from my past and then 3 general statements and a conclusion.

Experience 1: First is a daemon I wrote. Version 1 was in pure C. Albeit some coworkers asked, why I didn't do it in something like Python or Ruby I said, well because its a daemon running in background, I want it to use as minor memory as possible and take at least system resources. Both languages come with a hugh impact if you need to have them installed just because of this. Also its working at close hands with kernel system services. So C! The configuration used to be in XML. I did classical memory management. And since there were a lot of pointers criss-cross going on, it was just the task needed it. I was on the edge of maintainable in my head to add new functionality without either introducing memleak or crashes due to false freeing.

BUt it was still okay by itself. On another front people kept asking me to add more and more options to XML. With more logic, like when this kinda that. It soon become a kinda strange language itself like <if condition="bla"></if> etc. As this grew, at one moment I said, fuck that. You're going to have version 2 and the new configuration file is going to be some established scripting language. Then you can do all that kind of wired wishes you have by yourself in your config file. I'll just maintain core functionality. After a few days reading up on scripting languages I decided for Lua, albeit i never heared of it before. Fast and very small memory footprint and it was supposed to be easy to integrate in existing systems.

After I've done that, I wondered, I got already the Lua enginge bound and loaded, and I got a lot of complicated logic in the core where memory managent become a burden. So why not move some of the more complicated stuff in the Lua world. This worked out great and at the end I only got that stuff left in C that directly worked with the kernel, child-process, signal and pipe management.

And now for the surprise end. It actually ran faster than my C code! Why? Because my C stuff sucked. The Lua code was using hashtables all the way, everywhere, natively, where I by most of the stuff just bothered with binary searches - if at all and not doing linear searches. Also a lot of double and triple checking around the data could be done away, since the garbage collector took care of it. Yes of course a good coder putting in major effort will always be able to replicate all that in C(++), but an average coder, or someone trying to be efficient in the amount of work done, may get even better results using some scripting language. Also there are garbage collectors for C(++) like gcc uses internally. But they are strange to setup and work a bit weird.

There are some obscure examples where a just in time compiled language is actually faster than C++, since the JIT can use live profile gathering to recompile on the fly, like rearranging then/else clauses on the fly so the pipeline and cache hits better. However as argument in a debate I consider these very artificial, any real life example will not hold true to that. Anyway, to the casually coded stuff, it really can get better, for real.

-

Experience 2: Another experience. C++ stops being funny or efficient when you got that one bug that keeps crashing your application you find impossible to find. At one company I worked at, we had a ton of compile-time of configuration in XML, which needed to be done into other stuff - automatically written code for example. Anyway, I was asked how we should approach that, and I suggested, after a day research, Python back then. I was overruled at the meeting to use C++. Why C++? Compile-time configuration?? Its the one place where speed hardly matters at all. It even can be cached. No, I was told we didn't have any Pythoncoders and people need to learn C++ anyway, since they'll need that for other projects. *Sigh*. A few months later, I was approached again. Hey, you. You got long coding experiences, our compiletime stuff (in C++) keeps crashing, can you take a look at it? Why me? It was I who told you not to use C++ for it. Anyway, job is job and if boss asks you to do something... Took me a good week to find a place, where a rogue pointer overwrote one variable on the previous stack and thus caused a crash when the code was backtracking later on...

-

statement 1: there is an argument that you are only a "real" coder when you went through the pointer shit. I don't know. I won't argue with this, thats kinda subjective. I suppose it depends where you eventually want to end up with. To say on rogue likes, you'll be able to code awesome roguelikes without bothering about pointers ever. If you want to become an expert at computer science, or studying computer science. I think one should have seen pointers at work at least once.

statement 2: I have a serious dislike about people coming up with cool little coding snippets to show how awesome their language of choice is, this includes contests. If you're going to code a project that keeps you more busy than a few weeks than overall structure is way more important, than if you can code this or that task in 1, 3 or 7 lines. In my experience this are also guys and gals who code little snippets, alone, and hardly had ever to bother with maintaining a project over several years and also having to work on a code base with others where understandable structure is getting even more important.

statement 3: I have some vicinity to people doing heavy number crunching for their research. Tell you what. They more often than not keep in Matlab or R. Both very high level scripting languages. Not that they not know how to do it in C(++). Not that it wouldn't run around 10-50 times faster in C(++). But they are going to design and implement some algorithm, test it out, proof their point and publish a paper about that. So when the algorithm runs in 8 hours through the task on their desktop, its enough. Why invest a few weeks of coding - or just days if you're that awesome - to have the same thing run in 30 minutes? After its done it done. And you're going to publish the equations anyway, so if someone is going to put it to practice then s/he can do it.

Concluding. Especially the last arguments is about language "having their place in this world". Yes! I mean I've been now coding for 2 decades in more than a dozens languages. I'm not emotional about any anymore. But for heavens sake, it was not the question of the top poster if language X is has its place! (If he is still reading / caring at all that is).
« Last Edit: April 03, 2014, 02:39:21 pm by catpaw »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #31 on: April 03, 2014, 02:40:31 pm »

I really think that you should learn how to program before learning how to code. You know, changing data in order to make stuff happen? Paradigms can come later, first learn how to replace numbers divisible by 3 with "fizz", numbers divisible by 5 with "buzz" and numbers divisible by both with "fizzbuzz" without ever dividing by 15.

xpi0t0s

  • Bay Watcher
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #32 on: April 24, 2014, 06:49:10 am »

Agree with most of the stuff up here.  There is no "best" language.  There is also no "worst" language - sure, you might struggle with COBOL, but if you know it well and have the appropriate libraries then there's no reason not to use it.  Even if there were a "best" language, you still need to get to know it first.

So what is your goal?  Do you just want to get a simple roguelike up and running as quickly as possible, learning whatever language gets you there quickest?  Then pick a language that's easy to learn - BASIC, Python or whatever, and only look at other languages if and when you hit a brick wall in your chosen language - BASIC for example might not handle vast amounts of A* pathing well, and at that point you might have to start thinking about optimising further via C/C++/Assembler.

Or do you want to learn programming in order to get a job later?  Then pick the most common industry languages which are (if I'm not out of date) C++ and Java, although that might vary depending on which industry you want to get into - banking, for example, still has a lot of working COBOL that needs maintaining and tweaking every so often.

If you currently can't program *at all* then realistically whatever language you pick it's going to be at least three months (more if you've got a full-time occupation) before you'll get started on your RL project.
Logged

MDFification

  • Bay Watcher
  • Hammerer at Law
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #33 on: April 25, 2014, 09:04:45 am »

Here's a guide I used when I tried to learn how to program a roguelike. It uses Python and Libtcod, and comes with tutorials for the both of them.
I lost my project when my old laptop kicked the bucket and never restarted it b/c I'm terrible at programming. :'(
Logged

GavJ

  • Bay Watcher
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #34 on: April 25, 2014, 10:31:35 am »

Programming language for a roguelike isn't too important seeming. Dwarf Fortress is a major OUTLIER insofar as the resources it chews up. Your own roguelike is very unlikely to be simulating parabolic trajectories of flying bones and intelligent pathing of hundreds of entities and stuff all the time, and so maximum optimization in low level compiled programming languages will almost certainly not be necessary.

In most cases, I would in fact suggest either "whatever you are best at coding in" OR in the special case of "I want to distribute this to various devices / be able to play it on my phone," then use Java, because aside from user interface differences for input methods, you only have to code the core once for all platforms (it's specifically made for that), unlike porting 15 different versions each release like C++.



Edit: Also, as catpaw mentioned above, you have to be a REALLY good coder to out-think the built in garbage collection etc. in most higher level languages like lua, ruby, python (and java for this point at least), etc. Thus, the main advantage of C or C++ will not be realized by you anyway if you are an inexperienced coder, or even if you are but if you're excited by features and don't dwell long enough on optimization *cough cough soundsalittlebitfamiliar cough* (I do that too, Toady, it's okay)
« Last Edit: April 25, 2014, 10:39:28 am by GavJ »
Logged
Cauliflower Labs – Geologically realistic world generator devblog

Dwarf fortress in 50 words: You start with seven alcoholic, manic-depressive dwarves. You build a fortress in the wilderness where EVERYTHING tries to kill you, including your own dwarves. Usually, your chief imports are immigrants, beer, and optimism. Your chief exports are misery, limestone violins, forest fires, elf tallow soap, and carved kitten bone.

sweitx

  • Bay Watcher
  • Sun Berry McSunshine
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #35 on: April 25, 2014, 04:21:51 pm »

My couple of cents.
If you already have a programming language you're comfortable in, use that. Unless you're trying for something on the scale of DF, whatever performance penalty in your language of choice would likely not matter.
Personally, I'm partial to C/C++ since that's the language I'm deeply familiar with. If you have no coding experiences, I suggest Python as starting point. If you need a bit more performance, try learning Java. Both languages should be more than sufficient for most roguelike game (again, unless you're trying to code DF clone or something similar).

I would argue that if you REALLY want to learn as much as you can about programming, try C/C++ at least once (whether it being the first language or Java as a stepping stone). If nothing else, it makes you appreciate features in Java like garbage collection.
« Last Edit: April 25, 2014, 04:35:43 pm by sweitx »
Logged
One of the toads decided to go for a swim in the moat - presumably because he could path through the moat to my dwarves. He is not charging in, just loitering in the moat.

The toad is having a nice relaxing swim.
The goblin mounted on his back, however, is drowning.

ozyma

  • Bay Watcher
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #36 on: April 25, 2014, 09:58:26 pm »

SFML for graphic is probably the best choice. Learn to make sprites move on a screen and you can make any 2D game.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #37 on: April 26, 2014, 12:52:09 am »

SFML for graphic is probably the best choice. Learn to make sprites move on a screen and you can make any 2D game.

OpenGL is a better choice, learn to move textured faces around and you can make any game :P
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: I want to learn how to program roguelikes.
« Reply #38 on: April 26, 2014, 06:22:08 pm »

I want to tell you to start with C++. I really do. I didn't realize until recently, but I'm apparently a very "old-school" programmer. I started out programming with BASIC and then moved on to C++, which I've been using for years. For a long time, C++ was the only proper way to make a computer program as far as I was concerned. It's traditional, fast and reliable. It's a programmer's programming language if ever there was one.

That said, use Java or Python if you're just starting out. There's more to making a computer program than just squeezing a few more milliseconds out of that algorithm with low-level C++ shenanigans. Your time, as a programmer, is just as important. And memory management, boilerplate code and library headaches are a waste of it.

But real men code in assembly.


Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #39 on: April 27, 2014, 04:11:33 am »

That said, use Java or Python if you're just starting out. There's more to making a computer program than just squeezing a few more milliseconds out of that algorithm with low-level C++ shenanigans.

Especially since compilers are nowadays better at that than you will ever be.

Flarp

  • Bay Watcher
  • and tearing apart the self-esteem!
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #40 on: May 23, 2014, 12:46:55 am »

Don't ignore languages like [...] Visual Basic

Spoiler (click to show/hide)
Logged
He views any show of emotion as offensive, sees introspection as important, values self-control, and strongly believes that a peaceful and ordered society without dissent would be best. He believes that mastery of a skill is one of the highest pursuits, values nature, and finds romance distasteful. He holds well-laid plans and shrewd deceptions in the highest regard.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #41 on: May 23, 2014, 12:59:08 am »

Not to mention that Python is built around the "unconfusing syntax and a One Correct Way of Doing Things".

Trickman

  • Bay Watcher
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #42 on: May 24, 2014, 09:01:01 am »

I am a computer engineer and I absolutely DETEST Python. FUGLY code, horrible type casting issues (as with any language with no type declaration), some syntax issues, bad IDE's, bad debuggers, bad std libraries, bad everything.

The best language for this kind of projects is probably either Java or C#. The code is clean, tidy, readable and you're "forced" into good programming habits; the builds are stable, and the program itself gets easy to update, patch, maintain and make changes to. Good support and libraries, too. The problem is Java and C# aren't easy to learn properly, since you need to learn about OOP (and all there is to it) in the first place.

If you are serious about making games, I suggest doing an IT professional course or getting a degree on it. It's a perfectly legit life goal, and you can make a living out of it.

If you just want to make a roguelike "because why not", I have some bad news: You won't. There's A LOT to learn before making one of these. Sure Toady is a matematician, not an IT grad, but he made A SHITTON of games before DF, and he sometimes expresses he wishes he had known some better programming habits and standards beforehand. If he had known as much as he knows now when he started DF, FPS death would be a much smaller issue, and the game would have less bugs.

"I want to make a roguelike, because I feel like it, though I have no idea of programming" is and equivalent to "I want to run a marathon, because I feel like it, though I'm a couch potato". It's not something you just "do". It takes years of preparation and making smaller, more basic tries before you head for your goal.
Logged
This is a plain text forum signature. All typedwarfship is of the finest quality. It menaces with sentences of plain text.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: I want to learn how to program roguelikes.
« Reply #43 on: May 24, 2014, 03:32:55 pm »

All languages are on a sliding scale between ease of use and power. C and C++ are still some of most low-level and powerful languages around (excluding assembly or straight machine code), but they are hard. For your first roguelike they probably won't be what you want to use, but they have many, many other applications, simply by virtue of their power and the far-reaching optimizations you can do. I doubt Lua lets you control memory manually. In some contexts, that's an advantage, in others a disadvantage. I'd dare to say that most commercial games nowadays are written in C++, simply because you can do anything with them and because they have so many libraries.

Python is a very neat language by virtue of it's simplicity, but C# strikes (for me) an ideal balance between power and ease of use.

Also, if you REALLY want to learn good coding habits, try coding for an open-source game with strict code standards, like /tg/station. It's incredible how much a year of programming in the shitty engine that is BYOND, desperately swimming against the shitstream that is old SS13 code, featuring half-assed polymorphism while constantly being judged by the maintainers has taught me. (I'm a tgstation maintainer myself now, btw)

If you're really dedicated, you can probably make a basic thing that looks like a roguelike, but I suggest learning programming and doing small projects first. It won't take years of preparation, but I doubt you'll succeed if you go into this with no experience.
« Last Edit: May 24, 2014, 03:39:27 pm by miauw62 »
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: I want to learn how to program roguelikes.
« Reply #44 on: May 24, 2014, 10:36:33 pm »

desperately swimming against the shitstream that is old SS13 code
I've heard the legends of men swallowed whole by the seas of spaghetti. Is it true?

Also yes, C# is a good beginner's language too. I forgot to mention that one.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU
Pages: 1 2 [3] 4