Guest Melphina Micaela Posted July 29, 2017 Report Share Posted July 29, 2017 I have a legitimate question!! What is the point of declaring variables as constants inside methods when -- if the point of making variables constant is to make them immutable -- you can just as well declare them globally to avoid reassignment? Because here (correct me if I'm wrong, I haven't looked at anything beyond the screenshot) every time you call the method, it's just going to reassign values to what should be constant variables?? Quote Link to comment Share on other sites More sharing options...
gm112 Posted July 29, 2017 Author Report Share Posted July 29, 2017 2 hours ago, Melphina Micaela said: I have a legitimate question!! What is the point of declaring variables as constants inside methods when -- if the point of making variables constant is to make them immutable -- you can just as well declare them globally to avoid reassignment? Because here (correct me if I'm wrong, I haven't looked at anything beyond the screenshot) every time you call the method, it's just going to reassign values to what should be constant variables?? And I have an illegitimate answer! :D It provides a slight performance advantage in the context of JS interpretors to indicate when you're merely retrieving a value You're establishing a read-only contract so when the compiler optimizes your code, a lot of what may seem unnecessary or redundant gets tossed in favor of inlining everything(meaning those three consts you see turn into a few operations that moves data between registers. I could've just avoided the need for two of the three consts. But it was easier to interface with something that returns a partially parsed format than expecting the client of the implementation to provide its own. So in truth, the code comes out to be more internally verbose and friendlier on the outside. As far as defining those outside of the scope of the onMessage() call, no they cannot be pre-defined in the global context. This is an event callback so the data it's interacting with comes from an outside source. The emitters(save for the default one) are defined in the global scope(unfortunately due to how Node.JS modules work, there isn't a true "global context" but rather a local-global context specific to the module.. and I am referring to the one within index.js in this case), however(going back to the point I made earlier about removing two of the three consts). In JS when you assign a constant/variable to another object, you are merely receiving a reference of that object and not doing a deep copy. Plus I'm practicing functional paradigms(I failed here by the use of "this" and OOP concepts, but w/e that was rather intentional for the sake of keeping the syntax familiar for my coworkers whom wrote most of the original code) :) EDIT: Also failed to elaborate more on the performance benefit bit. I was referring to const vs var/let. Also if you look at the logic, its essentially an if statement that no-ops if there isn't an emitter. Seems redundant if there's a "default emitter" and it could just simply call the emitter either way. But at the time I wrote that method, there was no default handle. Though now I suppose it's left there.. but eh I still think it's okay. There comes a point when you can over-optimize and over-think your code. But with all of that said, you could just as easily do this instead: onMessage(message) { if (message.author.bot || !message.content.startsWith(command_delimiter)) return const cmd_args = parseMessageContent(message.content) (((!cmd_args[cmd_args.length - 1] || !this.message_handlers[cmd_args[cmd_args.length - 1]]) && this.message_handlers.default) ? this.message_handlers.default : this.message_handlers[cmd_args[cmd_args.length - 1]] ) .emit(message, cmd_args.splice(0, cmd_args.length -1)) .catch(error => console.error(error)) } Though as you can see, things are getting a little too crazy. There isn't any advantage either to this way versus above besides not having to write out three different consts. But those consts are what make that block of code a bit more readable. Plus with the references to having to call .length - 1, there's more temp vars for the Garbage Collector to clean up. Which leads me to believe that this way would actually perform worse albeit only slightly by a few clock cycles due to more memory accesses. And if you were to convert this to traditional syntax, it would be a little bit longer and wordier. Oh, and I wrote this short and dirty example to demonstrate a little something regarding JavaScript's memory model. Note that despite changing the "copy" of the object, changes appear to affect the original object. And vice-versa. https://jsfiddle.net/e5upcama/ Sorry if this response is a bit long and convoluted.. >_< But, if there's more you'd like to ask about or know then feel free to ask! Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted July 29, 2017 Report Share Posted July 29, 2017 (edited) Oh, okay! I see what went on now. Even so, I like that your reply was long because it was also really thorough and so easy to understand! The little example helped too, lol. Edited July 29, 2017 by Melphina Micaela Quote Link to comment Share on other sites More sharing options...
gm112 Posted July 29, 2017 Author Report Share Posted July 29, 2017 :D That's awesome! Err... I mean, very, very 1 Quote Link to comment Share on other sites More sharing options...
Crim Posted August 1, 2017 Report Share Posted August 1, 2017 Crimyeah! Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted April 27, 2018 Report Share Posted April 27, 2018 I'm working on a sort of pseudo(?) chess piece feature extraction program. As per usual, it's due tomorrow. ; v ; It's mostly a lot of GUI, honestly... Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted April 28, 2018 Report Share Posted April 28, 2018 (edited) It was due at midnight tonight but I got sick and woke up late and long story short I didn't get to turn it in on time, but here it is anyway. Might as well show it off somewhere, I guess. (I'm actually really bummed I couldn't turn it in on time, since the prof doesn't accept late work at all... : \) Edited April 28, 2018 by Melphina Micaela Quote Link to comment Share on other sites More sharing options...
hawthorneluke Posted May 1, 2018 Report Share Posted May 1, 2018 ha awesome (apart from the not being able to hand it in bit :( ) Quote Link to comment Share on other sites More sharing options...
gm112 Posted May 1, 2018 Author Report Share Posted May 1, 2018 Ah, Bummer.. You get an A for effort, at least Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted May 1, 2018 Report Share Posted May 1, 2018 Thanks, guys. ; v ; Working on a photo share program atm. Everything works though the code is a biiiit messy. Rn I'm just trying to implement security measures, but here's the program running after some parameters have been input after logging in. Quote Link to comment Share on other sites More sharing options...
Fragment Posted May 5, 2018 Report Share Posted May 5, 2018 *walks in* Whoa everything here looks complicated *walks out* Quote Link to comment Share on other sites More sharing options...
gm112 Posted May 7, 2018 Author Report Share Posted May 7, 2018 I see Java there. What UI toolkit are you using because that definitely doesn't look like Java's Swing or unless it's heavily styled. ? On 5/5/2018 at 2:49 AM, Fragment said: *walks in* Whoa everything here looks complicated *walks out* /me pulls Fragment back in here Hey, you can always ask questions an we can help you out! Learn somethin new. ? Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted May 8, 2018 Report Share Posted May 8, 2018 22 hours ago, gm112 said: I see Java there. What UI toolkit are you using because that definitely doesn't look like Java's Swing or unless it's heavily styled. ? /me pulls Fragment back in here Hey, you can always ask questions an we can help you out! Learn somethin new. ? JavaFX! I've never delved too deep into Swing, but I hear it can get messy in there. On 5/5/2018 at 1:49 AM, Fragment said: *walks in* Whoa everything here looks complicated *walks out* He's right! Feel free to ask anything as I could probably learn from your questions as well. Quote Link to comment Share on other sites More sharing options...
Fragment Posted May 8, 2018 Report Share Posted May 8, 2018 I don't really know anything about coding like you guys. Quote Link to comment Share on other sites More sharing options...
gm112 Posted May 9, 2018 Author Report Share Posted May 9, 2018 On 5/8/2018 at 2:24 AM, Melphina Micaela said: JavaFX! I've never delved too deep into Swing, but I hear it can get messy in there. Ah, right. Yeah, I haven't done traditional Java development in awhile besides workin with Spring MVC. But I do recall Swing being a butthole, so that's good they've replaced it with a better API. 18 hours ago, Fragment said: I don't really know anything about coding like you guys. That's fair. You doin anything creative on the side? ? On that topic.. I've been working on something and have some concept art to share. My team produced the following art... As an added bonus, here's a WIP song Renards_Theme_Sample.wav Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted May 9, 2018 Report Share Posted May 9, 2018 23 hours ago, Fragment said: I don't really know anything about coding like you guys. Same tho. @gm112 What a cute art-style!! The second picture's character's hair reminds me of Link if he had Ghibli hair. I only gave the music file a quick listen but it's really good!! Best yet, I'd say. Quote Link to comment Share on other sites More sharing options...
Fragment Posted May 11, 2018 Report Share Posted May 11, 2018 Not as creative as i used to be. Definitely had a lot more time to give this place when i was younger. Now I have to be an adult. Quote Link to comment Share on other sites More sharing options...
gm112 Posted May 14, 2018 Author Report Share Posted May 14, 2018 On 5/9/2018 at 12:42 PM, Melphina Micaela said: Same tho. @gm112 What a cute art-style!! The second picture's character's hair reminds me of Link if he had Ghibli hair. I only gave the music file a quick listen but it's really good!! Best yet, I'd say. Thank you. ? That's a very humbling comparison, I'll make sure to let them know! That'll make their day. And the music also wasn't my work, but I appreciate the time given to listen to it so thank you! Lotta thank yous in this post sorry :X On 5/11/2018 at 2:30 PM, Fragment said: Not as creative as i used to be. Definitely had a lot more time to give this place when i was younger. Now I have to be an adult. Yeah, seems like with age, more things eat up your free time... derp Quote Link to comment Share on other sites More sharing options...
Blood Willow Posted May 17, 2018 Report Share Posted May 17, 2018 Game char? Looks good I wish i could actually draw lol Quote Link to comment Share on other sites More sharing options...
Guest Melphina Micaela Posted June 18, 2018 Report Share Posted June 18, 2018 On 5/14/2018 at 9:08 AM, gm112 said: Thank you. ? That's a very humbling comparison, I'll make sure to let them know! That'll make their day. And the music also wasn't my work, but I appreciate the time given to listen to it so thank you! Lotta thank yous in this post sorry :X Definitely!! They deserve the praise! : > No worries, dude. Always inspiring/great to take a look at others' creative works! Quote Link to comment Share on other sites More sharing options...
gm112 Posted September 5, 2018 Author Report Share Posted September 5, 2018 I've been up to stuff. Quote Link to comment Share on other sites More sharing options...
gm112 Posted November 17, 2018 Author Report Share Posted November 17, 2018 Lol.. little bit of fun with a sin function being applied on the translation matrix of a bunch of child nodes. Makes for a simple but effective animation. And, this mesh is rendered with 1 drawcall. Pretty happy with having this working 🙂 Quote Link to comment Share on other sites More sharing options...
Crim Posted November 19, 2018 Report Share Posted November 19, 2018 walk walk walk Quote Link to comment Share on other sites More sharing options...
gm112 Posted November 25, 2018 Author Report Share Posted November 25, 2018 On 11/19/2018 at 1:01 AM, Crim said: walk walk walk yes Quote Link to comment Share on other sites More sharing options...
Crim Posted December 26, 2018 Report Share Posted December 26, 2018 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.