G'day Cody Fendant,
I would keep the base operations separate and clearly named to indicate their functions:
This allows you to unambiguously call the method you want directly and get feedback for errors.
For your "either add or update" function, what you're doing is modifying your set of widgets. I'd give it a name that exactly reflects that:
$self->modify_widget_set($id, @other_args)
This would call either add_widget() or update_widget() depending on the existence of $id in the database.
The method names I've shown are just suggestions. I'm not a big fan of CamelCase; however, if this is already used throughout your codebase, it would make sense to stick with it (addWidget(), modifyWidgetSet(), etc.).
"Would you call it just widget()?"
Short answer: Never!
Longer answer: Subroutines do something and their names should reflect this. Use verbs (or, at least, something suggesting a verb).
— Ken
In reply to Re: Subroutine naming convention/style
by kcott
in thread Subroutine naming convention/style
by Cody Fendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |