Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
PG Lewis
@pglewis
having those allows you to change the whole underlying implementation later if you want to
the getters and setters are what are exposed and used on the consuming side, and hide the details so you're more free to change them in the future
though a single getter/setter does that too
Justin Sternberg
@jtsternberg
yah, that's my main question. Why not one (or fewer)
PG Lewis
@pglewis
let me turn it on it's head for a moment, what's the benefit of not having separate ones?
PG Lewis
@pglewis
with individual getters and setters you can phpDoc the return values properly for each one
Justin Sternberg
@jtsternberg
yah, that's true. Curious, how does this handle custom metabox properties?
PG Lewis
@pglewis
this in turn means my IDE knows when I call get_field_objects() and foreach through it, each element is a Field object
and i get autocomplete on the field object as a freebie
Justin Sternberg
@jtsternberg
because users can (and do) add arbitrary data to the cmb array and then pull it out elsewhere
Justin Sternberg
@jtsternberg
since we're renaming things, I think we definitely should rename the cmb_id property/methods to just id
just kludged to add it to it's own free form array that I tack back on with array_merge()
just there for back compat or I wouldn't have thought of it
Justin Sternberg
@jtsternberg
how about back-compat for the prop method?
PG Lewis
@pglewis
passes all tests, including some I added specifically for prop
Justin Sternberg
@jtsternberg
since that's how the arbitrary values are retrieved currently
ah ok, you still have the prop method. should have looked
PG Lewis
@pglewis
reworked to use the "new way"
everything internally in cmb2 should be using the getters/setters now
and helper functions too
outside code doesn't yet, but the back compat bits should be catching nearly all that
Justin Sternberg
@jtsternberg
yah, makes sense. so my biggest opposition to the individual setters/getters is the non-DRY redundancy throughout this file. Just eats at me. :) not necessarily a good enough argument to remove, but...
PG Lewis
@pglewis
so, ultimately, it's "doable"
explicit getters and setters are the one time I come off my "less code is always better" stump
or one of the rare times
but in the end, it's usually not much less code overall and the IDE can generate the skeletons
Justin Sternberg
@jtsternberg
at least do this?
        case 'id':
        case 'title':
        case 'type':
        case 'object_types':
        case 'context':
        case 'priority':
        case 'show_names':
        case 'show_on_cb':
        case 'show_on':
        case 'cmb_styles':
        case 'enqueue_js':
        case 'fields':
        case 'hookup':
        case 'save_fields':
        case 'closed':
        case 'new_user_section':
            return call_user_func( array( $this, 'get_'. $property ) );
:D
PG Lewis
@pglewis
a single getter/setter approach still has to have all your logic
lol
the whole point is the freedom to refactor more in the future...
when they're all explicit like that, if we change a method name it's picked up through refactor tools
dynamic things like that are not
if it really saved time in code or execution, sure why not
Justin Sternberg
@jtsternberg
Ok makes sense
PG Lewis
@pglewis
when it's dynamic, my IDE is more likely to miss it, so I shy away from that a lot
but it's really a minor point, just letting you know why I didn't do the call_user_func approach myself
Justin Sternberg
@jtsternberg
So the trade-off is that the code is more readable but less readable by humans
(ish)
ugh, didn't finish my thought
PG Lewis
@pglewis
the getters and setters litter things up a bit, that's my least favorite part
Justin Sternberg
@jtsternberg
So the trade-off is that the code is more readable to IDEs but less readable by humans
PG Lewis
@pglewis
phpStorm has convinced me somewhat that if my IDE reads it better, so do I lol
Justin Sternberg
@jtsternberg
yah, haven't dove into phpStorm yet
PG Lewis
@pglewis
like I said, the getter/setter litter is probably the biggest downside I see
but without having to actually write them all, how much do they get in my way?