Some General Questions :)

Hey codeCademy!

  I had a few general questions to ask about the code in relationship to objects, properties, and getters. I write within the "General Programming" forum as I would like to know if their is a relation which exhists across multiple languages (Right now, I assume it could just be a JavaScript example due to the way the language has been designed,  however I was wondering if other languages include these questions listed below):


  1. If the object can contain a method where we pass code within the property, could a function store an object which stores another function? in addition, If we were to manipulate the object within the function… would we do so by utilizing the .method (getters/setters) outside of the function by calling the object and using this method to re-define its parametres? If we know functions are always calling the constant of the “rules” in which we have defined withing them… could calling theFunction + theChange help produce a different output?

  2. If so… is it quicker to code this way?
    → Create the objects you want the function to store… Add their properties… and then create an overall functioning of the objects. Once made we can edit objects using the .method approach where we can use Getters and Setters to define the values of each property? That way we can easily update and change the functions when we like.

  3. For the coding languages in general is their an approach which will help us shorten the lines of code the computer needs to process for a more efficent processing speed? would creating functions which run intended opperations and then just having a program which calls each condensed function be a practical approach?
    For Example; a non complex decision based game made up of 11 functions: 10 which hold 10 characters and all of their attributes and then an 11th function determines how the 10 functions would interact with one another based on the players decsions. IF/Else statements would be used to define which of the 10 fucntions create this dynamic. Do you think this approach would be possible to make something that can run with the simple coding between 11 different words and their 10^11 combinations?

Hope this makes sense!

1 and 2.

Yes, it is possible for you to store an object which stores another function. You can do this by utilizing the dot notation to access the object’s properties. Once you have access to the object’s properties, you can call the function inside that object and manipulate its parameters.

Calling the function plus the change can help produce a different output, depending on the nature of the change. It is possible to code this way, but whether or not it is quicker depends on the complexity of the code being written.

In general, it is always beneficial to utilize functions because they help you keep your code clean and organized, as well as make it easier to debug and maintain.

Yes, creating functions to run intended operations and then using a program to call each condensed function is an effective approach to shorten the lines of code and make the processing speed more efficient. This approach can be used to create a non-complex decision based game, as you have suggested. By creating functions for each character and their attributes, and then an 11th function to determine how those characters interact with each other, you can create a dynamic game with simple coding between the 11 words and their 10^11 combinations. This approach can be beneficial for creating a game that can run quickly and efficiently.

hope this helps! :slight_smile: