Whitespace Posted September 7, 2015 Share Posted September 7, 2015 Runn is like MCCv2 but less ugly and actually OO. That's all... Over the next few weeks I will occasionally provide examples of the functionality of the and address issues MCC had which Runn will address. Example 1: The user's information MCC functions around globals.php which pulls functions and database queries. This is more often used to call the user's information, such as their id, username, money, etc. This method of calling the user's information can be very useful, however, issues do occur from this methodology: Irrelevant information for the current script/Unnecessary amount of database queries The information will more than often be static The script itself may not require any user information One primitive example of this is the user's information on the left panel of MCC. To resolve this issue we can take advantage of sessions. Firstly, if we successfully authenticate a user's information before proceeding to login we can create a $_SESSION element and set it to be true. $_SESSION['user_update'] = 1; This array element is important as the information will be assessed by an if statement. if ($_SESSION['user_update']) { $_SESSION['user'] = User_get_info( 'user_id', 'user_display_name', 'user_money', 'user_crystal', 'user_level', 'user_will', 'user_energy', 'user_health', 'user_brave', $_SESSION['user_id'] ); $_SESSION['user_update'] = 0; } Now a developer can simply use the already provided information without needing to hit the database. Runn runs its own globals file and will check the state of the session. Though we have to remember to include update the session's when we change the (relevant) information about the user we've simplified the process and save ourself time debugging as we're only using one function and one file, rather than numerous files and functions. This was brief example of what Runn will be capable of. Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted September 7, 2015 Share Posted September 7, 2015 Doesn't look very "OO" to me. Looks like you've created a function called "User_get_info" and that's it. But, that's based off of your current example. Preferably, you'd want to instantiate a new user model/class, and then fetch the data using a function. Like I said, though, this is 16 lines of code. Hard to tell what you're really doing. Quote Link to comment Share on other sites More sharing options...
Whitespace Posted September 7, 2015 Author Share Posted September 7, 2015 This particular example isn't OOP, but rather a simple and brief example of how the functionality of MCC can be improved. In addition, procedural programming makes the process much easier than requiring an entire class and additional lines of code. In addition, the function (User_ge...) is one time database query, which fit into the one of the listed problems I mentioned before. If you have any more questions please feel free to ask. Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted September 7, 2015 Share Posted September 7, 2015 This particular example isn't OOP, but rather a simple and brief example of how the functionality of MCC can be improved. In addition, procedural programming makes the process much easier than requiring an entire class and additional lines of code. In addition, the function (User_ge...) is one time database query, which fit into the one of the listed problems I mentioned before. If you have any more questions please feel free to ask. It doesn't matter about the lines of code, that's what OOP is and functionally speaking, it's 100x's better. Infact, if you nail your autoloader, calling a static method is quicker than calling a function you've loosely named in a "globals.php" file. Unless, of course, all you're returning is a hard-coded string. I'd rather use a full OOP implementation than half of one. What happens if I wanted to extend the functionality of "User_get_info" without having to edit the globals file, which I assume is "core"? I can't extend it or build a layer on top. Quote Link to comment Share on other sites More sharing options...
Whitespace Posted September 7, 2015 Author Share Posted September 7, 2015 It doesn't matter about the lines of code, that's what OOP is and functionally speaking, it's 100x's better. In fact, if you nail your autoloader, calling a static method is quicker than calling a function you've loosely named in a "globals.php" file. This isn't necessarily true. There is an entire class dedicated to a User; its intention is to provide passed information to completely map the object to the class and pass the object to a separate (Validation) class, and so on... To simply put it, we want to play with the object rather create one to have it on display. You can of course do this but this can be accomplished more simply. You can indeed argue that you can always treat the user as an object (or for a majority of the time), which can indeed beneficial, however you don't have to. Also, the calling of Use_get.. is handled by globals, which is handled by another, and so on... Essentially you revolve around independent files for different purpose without interacting with other important files (which you can also do). What happens if I wanted to extend the functionality of "User_get_info" without having to edit the global file, which I assume is "core"? I can't extend it or build a layer on top. User_get_info simply returns information to be displayed or handled, which (can) be passed on to a class - such as Users. This saves you the reverse process (e.g. having a completely defined objected rather than an object searching itself). Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted September 7, 2015 Share Posted September 7, 2015 This isn't necessarily true. There is an entire class dedicated to a User; its intention is to provide passed information to completely map the object to the class and pass the object to a separate (Validation) class, and so on... To simply put it, we want to play with the object rather create one to have it on display. You can of course do this but this can be accomplished more simply. You can indeed argue that you can always treat the user as an object (or for a majority of the time), which can indeed beneficial, however you don't have to. Also, the calling of Use_get.. is handled by globals, which is handled by another, and so on... Essentially you revolve around independent files for different purpose without interacting with other important files (which you can also do). User_get_info simply returns information to be displayed or handled, which (can) be passed on to a class - such as Users. This saves you the reverse process (e.g. having a completely defined objected rather than an object searching itself). It *is* 100% true. You seem to be confused by "less lines" > "number of files". Which isn't the OOP way, which leads me to believe you have little understanding of OOP itself. You're more than welcome to try and prove me wrong, though. I applaud you to try. These examples were run from within a project I'm currently working on, where we use PSR-4 autoloading to load my model. I just created a "check_user" function that runs a single database query, using PDO. Total Execution Time: 6.83466 I load my model, in the correct PSR standard way, which has a "user" class, we instantiate the class and call a static method to return the query: Total Execution Time: 4.33912 So not sure what planet you're living on. Now, I've got code that executes quicker AND it's easier to read and extend. What a fabulous result. Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted September 8, 2015 Share Posted September 8, 2015 And just for arguments sake, the same code ran on some static content. Let's load a loop of 10,000 (corrected execution time) My way, the proper way: 0.00055985 Your way, the wrong way: 0.00066395 Now I have a lovely fast loop, that I can extend and is done in true "OOP" style, and adhere's to PSR standards, how delightful! Edit: I just want to point out, I do not care about the load times here, even if the results are what I wanted. I'm just pointing out that having a single function inside of a "globals" file isn't PSR standard or OOP AND often times, it's still slower. You're either coding something in OOP style or you're not. Pick one, it will make your life easier. Quote Link to comment Share on other sites More sharing options...
~Rob0t Posted September 8, 2015 Share Posted September 8, 2015 [...] You're either coding something in OOP style or you're not. Pick one, it will make your life easier. I'd like to point out, in case anyone missed it, there seems to be a correct answer here. Pick wisely ;) Quote Link to comment Share on other sites More sharing options...
IllegalPigeon Posted September 8, 2015 Share Posted September 8, 2015 i'd like to point out, in case anyone missed it, there seems to be a correct answer here. Pick wisely ;) procedural!! Woooooo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.