Author Topic: Source file sizes  (Read 15434 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Source file sizes
« on: August 13, 2010, 04:07:49 PM »
How big is your biggest file? I was thinking to combine all three .cpp files of Creature class (in Kaduria) but it would be 3134 lines then. That's too big. Currently the biggest file is level.cpp (2225 lines) but I have Level class in four different .cpp files, so together they would be really huge.

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #1 on: August 13, 2010, 05:20:32 PM »
Monsters.cpp - 8581 lines

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Source file sizes
« Reply #2 on: August 14, 2010, 05:58:39 PM »
Monsters.cpp - 8581 lines

Is that a major roguelike?

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #3 on: August 15, 2010, 04:16:33 AM »
It's my 'Wizard's Quest'.

Monsters in wq are code driven.
I.e. each monster type is represented by a separated class.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Source file sizes
« Reply #4 on: August 15, 2010, 10:38:49 AM »
each monster type is represented by a separated class.

Is it too much to ask why? I can't see any reason to do that. It's just generating a lot of classes with maintaining problems for sure.

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #5 on: August 15, 2010, 01:32:03 PM »
Most monsters have unique abilities.
Some have special AI tweaks.
Stats of monsters are not fixed (depends on level),
and some monsters have dynamic stats.

I don't have any kind of maintaning problems :)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Source file sizes
« Reply #6 on: August 15, 2010, 07:02:50 PM »
Yeah, but small things like that could be easily made data-driven. One day I was dreaming of full data-driven game object system (no inheritance and no switch-cases, just data) but that might not be possible unless everything is super generic.

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #7 on: August 16, 2010, 05:50:37 AM »
Yeah, but small things like that could be easily made data-driven. One day I was dreaming of full data-driven game object system (no inheritance and no switch-cases, just data) but that might not be possible unless everything is super generic.

Well. If I add all special AI behavior into single AI method with lots of ifs... It will be really hard to maintain :)

It's not that I think that code driven monsters and items are superior to data driven.
After all wq is my first attempt to make a roguelike.
This method definitely works, and provides more than enough flexibility.
But adding new monsters, or making some global rebalancing is indeed cumbersome.
Most likely in my next rl I'll try to implement what your are talking about - fully data driven game.
But IMO that will require much more careful planing, and some complex tools, to work with data.

I don't want to start any new projects before I finish todo list of wq.
But after this I'll be glad to discuss data driven roguelike, if you are interested :)

Jolly Roger

  • Newcomer
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #8 on: August 16, 2010, 10:19:29 AM »
6989  :D
PC PC only action.
It looks like I need to cut it.  ::)

Etinarg

  • Rogueliker
  • ***
  • Posts: 424
  • Karma: +1/-1
  • Idea archivist and game tinkerer.
    • View Profile
    • Gedankenweber Blog (German)
Re: Source file sizes
« Reply #9 on: August 16, 2010, 10:40:11 AM »
Software engineering rules of thumb say, 20 lines per method, otherwise try to split. 1000 lines per class, otherwise split.

My old prof said "A procedure must be short enough that I can see in one look what it's doing". At the time I felt this a bit a harsh requirement, but actually he was right. Having code in small, easy to understand pieces avoids mistakes.

Of course all rules have exceptions. But they come from good and bad experience.

Jolly Roger

  • Newcomer
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #10 on: August 16, 2010, 11:02:03 AM »
As I know “20 lines per method” rule brings more troubles than profit.

Etinarg

  • Rogueliker
  • ***
  • Posts: 424
  • Karma: +1/-1
  • Idea archivist and game tinkerer.
    • View Profile
    • Gedankenweber Blog (German)
Re: Source file sizes
« Reply #11 on: August 16, 2010, 11:04:08 AM »
Can you elaborate on that? I'm sure I get involved in such a discussion again, and it would be good to know more about the why's and how's :)

Edit: Personally I'd rather make a "one task per method" rule than a certain number of lines. If a method consists of several sub-tasks, better move those into their own methods. This is still very blurry, but generally what I try to do and it seems to help.
« Last Edit: August 16, 2010, 11:07:17 AM by Hajo »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Source file sizes
« Reply #12 on: August 16, 2010, 11:18:51 AM »
With functions the evolution seems to go like this: as a beginner you write very long functions trying to do everything. In intermediate level you make short functions out of everything and finally when you reach the master level you write functions only if it's called more than once (in basic classes, data type classes are different case..)

I think it's quite hard to avoid large classes in roguelikes.

Nolithius

  • Newcomer
  • Posts: 25
  • Karma: +0/-0
  • Ebyan "Nolithius" Alvarez-Buylla
    • View Profile
    • Nolithius.com
Re: Source file sizes
« Reply #13 on: August 16, 2010, 06:04:43 PM »
The whole "20 lines per function" metric, as well as a pervasive use of design patterns, works well in an academic setting, where professors or peers might need to easily review your code or analyze it from an academic perspective.

In a professional or personal project, the criteria are different: 1) does it work? 2) is it efficient? 3) is it easy to maintain?, in that order-- and if you're the only one on the project, 3 ceases to be as important.

I personally find shorter functions harder to understand than longer ones, since they usually rely heavily on other function calls, which makes tracing the logic and debugging a bit of an adventure. As Krice mentioned, I will usually only split functionality out into a function if it needs to be called from multiple spots.

The overhead of a function call can be expensive if it needs to be called once per pixel, 60 times per second, for example, hence the old SDL trick of inlining screen buffer writes instead of using a function.

Ebyan "Nolithius" Alvarez-Buylla
http://www.nolithius.com

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Source file sizes
« Reply #14 on: August 17, 2010, 05:18:56 AM »
My Unit::receiveDamage and LevelGenerator::generate methods are about 800 lines each.
And I'm not quite sure that I can split them.
There is so much local variables, that splitting them will born really hairy methods.

IMO method/function can be as big as it needs as long as it is well commented and structured.