The International Simutrans Forum

Simutrans Extended => Simutrans-Extended development => Simutrans-Extended future development discussion => Topic started by: Mariculous on June 13, 2021, 12:01:01 PM

Title: Code redundancy/maintainability
Post by: Mariculous on June 13, 2021, 12:01:01 PM
In Simutrans, not limited to, but especially in extended, there is a lot of (logically) duplicate code.
That means blocks of identical code being spread all around the codebase.

This leads to maintainance issues.
In the forums we can find bugreport threads like this quite often:
Player: I found the following bug...
Dev: Should be fixed now.
Player: It is, in this specific case, but in another case it's still there.
Dev: Should be fixed now.
Player: It is in this specific case, but in yet another case it's still there.
...

Quite often such conversations were the result of duplicated code spread all over the codebase.
Just to give the most recent example, see the bugreport about road construction/destruction costs.
There had been many of such cases in the past, however. A few that immediately come into my mind are signalling bugs being fixed on ordinary rail but persisting at narrow gauge, construction collision checks (build ways above public buildings, runways or next to runways) mesides many many more.

I am aware that fixing this all over the codebase is a huge task and it is quite unlikely that the code duplication issue will ever be fixed in the entire codebase.
However, I'd like to point this issue out and encourage any dev to keep this in mind when designing new features or adding new code in general.
Even when modifying code, we should ask ourselves a simple question: is the same logic used elswhere in the code?
If so, can we refactor this to implement that logic in a central place without redesigning the whole code?
Yes? Let's do it!
No? Well, we should... maybe... some day... Leave a note or something.
Title: Re: Code redundancy/maintainability
Post by: jamespetts on June 13, 2021, 01:20:37 PM
Yes, this is a longstanding problem in Simutrans. In Extended, the development has tended to try to be in keeping with the way in which the code works in Standard where functionality from Standard is retained to make incorporating changes from Standard easier, so it can be difficult for Extended developers to go it alone on code refactoring except in parts of the codebase that are Extended specific.