5 ms·
If you replace 100 lines of my code with 20 lines, God bless you. If you replace 100 lines of my code with 500 lines of buzzword-driven development that is 50%
by alrs 7y ago
If you replace 100 lines of my code with 20 lines, God bless you.
If you replace 100 lines of my code with 500 lines of buzzword-driven development that is 50% copied off of Stackoverflow, we're going to have a discussion.
- newswasboring 7y agoI don't know much about JavaScript. Are you saying that Prototype was replaced with bad code? Or was this not directly related comment?
- paulcole 7y agoYou get paid either way though, right?
- alrs 7y agoSo long as I'm not getting called at 3am to debug it, then yup.
- johnchristopher 7y agoSo, I recently (as in yesterday evening) converted the following piece of code in index.php of a wordpress plugin: if( $_GET["foo"] == "bar" ) { //add_action( 'wp_loaded', 'do_foo' ); //add_action( 'init', 'do_foo' ); //add_action( 'admin_init', 'do_foo' ); do_foo(); } which allowed easy launching of do_foo() by simply httping http://wordpress.tld/?foor=bar http://wordpress.tld/?foor=bar to add_action('rest_api_init', 'Company\PluginName\setup_foo_route'); and namespace Company\PluginName; function setup_foo_route() { register_rest_route( 'company/v1', 'bar', array( 'methods' => 'GET', 'callback' => 'Company\PluginName\do_foo', ) ); } which can be run by httping http://wordpress.tld/?rest_route=/company/bar http://wordpress.tld/?rest_route=/company/bar Which one of us would like to talk to :) ?
- dahart 7y agoThat’s perhaps much too small to be an example of what the parent comment was talking about. This might be a good example of what the article is talking about though. These represent two different fashions, both of which have enjoyed widespread support at different times. The original is explicit and smaller and easier for someone who’s not you to follow & modify. The latter is event/callback driven, and more complicated to follow, but in a large codebase might be a pattern that is easier to build on, maintain, and refactor, as well as harder to screw up when adding new routes.
- johnchristopher 7y agoI agree with you. What makes me lean towards my solution is that I can pass the plate to the WordPress documentation if anyone else want to know what the code is doing and we can follow the trail of callbacks and hooks while that request check can be (and in this case, is) sprinkled all over the codebase. What I noticed is that people following the first method ends up hacking core functionalities of WP because "it just works" but in the end that makes the code unstable and harder to maintain because it relies on undocumented stuff and a coding style that is very personal. It can also messes big time with stable things expected from the CMS (mangled taxonomies, hijacked hooks in the core instead of the WP pile that make it hard to debug or to play nice with other plugins/themes).
- folkhack 7y agoSorry for the critique on methodology but I'd start to consider a different system for routing vs hooking into the WordPress REST API. If I'm doing anything that actually requires sane PHP primitives (like the routing in your above example, and also notably DB) I steer clear from WordPress entirely. WordPress is a good CMS and makes for a great blogging platform but I have done my best to decouple any-and-all custom application development to it's own API. WordPress and it's core simply don't offer good tools, and it's a VERY highly targeted platform in regards to security. I would suggest Symfony or Laravel for PHP frameworks that do APIs very well; or even AltoRouter + vanilla PHP for super light-weight stuff where you want minimal dependencies. Personally I think Laravel is the easiest, and a joy to learn. Otherwise - kudos on ripping it out and replacing it with cleaner code!