aliens

Author Topic: a thought from a c++ software developper  (Read 8349 times)

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
a thought from a c++ software developper
« on: September 16, 2013, 02:04:08 am »
Hello forum users, and openXcom developpers. I have been very enthusiastic once I have read about the openXcom project by some wierd coincidence. UFO:Enemy Unknown was undeniably the game of my life. It was extremelly playable, even more than later encountered dune2:battle for arrakis, or starcraft:broodwar years after. It was the very same thing this time - nothing changed. I have installed it somewhere around midnight, and stopped playing just before 6A.M. having full tech and a lot of talented psionics, basically only waiting for the right moment to invade cydonia...

With the same dose of fanatism I have helplessly fallen under the might of the thought to help your development team with maintaining the product, fixing its problems and delivering new, configurable functionality. All that until I've taken a look on your codebase.

I personally think your project could use some help of a system architect. I won't name what I've seen until you decide whether you want some help on the game's architecture or not, but some simple refactoring would facilitate further development and made the code a lot more readible and flexible, giving you productivity and a greater scope of changes you can incorporate to satisfy your audience, alongside with less errors introduced.

It's your call - I will check this forum from time to time for an answer from the dev.

Regards,

Offline xracer

  • Commander
  • *****
  • Posts: 564
  • X-COM lover, we've gone at it everywhere
    • View Profile
Re: a thought from a c++ software developper
« Reply #1 on: September 16, 2013, 10:29:43 pm »
Hello djemon_Ida

Welcome to OXC!!!! Now i am not a programmer, but from a layman's point of view i don't see why you can't give a hand. I know there are a couple of individuals attempting to clean up the code. Sup has always been extremely open to anything that improves the code, if your skills are on par, then i would suggest presenting your idea on how to streamline, clean-up and over all improve the code. Clearly an overhaul of the system in general will be a daunting task to say the least, but if you are up to the task i vote why not, get your hand dirty already!!! :P

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2160
    • View Profile
Re: a thought from a c++ software developper
« Reply #2 on: September 17, 2013, 01:57:14 am »
Uhhhhhh... ok?

No offense djemon_lda, but I'm sure any programmer could come in, take a look and say "wow this is terrible, I could do a much better job". Hell, we ourselves sometimes take a look at it and say "wow this is terrible, I could do a much better job". Code is always debatable, but unless you just wanna look cocky you're gonna have to give me more than that.

I mean I'm sure OpenXcom has some serious architectural problems. It's been in development for years now, and in that time it's been touched by dozens of completely different people with completely different ideals. A lot of solutions and implementations weren't meant to be "final". And my own experience has changed in the course of these years, so if I were to start today I probably would've done it completely different. :P

But at this point it has also "matured". It's feature-complete. Players are pretty happy with it. I'm not sure taking it apart and putting it back together is a good approach this late in the cycle, when programmers are already pretty familiar with the workings, and players just want less bugs and more improvements.

So what exactly do you have in mind?

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: a thought from a c++ software developper
« Reply #3 on: September 17, 2013, 03:29:33 am »
I was in the middle of responding to xracer, so I will just divide the replay into two.
@xracer:

Hello, and thank you for a warm welcoming word. I prefer to wait for the comments of the development team. It is fully in their hands to decide whether they wish my influence on their codebase or not. All in all - it is their piece of work, and a lot of their effort.

Regards,
djemon_lda

@SupSuper:
I'm afraid you've misunderstood what I've had in mind. I didn't mean to insult you or any other developer, and as a part of that I didn't want to start off with lists of what I deem to be a problem without anyone from the dev to actually show interest in such a talk. How rude would I be then? I have, tough, made an exception from that rule, because I have found a reason in the code, for what some people were complaining ( and which also bugged me a bit ) - reaction fire, yet I've only explained the problem in code, without proposing any solutions  - after all, exception or not, I still didn't have any approval from your side - and believe me I really respect the code of other people and I am not fiery tempered as it goes to estimating overall programming skill of a team of programmers based on a project they've developped - I do understand that the current state of the project is a creation that is evolutionary in nature - you can only build up on what you've already have.

I've had in mind an image of many changes in the development team during the lifetime of this project just by taking a look into the code. Keep in mind, that nowhere have I judged anyone, and didn't name the codebase with the epithets you've suggested - all I've stated is that in my opinion it could use some help of an architect, which means nothing more, that I could propose some improvements, that are - as you stated relating to all code - debatable and either can be seen as helpful or as being yet another problem.

I know the problem of "long term temporary solutions" and I have faced them many times in the projects I have been working on. The mature state of the product is a big virtue, but it still isn't 'ready' or 'done' - depending which naming convention is closer to you. For example it crashed when a battleship has flown into a base with no soldiers inside with a message box about not  supporting RTTI if I recall correctly. How effective would fixing that be with the current codebase, team and familiarity with code? BUT I also know that no product can survive without continuous refactoring and claryfying it's internal language. The better the domains are defined, the better are the classes responsibilities defined, and the lower the coupling is, the easier it is to avoid/track/fix bugs, and the easier and faster it is to implement new functionality. Pardon me if I am repeating something widely known, but I wish to present my view, and nothing more.

What I'd like to propose is far from breaking the thing apart and trying to put it back in different order. What I think would boost your productivity is to grab a little code here, a little code there, and make a functionality out of it. For example giant sections of if/else/switches could easily by handled by clarifying responsibilities, which would not only make the code a lot easier to read, but also to extend and test and you also wouldn't need enums flying left and right. It would be a lot easier to introduce different AI for different alien races and civillians on terror missions - even differentiating aliens by their ranks. If, on the other hand, we will consider the use of the enum BattleActionType then we can actually facilitate the code, to make it - from if/else/swiched things - to a simple one-liner that takes into account the responsability of an action type. Having actions like shots  Auto/Aimed/Snap that determine how many projectiles are fired, what are the moddifiers to the accurracy, time units cost and so on, you could just use those objects instead. Giving more responsibility to BattleUnit you wouldn't need to use those a->b->c->d calls to determine if an action can be performed in terms of time units ( a CanPerform(Action& ?) ), the same goes with things like GetReactionScore() etc.

And again - it is up to the team to consider if this would help you, and if you need /or not/ my assistance in any dimension and in the specific way. I might just propose changes, I might participate in development, or I just might alert if something in the code looks like a bug. Whatever suits you best.

Decide if you need such help - and again don't treat this like "dicking around" - I'm simply not a native speaker and it might be necessary to take it into accound while reading.

Kind regards,
djemon_lda

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2160
    • View Profile
Re: a thought from a c++ software developper
« Reply #4 on: September 17, 2013, 06:58:31 pm »
I understand not wanting to open up by criticizing everything, but your first post was just really vague, which bugged me. Now that you have presented your view your intentions are more clear.

Anyways your ideas sound good. :) From what I understand you're basically suggesting a more compartmentalized component-based design as opposed to the current value-based approach, where instead of checking a whole bunch of values and relying on if/elses to figure out what do with an item or unit, you delegate that to appropriate classes. The current design probably comes from originally the game had a lot smaller scope so Ruleset and SavedGame were meant to just hold values while the actual game states did all the work (which was close to the original game structures), but in retrospect that probably wasn't such a great idea, although it has seen improvement over time.

In conclusion I'm curious to see your improvements. Whether you choose to code them yourself or just post them is fine by me (normally contributors work in their own codebase forks so they're free to mess around without disrupting and can later be merged into the main codebase). However the main Battlescape developers are Daiky and Warboy, so if you wanna direct your efforts there I'd suggest contacting them through forum or IRC (though they're kinda hard to get a hold of), as they probably have a much better understanding of how it works and what can be improved than I do (I mainly deal with the engine and Geoscape stuff).

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: a thought from a c++ software developper
« Reply #5 on: September 18, 2013, 02:16:34 am »
Very well :) I will contact warboy as it goes to the battlescape development. I will start looking for usable improvements once I will get visual assist x installed for my visual studio ( I will have to get other version than express, as it doesn't support any add-ins).
I have an inquiry tough: do you have all the externall dlls, libs and include files gathered somewhere in one place, or should I download them on my own?

Regards,
djemon_lda

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2160
    • View Profile
Re: a thought from a c++ software developper
« Reply #6 on: September 18, 2013, 03:12:59 am »
Visual Assist X is amazing for C++ development, I heartily recommend it. :)

Since you're using Visual Studio, you can get all the dependencies ready to go here. There's more details on the wiki.

Offline Daiky

  • Battlescape Programmer
  • Administrator
  • Commander
  • *****
  • Posts: 904
    • View Profile
Re: a thought from a c++ software developper
« Reply #7 on: September 21, 2013, 10:28:03 pm »
Hello djemon_lda, I have had not yet the chance to say hi.

Let me first introduce you to my background and the battlescape code :) First of all, I've never learnt how to code from books (I quit school at 18), but mostly from looking at other people's code. I kinda tumbled into a developers job, first programming PLCs, assembler, C, and then some Basic, Pascal, Java, etc. Before openxcom I did now C++ somewhat, but never heard of STL. I know basics of OOP, but once people start saying words like polymorphism, I have to google them to see what they mean.
Basically, I'm a man of making stuff work and it doesn't have to look pretty on the inside. It's how we do things in the software company I'm working 12 years for now. The customer wants to see results fast, he doesn't care about the code. I get the job done, customer is happy, my boss is happy :)

In my hobby projects it's exactly the same. I really tried my best to follow SupSuper's guidelines and I learned a lot from looking at his code and I was just happy things compiled and it could run and the battlescape came to life... a lot of people were happy with openxcom having a battlescape :)

But anyhow, I'm not -yet- too old to learn new tricks, so I'll be reading your comments with interest and hopefully learn someting from it. Or from your code if you have plans to start refactoring things. However I think it will take a lot of courage to start refactoring things in a project like this, at a stage where everything kinda works. It's almost like starting all over again...

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: a thought from a c++ software developper
« Reply #8 on: September 24, 2013, 03:48:34 pm »
Perhaps I could make a topic in the development section (or even a full section with independent topics?) with something like tutorials about some concepts ? with examples from the codebase ? that might come out fruitful in the end. What do you guys think ? how many recipients would such a section have?

I could cover topics like encapsulation, how to really do that, why is it there for, what are the scopes of encapsulation etc, how not to mistake object based programming with object oriented programming, stuff about testing software, tools for testing, how to make your software more testable, more flexible for changes, and how to desing(or refactor) stuff into things, that can be extended, but won't need modification and so on.

anyone intersted say "I!" in this topic :P

(I'm sick and feel barely alive now, that is why I am inactive lately )
« Last Edit: September 24, 2013, 03:56:37 pm by djemon_lda »

Offline Yankes

  • Commander
  • *****
  • Posts: 3208
    • View Profile
Re: a thought from a c++ software developper
« Reply #9 on: September 24, 2013, 08:43:20 pm »
Perhaps I could make a topic in the development section (or even a full section with independent topics?) with something like tutorials about some concepts ? with examples from the codebase ? that might come out fruitful in the end. What do you guys think ? how many recipients would such a section have?

I could cover topics like encapsulation, how to really do that, why is it there for, what are the scopes of encapsulation etc, how not to mistake object based programming with object oriented programming, stuff about testing software, tools for testing, how to make your software more testable, more flexible for changes, and how to desing(or refactor) stuff into things, that can be extended, but won't need modification and so on.

anyone intersted say "I!" in this topic :P

(I'm sick and feel barely alive now, that is why I am inactive lately )
Interesting proposition. You should say something about my favorite C++ feature: template metaprograming :)

Offline MyThos

  • Sergeant
  • **
  • Posts: 40
    • View Profile
Re: a thought from a c++ software developper
« Reply #10 on: September 24, 2013, 09:16:52 pm »
anyone intersted say "I!" in this topic :P

Me! :P

But I would also like to see your suggestions applied directly to the code. This would give some encouragement for further improvements.

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: a thought from a c++ software developper
« Reply #11 on: September 24, 2013, 11:32:29 pm »
Quote from: Yankes
Interesting proposition. You should say something about my favorite C++ feature: template metaprograming :)

I don't think that there will be that much room for really interesting things on meta programming or using SFINAE in this particular project, but when I see a suitable place I will gladly propose something. Most of all there aren't any performance problems caused by things like extensive usage of trigonometrics or other slow functions like this that would require a compile time computation on taylor series for some number of elemnts.

Not making generic purpose stuff I don't see a place for SFINAE here either :( making some shenanigans with conditional template compilation is fun, but here would have been achieved by polymorphism and an interface and at the same time be a lot more readable.

static polymorphism - well maybe, why not - at the first thought. but on the second - data will be there either as references or pointers either way, and sparing one assembler command per a method call isn't enough to sacrifice the readibility in my opinion.

I do LOVE templates, but only when they are used properly, and when they are done by layering if possible ( and often it is ).

Quote from: MyThos
But I would also like to see your suggestions applied directly to the code

if I will just fix and commint, noone will ever notice until something really major gets changed. noone will learn from that I think. and if someone reads the intentions of the change wrong - well that is even worse. my proposition here was


Offline Yankes

  • Commander
  • *****
  • Posts: 3208
    • View Profile
Re: a thought from a c++ software developper
« Reply #12 on: September 25, 2013, 10:14:44 pm »
I don't think that there will be that much room for really interesting things on meta programming or using SFINAE in this particular project, but when I see a suitable place I will gladly propose something. Most of all there aren't any performance problems caused by things like extensive usage of trigonometrics or other slow functions like this that would require a compile time computation on taylor series for some number of elemnts.

Not making generic purpose stuff I don't see a place for SFINAE here either :( making some shenanigans with conditional template compilation is fun, but here would have been achieved by polymorphism and an interface and at the same time be a lot more readable.

static polymorphism - well maybe, why not - at the first thought. but on the second - data will be there either as references or pointers either way, and sparing one assembler command per a method call isn't enough to sacrifice the readibility in my opinion.

I do LOVE templates, but only when they are used properly, and when they are done by layering if possible ( and often it is ).
OpenXcom is already using static polymorphism, but is only one place (function `ShaderDraw<>`).
I think its successful because its remove lot of boilerplate require when you blit one surface to another (with some spacial twist :) ).

Offline djemon_lda

  • Captain
  • ***
  • Posts: 52
    • View Profile
Re: a thought from a c++ software developper
« Reply #13 on: September 25, 2013, 10:51:57 pm »
well that is nice :) I haven't had a chance to take a look on that part of the codebase yet. I'll check that out the first thing when I'm back on my feet with health stuff - now I can barely sit after work, because I'm sick.

what I like most in template metaprogramming is using SFINAE to make compilation time conditionally chosen classes based on specified types properties to generate safe inlined recurrent structures, so that you can make your more advanced templates always produce safe results. unfortunately this is very very rarely required. its fun to write these basic SFINAE structures on your own, but many useful cases are already implemented in boost.