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
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?
just doesn't appeal to the "less code, always less code" training in me
Justin Sternberg
@jtsternberg
nor me :)
PG Lewis
@pglewis
but I have found as a pattern, they tend to be pretty maintainable and they do free you up from letting people get to deep in your implementation
Justin Sternberg
@jtsternberg
I'd also like to hear your reasoning for having them all be individual properties instead of using the array thing.
PG Lewis
@pglewis
and that's what I'm trying to address for starters, because the back compat part is the hardest part
I have grown a hate for literal strings in my code
can't auto-complete
global search for 'type' is a nightmare
whereas a getter, get_type() on an object, one click and I'm in the method
Justin Sternberg
@jtsternberg
Ok, so IDE chaining stuff
PG Lewis
@pglewis
arrays get messy debugging too
I really couldn't have done the nested fields at this point trying to maintain field arrays and field object arrays at the same time
and I'm not sure what the separate meta_box array was bringing to the table
Justin Sternberg
@jtsternberg
yah, def. was due for some refactoring, and I'm super glad to be rid of the field arrays/objects stuff
PG Lewis
@pglewis
those properties are properties of the metabox object... that's what object props are for the way I see it
Justin Sternberg
@jtsternberg
yah, that's a fair statement
PG Lewis
@pglewis
simplifies the data structure a lot when debugging, that screen-shot from a few days ago shows that
cmb2-nested-data.png
all your metabox properties are right there, not nested in an extra layer inside the metabox array
Justin Sternberg
@jtsternberg
yah
PG Lewis
@pglewis
but I'm not a hard-ass on code style, I've learned over the years to work in a when in Rome approach
Justin Sternberg
@jtsternberg
This has been my baby for a long time, so I'm sure you understand the questioning. :D
PG Lewis
@pglewis
I'm totally open to that, I'm never sold on what I'm doing, myself