Author Topic: How big is your Level class/file?  (Read 82267 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #30 on: November 23, 2014, 06:21:51 PM »
I thought it was a genuine question about programming with several good replies, even sharing some techniques that people have found useful, but you've dismissed it all.

I don't think there was a good advice how to split a class where everything seems to be connected anyway. I try to be open for new ideas and be a less dork, but it's difficult... I become defensive fast when people don't have experience from programming large scale roguelikes.

Another thing is that should you split classes when they become "too" big. If so, why? What is the "limit" of lines of source code per class?

mcouk

  • Newcomer
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #31 on: November 23, 2014, 06:30:11 PM »
[Redacted]
« Last Edit: November 25, 2014, 12:40:53 AM by mcouk »

LindaJeanne

  • Newcomer
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #32 on: November 23, 2014, 06:52:42 PM »
I don't think there was a good advice how to split a class where everything seems to be connected anyway.


I'll address this for the sake of others who find this thread while genuinely looking for answers -- but I'm under no illusions about what you will think of me or my reply.

One of the reasons you haven't been getting more concrete answers is because you're asking a very abstract question. I can't know whether or how to break up your level class, because I have no idea what it contains.

But the general answer to the general question of how to break up a huge class "when everything seems to be connected anyway": you need to take a step back and look at it from an architectural perspective. What is coupled due to a genuine need for coupling, and what just sort of ended up that way? Obviously, everything IS connected to everything else in some fashion, or it wouldn't be a single program. But there is flexibility in how tightly things are connected, and in what is connected to what, and where those connection points are.

As an example, I have a separate class for generating the "blueprint" of a level. It handles all the procedural level level generation code, and creates an array with the results. That array is then passed to a different class which uses the array as a blueprint for actually building the level. This second class then keeps track of the locations of things during gameplay.

It would be easy to say that "deciding what to put where" and "putting it there" are too tightly coupled to separate without causing even more complexity, but I have found that not to be the case.

One technique that I've found is helpful for finding hidden/unnecessary couplings is writing unit tests, because this helps you think about smaller more isolated pieces of code.

Like everything else, design patterns and refactoring can be used badly, and make more of a mess out of code than it was before. But that's true of any programming technique, and doesn't happen when the technique is used properly & when appropriate. What makes structuring large bodies of code difficult is the need to simultaneously look at the big picture of the whole, and also the smallest decomposable parts at the same time.

Another thing is that should you split classes when they become "too" big. If so, why? What is the "limit" of lines of source code per class?

It's not the number of lines that's significant, it's the amount of work the class is doing, and what responsibilities it has.
« Last Edit: November 23, 2014, 06:55:44 PM by LindaJeanne »

Trystan

  • Rogueliker
  • ***
  • Posts: 164
  • Karma: +0/-0
    • View Profile
    • my blog
Re: How big is your Level class/file?
« Reply #33 on: November 23, 2014, 07:30:08 PM »
I don't think there was a good advice how to split a class where everything seems to be connected anyway. I try to be open for new ideas and be a less dork, but it's difficult... I become defensive fast when people don't have experience from programming large scale roguelikes.

There's excellent advice on splitting large files; separating concerns, refactoring, real world examples, etc. You have to actually do it though. If you want to change your code you have to change what you're doing. Like Einstein said: "We can't solve problems by using the same kind of thinking we used when we created them."

The principals of good programming within a large codebase are the same regardless of the product. If you are determined to dismiss anyone who doesn't have 4000 lines of C++ Level code then you're missing out on a lot of good advice and only hurting yourself for no good reason.

Another thing is that should you split classes when they become "too" big. If so, why? What is the "limit" of lines of source code per class?

Ultimately the reason for any programing technique, principal, or practice is to reduce the cost or risk of future changes. Clean code takes less time to add new features and is less likely to acquire bugs when changed; messy code takes more time to add new features and is more likely to acquire bugs when changed. Code that has high cohesion and low coupling is generally considered clean and good; code that has low cohesion or high coupling is generally considered messy and bad. There are a ton of good books, presentations, and blog posts out there on this stuff - you should check some out.

There's not hard "limit" - it's not like 1000 lines is good and 1001 lines is bad. It's more about the concepts and responsibilities than line numbers. No one can give specific advice about your code unless they see what you're asking about but it seems like there's several people who would help.

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #34 on: November 23, 2014, 08:01:56 PM »
Quote
I become defensive fast when people don't have experience from programming large scale roguelikes.

sensiblechuckle.gif

Man, you ought to be a lot more gracious with the people who are humoring you in this thread.
« Last Edit: November 23, 2014, 08:09:47 PM by mushroom patch »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #35 on: November 24, 2014, 06:13:59 PM »
What experience do you have of programming roguelikes?

You must be new here. I have experience from year 1995 when I started to program a next generation roguelike. Apart from studying in 1998-2001 it's been practically continuous development. The project (Kaduria) has about ~500K lines of code. Now.. show me your roguelike (doesn't have to be released) that has ~500K lines of code. Then we can possibly talk more about things.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #36 on: November 24, 2014, 06:17:31 PM »
If you are determined to dismiss anyone who doesn't have 4000 lines of C++ Level code then you're missing out on a lot of good advice and only hurting yourself for no good reason.

I think I'm going to keep what I have. I'm estimating the final size of Level can be a lot more than 4000 lines. Maybe something like 6000 with town generation routines.

reaver

  • Rogueliker
  • ***
  • Posts: 207
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #37 on: November 24, 2014, 06:27:46 PM »
You must be new here. I have experience from year 1995 when I started to program a next generation roguelike. Apart from studying in 1998-2001 it's been practically continuous development. The project (Kaduria) has about ~500K lines of code. Now.. show me your roguelike (doesn't have to be released) that has ~500K lines of code. Then we can possibly talk more about things.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”
― Bill Gates

Rickton

  • Rogueliker
  • ***
  • Posts: 215
  • Karma: +0/-0
    • View Profile
    • Weirdfellows
Re: How big is your Level class/file?
« Reply #38 on: November 24, 2014, 06:48:10 PM »
What experience do you have of programming roguelikes?

You must be new here. I have experience from year 1995 when I started to program a next generation roguelike. Apart from studying in 1998-2001 it's been practically continuous development. The project (Kaduria) has about ~500K lines of code. Now.. show me your roguelike (doesn't have to be released) that has ~500K lines of code. Then we can possibly talk more about things.
If you're only interested in hearing from people who have worked on a single roguelike for 20 years, why not just email the ADOM guy? I think he's the only one who fits that description. He's actually had releases, too, so I'm sure you could learn something from him if you don't make up ridiculous excuses not to.
Creator of the 7DRL Possession: Escape from the Nether Regions
And its sequel, simply titled Possession

LindaJeanne

  • Newcomer
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #39 on: November 24, 2014, 08:09:04 PM »
Krice,

Why did you start this thread anyway? It wasn't out of interest in having a discussion, or you wouldn't be so dismissive of everyone who tries to participate. It wasn't in the hope of learning anything, since your coding skills are so superior to what any of the rest of us could ever hope to be. So I'm confused: what did you hope this thread would become?

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #40 on: November 24, 2014, 10:24:03 PM »
If you're only interested in hearing from people who have worked on a single roguelike for 20 years, why not just email the ADOM guy? I think he's the only one who fits that description. He's actually had releases, too, so I'm sure you could learn something from him if you don't make up ridiculous excuses not to.

I think ADOM's code is still old school C. Must be pain to maintain. He is actually talking about message routine refactoring in the newest blog post (I'm following ADOM blog) and it's just as you would think, it's even difficult to create a new message routine in gui, because the old is so hard coded (not cleanly modular). I know how it is, I have those same problems myself, but maybe not that bad, because since 2005 Kaduria has been mainly class-based. Although it's possible to create poor connections between classes as well, breaking something when another class is refactored.

But then again what would I learn? ADOM is not a next gen roguelike, it's nowhere near it. It's actually very old school, resembling mostly Nethack, but just has more everything. What would I learn from that or the fact that he is having constant problems with poorly written and hard to maintain C source code? Now he has like four or something guys helping him and it still seems to be difficult to add new features in the game. It's the reality in -actual- roguelike development. Not in theory or with 7DRL "roguelikes".

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #41 on: November 24, 2014, 10:50:59 PM »
"How big is your X?"

That's the question he asks. His answer: "real big." It is completely obvious what this thread is about and why he started it. "Your X isn't as big? You think the size of X doesn't count? Well, I don't have time for people who haven't been working their X for 20 years."

It's just lame-ass trolling from Krice as usual. Confused? Just stop pretending his game exists and everything makes sense.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #42 on: November 24, 2014, 10:59:53 PM »
Why did you start this thread anyway?

I'm not so sure now. I realized no one here knows what I'm talking about. Could it be really that depressing?

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: How big is your Level class/file?
« Reply #43 on: November 24, 2014, 11:01:42 PM »
Just stop pretending his game exists and everything makes sense.

You know, that's a bit old joke isn't it. I've heard it so many times.

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: How big is your Level class/file?
« Reply #44 on: November 24, 2014, 11:33:24 PM »
Some jokes never get old. They're funny because they're true.