[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4752: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4754: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4755: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4756: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
ToME: the Tales of Maj'Eyal • View topic - C++ best practices for current ToME2 code?

ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Tue Apr 13, 2021 11:49 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Wed Mar 02, 2016 2:42 pm 
Offline
Uruivellas

Joined: Tue Dec 13, 2005 12:35 am
Posts: 712


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 4:56 pm 
Offline
Spiderkin

Joined: Sat Mar 18, 2006 12:48 pm
Posts: 482


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 6:09 pm 
Offline
Uruivellas

Joined: Tue Dec 13, 2005 12:35 am
Posts: 712
Thanks @AnonymousHero...

Hmm. I have to admit that the passing-mutable-bool-pointers thing seems weird to me. It sounds like an easy way to run into variable scoping issues. Also, void functions with mutable parameters and side effects just seems... Kind of oddball? It's less cluttered than using a bool return value and an assignment, but something just looks wrong about it.

Though, I don't think anything does use the value of ident. I believe that's just returned if the trap is to be identified.

Re boost::tuple and tie(): now that seems more like it! Seems like a bunch of stuff could be moved out of global/static/side effect territory, by putting it in tuple return values.

(Immediate questions on that:
1. Is there a way to do that without Boost, using only C++11 standard libraries?
2. For future reference, is there a sane way to have "tuples" in pure C? Because it seems really, really handy. Best I can come up with seems to be returning a static array. But that can be dangerous in C, with out-of-bounds accesses not being caught by the compiler...)

Re map(), that sounds fantastic but the syntax confuses me. I'll see if I can find online reference stuff about that.

...

For the code itself: yes, that's exactly what I was thinking. Reduce the amount of static/global clutter, and divvy up different stuff into different functions.

Traps were just a handy example though. :) Also, too bad they seem to be more heavily incorporated into the Theme module...

...

And thank you for the book recommendation. There are a bunch of legacy Linux apps that I've wanted to revitalize, so that sounds worthwhile.


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 6:27 pm 
Offline
Spiderkin

Joined: Sat Mar 18, 2006 12:48 pm
Posts: 482


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 10:10 pm 
Offline
Uruivellas

Joined: Tue Dec 13, 2005 12:35 am
Posts: 712
Huh. Last I checked, anonymous structs weren't a thing in C. Not sure if that changed with C11 though.

Variable scoping issues: right, the compiler would catch this. N/M. In any case, I don't think I've yet seen a function written such that what you describe would be necessary...

In any case, which code besides the trap stuff do you think most needs refactoring? I've noticed really hefty duplication in the wand/rod/staff code, and more giant switch()ing functions for scrolls and potions... Not sure what else there is though. I'm thinking I will start attacking the scroll/potion stuff this evening.


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 10:22 pm 
Offline
Spiderkin

Joined: Sat Mar 18, 2006 12:48 pm
Posts: 482


Top
 Profile  
 
PostPosted: Wed Mar 02, 2016 11:54 pm 
Offline
Uruivellas

Joined: Tue Dec 13, 2005 12:35 am
Posts: 712


Top
 Profile  
 
PostPosted: Thu Mar 03, 2016 12:01 am 
Offline
Spiderkin

Joined: Sat Mar 18, 2006 12:48 pm
Posts: 482
Yeah, I'm not a fan of the , as it's called. There doesn't seem to be any quite-as-compact way of doing it in C++, but that doesn't make me like it more. Template traits are quite similar, but seem quite a bit more verbose.

It screws up IDEs, it induces quite high coupling (though it's compile-time), etc.


Top
 Profile  
 
PostPosted: Thu Mar 03, 2016 4:32 am 
Offline
Thalore

Joined: Mon Mar 25, 2013 10:09 pm
Posts: 153

_________________
(QDZ) - an Oriental-themed fantasy game for T-Engine. - auto-generated spoilers for ToME.


Top
 Profile  
 
PostPosted: Thu Mar 03, 2016 4:58 am 
Offline
Thalore

Joined: Mon Mar 25, 2013 10:09 pm
Posts: 153

_________________
(QDZ) - an Oriental-themed fantasy game for T-Engine. - auto-generated spoilers for ToME.


Top
 Profile  
 
PostPosted: Thu Mar 03, 2016 10:11 am 
Offline
Uruivellas

Joined: Tue Dec 13, 2005 12:35 am
Posts: 712
@Castler

Callback map, hmm. I was experimenting a bit with something like that for potions, though in the C style - just an array of function pointers, and calling the one corresponding to the potion SVAL.

I do sometimes wish T2 were still pure C. I know C++ has a lot of advantages, but simplicity is not one of them.

For OOP, I'd considered that too, but wasn't sure how/if it fit with the C++11 stuff. Also it would require bottom-up redesign. Though that might be a good thing... hmm. And I do like the idea of using fewer libraries and whatnot (both Boost and standard libraries). Since classes are a C++ builtin feature, etc.

I'll admit I kind of balk at hierarchical inheritance though. Not for any theoretical reasons; more just that it's been my programming bugbear since I learned Java back in college.

(And as far as macros being evil: maybe, but they beat manually duplicated code any day IMO.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group