"be consistent" | |
PerlMonks |
Re: A small Deity AI class systemby jahero (Pilgrim) |
on Nov 06, 2017 at 08:14 UTC ( [id://1202802]=note: print w/replies, xml ) | Need Help?? |
Hi there! Almost too long to read without further explanation, however - let me provide brief feedback based on what I have seen in package HollyGameAI::RNG. Please note that I am writing this without knowledge of context. Mistake in sub *rollDX*. Global symbol "$dx" requires explicit package name (did you forget to declare "my $dx"?) at test.pl line 22
Did you perhaps mean something like this?
Class constructor is usually named *new*. In your code, you are using constructor named RNG, which of course works, however this name is not something other people reading your code would expect to be. I would recommend sticking with the name *new* (minus the asterisk of course).
The way how you pass parameters to your subs is broken.
Consider this code:
This leaves variable $dxx undefined. Did you mean this?
Rather complex logic in sub *roll* could be simplified.
Seemingly, the *given* statement in your code is not needed, your *rollDX* covers all scenarios which are defined in *rollD1*, *rollD3*, *rollD<whatever>* routines. However, it is possible that these are actual placeholders which will contain additional code...
So it is possible this is actually valid.
Anyway, the *given* statement could be replaced by something more readable, for example:
Final tip - it seems you are serious in that your code will be object oriented. If that's the case, I would recommend investing some time and learning one of Perl object oriented frameworks. As for myself, I have been using Moo for some time, and never looked back. Moo Don't give up! Regards, Jan
In Section
Meditations
|
|